Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update dev dependencies and workflow #63

Merged
merged 1 commit into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
]
}
15 changes: 3 additions & 12 deletions __tests__/buildx.test.ts
@@ -1,3 +1,4 @@
import {describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
Expand Down Expand Up @@ -26,26 +27,17 @@ jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
describe('getMetadata', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
console.log(`metadataFile: ${metadataFile}`);
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getMetadata();
console.log(`metadata: ${expected}`);
expect(expected).toEqual(metadata);
});
});

describe('isAvailable', () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
execSpy.mockImplementation(() =>
Promise.resolve({
exitCode: expect.any(Number),
stdout: expect.any(Function),
stderr: expect.any(Function)
})
);

const execSpy = jest.spyOn(exec, 'getExecOutput');
buildx.isAvailable();

// eslint-disable-next-line jest/no-standalone-expect
expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], {
silent: true,
ignoreReturnCode: true
Expand All @@ -55,7 +47,6 @@ describe('isAvailable', () => {
describe('getVersion', () => {
it('valid', async () => {
const version = await buildx.getVersion();
console.log(`version: ${version}`);
expect(semver.valid(version)).not.toBeNull();
}, 100000);
});
Expand Down
47 changes: 19 additions & 28 deletions __tests__/context.test.ts
@@ -1,67 +1,59 @@
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
import * as os from 'os';
import * as context from '../src/context';

describe('getInputList', () => {
it('single line correctly', async () => {
await setInput('foo', 'bar');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar']);
});

it('multiline correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('empty lines correctly', async () => {
setInput('foo', 'bar\n\nbaz');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('comma correctly', async () => {
setInput('foo', 'bar,baz');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('empty result correctly', async () => {
setInput('foo', 'bar,baz,');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});

it('different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = await context.getInputList('foo');
console.log(res);
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz', 'bat']);
});

it('multiline and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
const res = await context.getInputList('cache-from', true);
console.log(res);
const res = context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});

it('different new lines and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
const res = await context.getInputList('cache-from', true);
console.log(res);
const res = context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});

Expand All @@ -74,8 +66,7 @@ bbbbbbb
ccccccccc"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
Expand All @@ -98,8 +89,7 @@ FOO=bar
bbbb
ccc"`
);
const res = await context.getInputList('secrets', true);
console.log(res);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
Expand All @@ -122,8 +112,7 @@ bbbbbbb
ccccccccc
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
const res = context.getInputList('secrets', true);
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
});

Expand All @@ -136,12 +125,11 @@ bbbb""bbb
ccccccccc"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbb\"bbb
bbbb"bbb
ccccccccc`,
'FOO=bar'
]);
Expand All @@ -163,19 +151,22 @@ describe('asyncForEach', () => {

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
12 changes: 6 additions & 6 deletions hack/build.Dockerfile → dev.Dockerfile
@@ -1,8 +1,8 @@
# syntax=docker/dockerfile:1.3-labs
# syntax=docker/dockerfile:1

ARG NODE_VERSION
ARG DOCKER_VERSION=20.10.10
ARG BUILDX_VERSION=0.7.0
ARG NODE_VERSION=12
ARG DOCKER_VERSION=20.10.13
ARG BUILDX_VERSION=0.8.1

FROM node:${NODE_VERSION}-alpine AS base
RUN apk add --no-cache cpio findutils git
Expand Down Expand Up @@ -57,10 +57,10 @@ RUN --mount=type=bind,target=.,rw \
FROM scratch AS format-update
COPY --from=format /out /

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

FROM docker:${DOCKER_VERSION} as docker
FROM docker/buildx-bin:${BUILDX_VERSION} as buildx
Expand Down