Skip to content

Commit

Permalink
update dev dependencies and workflow (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max committed Apr 24, 2022
1 parent 2d446a1 commit cc3fc46
Show file tree
Hide file tree
Showing 19 changed files with 2,003 additions and 5,880 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,23 @@
{
"env": {
"node": true,
"es2021": true,
"jest/globals": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"jest",
"prettier"
]
}
34 changes: 18 additions & 16 deletions __tests__/githubstatus.test.ts
@@ -1,18 +1,18 @@
import {describe, expect, it, jest, test} from '@jest/globals';
import * as path from 'path';
import * as githubstatus from '../src/githubstatus';
import {Page, Status} from '../src/status';
import {Summary} from '../src/summary';
import fs from 'fs';

describe('githubstatus', () => {
it('returns GitHub Status (status)', async () => {
const status = await githubstatus.status();
console.log(status);
expect(status?.indicator).not.toEqual('');
});

it('returns GitHub Status (summary)', async () => {
const summary = await githubstatus.summary();
console.log(summary);
expect(summary?.status.indicator).not.toEqual('');
expect(summary?.components?.length).toBeGreaterThan(0);
});
Expand Down Expand Up @@ -49,29 +49,31 @@ describe('status', () => {
} as Page
]
])('given %p', async (file, expStatus, expPage) => {
jest.spyOn(githubstatus, 'status').mockImplementation(
(): Promise<Status | null> => {
return <Promise<Status>>require(path.join(__dirname, 'fixtures', file));
}
);

jest.spyOn(githubstatus, 'status').mockImplementation((): Promise<Status> => {
return <Promise<Status>>(JSON.parse(
fs.readFileSync(path.join(__dirname, 'fixtures', file), {
encoding: 'utf8',
flag: 'r'
})
) as unknown);
});
const status = await githubstatus.status();
console.log(status);
expect(status?.status).toEqual(expStatus);
expect(status?.page).toEqual(expPage);
});
});

describe('summary', () => {
test.each([['data-summary.json'], ['data-summary-2.json']])('given %p', async file => {
jest.spyOn(githubstatus, 'summary').mockImplementation(
(): Promise<Summary | null> => {
return <Promise<Summary>>require(path.join(__dirname, 'fixtures', file));
}
);

jest.spyOn(githubstatus, 'summary').mockImplementation((): Promise<Summary> => {
return <Promise<Summary>>(JSON.parse(
fs.readFileSync(path.join(__dirname, 'fixtures', file), {
encoding: 'utf8',
flag: 'r'
})
) as unknown);
});
const summary = await githubstatus.summary();
console.log(summary);
expect(summary?.status.indicator).not.toEqual('');
expect(summary?.components?.length).toBeGreaterThan(0);
});
Expand Down
1 change: 1 addition & 0 deletions __tests__/util.test.ts
@@ -1,3 +1,4 @@
import {describe, expect, it} from '@jest/globals';
import * as githubstatus from '../src/githubstatus';
import * as util from '../src/util';

Expand Down
3 changes: 3 additions & 0 deletions codecov.yml
@@ -0,0 +1,3 @@
comment: false
github_checks:
annotations: false
71 changes: 71 additions & 0 deletions dev.Dockerfile
@@ -0,0 +1,71 @@
# syntax=docker/dockerfile:1

ARG NODE_VERSION=12

FROM node:${NODE_VERSION}-alpine AS base
RUN apk add --no-cache cpio findutils git
WORKDIR /src

FROM base AS deps
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn install && mkdir /vendor && cp yarn.lock /vendor

FROM scratch AS vendor-update
COPY --from=deps /vendor /

FROM deps AS vendor-validate
RUN --mount=type=bind,target=.,rw <<EOT
set -e
git add -A
cp -rf /vendor/* .
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'
git status --porcelain -- yarn.lock
exit 1
fi
EOT

FROM deps AS build
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run build && mkdir /out && cp -Rf dist /out/

FROM scratch AS build-update
COPY --from=build /out /

FROM build AS build-validate
RUN --mount=type=bind,target=.,rw <<EOT
set -e
git add -A
cp -rf /out/* .
if [ -n "$(git status --porcelain -- dist)" ]; then
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
git status --porcelain -- dist
exit 1
fi
EOT

FROM deps AS format
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run format \
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out

FROM scratch AS format-update
COPY --from=format /out /

FROM deps AS lint
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run lint

FROM deps AS test
ENV RUNNER_TEMP=/tmp/github_runner
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run test --coverageDirectory=/tmp/coverage

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /

0 comments on commit cc3fc46

Please sign in to comment.