Skip to content

Commit

Permalink
chore: update dev dependencies and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Mar 15, 2022
1 parent 11e26b9 commit 27c90ae
Show file tree
Hide file tree
Showing 20 changed files with 2,214 additions and 11,564 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"env": {
"node": true,
"es2021": true,
"jest/globals": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"jest"
]
}
6 changes: 5 additions & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
import * as os from 'os';
import * as context from '../src/context';

describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn();
process.stdout.write = jest.fn() as typeof process.stdout.write;
});

// eslint-disable-next-line jest/expect-expect
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});

// eslint-disable-next-line jest/expect-expect
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});

// eslint-disable-next-line jest/expect-expect
it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
Expand Down
18 changes: 8 additions & 10 deletions __tests__/gpg.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {describe, expect, it} from '@jest/globals';
import * as fs from 'fs';
import * as gpg from '../src/gpg';
import {parseKeygripFromGpgColonsOutput} from '../src/gpg';
Expand Down Expand Up @@ -52,7 +53,6 @@ const userInfos = [
describe('getVersion', () => {
it('returns GnuPG and libgcrypt version', async () => {
await gpg.getVersion().then(version => {
console.log(version);
expect(version.gnupg).not.toEqual('');
expect(version.libgcrypt).not.toEqual('');
});
Expand All @@ -62,7 +62,6 @@ describe('getVersion', () => {
describe('getDirs', () => {
it('returns GnuPG dirs', async () => {
await gpg.getDirs().then(dirs => {
console.log(dirs);
expect(dirs.libdir).not.toEqual('');
expect(dirs.datadir).not.toEqual('');
expect(dirs.homedir).not.toEqual('');
Expand All @@ -71,23 +70,23 @@ describe('getDirs', () => {
});

describe('configureAgent', () => {
// eslint-disable-next-line jest/expect-expect
it('configures GnuPG agent', async () => {
await gpg.configureAgent(gpg.agentConfig);
});
});

for (let userInfo of userInfos) {
for (const userInfo of userInfos) {
// eslint-disable-next-line jest/valid-title
describe(userInfo.key, () => {
describe('importKey', () => {
it('imports key (as armored string) to GnuPG', async () => {
await gpg.importKey(userInfo.pgp).then(output => {
console.log(output);
expect(output).not.toEqual('');
});
});
it('imports key (as base64 string) to GnuPG', async () => {
await gpg.importKey(userInfo.pgp_base64).then(output => {
console.log(output);
expect(output).not.toEqual('');
});
});
Expand All @@ -97,7 +96,6 @@ for (let userInfo of userInfos) {
it('returns the keygrips', async () => {
await gpg.importKey(userInfo.pgp);
await gpg.getKeygrips(userInfo.fingerprint).then(keygrips => {
console.log(keygrips);
expect(keygrips.length).toEqual(userInfo.keygrips.length);
for (let i = 0; i < keygrips.length; i++) {
expect(keygrips[i]).toEqual(userInfo.keygrips[i]);
Expand All @@ -109,9 +107,8 @@ for (let userInfo of userInfos) {
describe('getKeygrip', () => {
it('returns the keygrip for a given fingerprint', async () => {
await gpg.importKey(userInfo.pgp);
for (let [i, fingerprint] of userInfo.fingerprints.entries()) {
for (const [i, fingerprint] of userInfo.fingerprints.entries()) {
await gpg.getKeygrip(fingerprint).then(keygrip => {
console.log(`Fingerprint: ${fingerprint}; Index: ${i}; Keygrip: ${keygrip}`);
expect(keygrip.length).toEqual(userInfo.keygrips[i].length);
expect(keygrip).toEqual(userInfo.keygrips[i]);
});
Expand All @@ -123,16 +120,16 @@ for (let userInfo of userInfos) {
it('presets passphrase', async () => {
await gpg.importKey(userInfo.pgp);
await gpg.configureAgent(gpg.agentConfig);
for (let keygrip of await gpg.getKeygrips(userInfo.fingerprint)) {
for (const keygrip of await gpg.getKeygrips(userInfo.fingerprint)) {
await gpg.presetPassphrase(keygrip, userInfo.passphrase).then(output => {
console.log(output);
expect(output).not.toEqual('');
});
}
});
});

describe('deleteKey', () => {
// eslint-disable-next-line jest/expect-expect
it('removes key from GnuPG', async () => {
await gpg.importKey(userInfo.pgp);
await gpg.deleteKey(userInfo.primary_key_fingerprint);
Expand All @@ -142,6 +139,7 @@ for (let userInfo of userInfos) {
}

describe('killAgent', () => {
// eslint-disable-next-line jest/expect-expect
it('kills GnuPG agent', async () => {
await gpg.killAgent();
});
Expand Down
4 changes: 3 additions & 1 deletion __tests__/openpgp.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {describe, expect, it} from '@jest/globals';
import * as fs from 'fs';
import * as openpgp from '../src/openpgp';

Expand Down Expand Up @@ -44,7 +45,8 @@ const userInfos = [
}
];

for (let userInfo of userInfos) {
for (const userInfo of userInfos) {
// eslint-disable-next-line jest/valid-title
describe(userInfo.key, () => {
describe('readPrivateKey', () => {
it('returns a PGP private key from an armored string', async () => {
Expand Down
72 changes: 72 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# syntax=docker/dockerfile:1.4

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
RUN apk add --no-cache gnupg
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 /
Loading

0 comments on commit 27c90ae

Please sign in to comment.