Skip to content

Commit 14fe2cc

Browse files
authored
Merge pull request #241 from crazy-max/esm
switch to ESM and update config/test wiring
2 parents 7e10951 + db7449a commit 14fe2cc

17 files changed

Lines changed: 1282 additions & 3499 deletions

.prettierrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"singleQuote": true,
77
"trailingComma": "none",
88
"bracketSpacing": false,
9-
"arrowParens": "avoid",
10-
"parser": "typescript"
9+
"arrowParens": "avoid"
1110
}

__tests__/context.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {beforeEach, describe, expect, test} from '@jest/globals';
1+
import {beforeEach, describe, expect, test} from 'vitest';
22

3-
import * as context from '../src/context';
3+
import * as context from '../src/context.js';
44

55
describe('getInputs', () => {
66
beforeEach(() => {
@@ -13,7 +13,7 @@ describe('getInputs', () => {
1313
});
1414

1515
// prettier-ignore
16-
test.each([
16+
const cases: [number, Map<string, string>, context.Inputs][] = [
1717
[
1818
0,
1919
new Map<string, string>([
@@ -23,7 +23,7 @@ describe('getInputs', () => {
2323
image: 'docker.io/tonistiigi/binfmt:latest',
2424
platforms: 'all',
2525
cacheImage: true,
26-
} as context.Inputs
26+
}
2727
],
2828
[
2929
1,
@@ -36,7 +36,7 @@ describe('getInputs', () => {
3636
image: 'docker/binfmt:latest',
3737
platforms: 'arm64,riscv64,arm',
3838
cacheImage: false,
39-
} as context.Inputs
39+
}
4040
],
4141
[
4242
2,
@@ -48,10 +48,11 @@ describe('getInputs', () => {
4848
image: 'docker.io/tonistiigi/binfmt:latest',
4949
platforms: 'arm64,riscv64,arm',
5050
cacheImage: true,
51-
} as context.Inputs
51+
}
5252
]
53-
])(
54-
'[%d] given %p as inputs, returns %p',
53+
];
54+
test.each(cases)(
55+
'[%d] given %o as inputs, returns %o',
5556
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
5657
inputs.forEach((value: string, name: string) => {
5758
setInput(name, value);

__tests__/setup.unit.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import fs from 'node:fs';
2+
import os from 'node:os';
3+
import path from 'node:path';
4+
5+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-setup-qemu-action-'));
6+
7+
process.env = Object.assign({}, process.env, {
8+
TEMP: tmpDir,
9+
GITHUB_REPOSITORY: 'docker/setup-qemu-action',
10+
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
11+
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
12+
});

dev.Dockerfile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
ARG NODE_VERSION=20
44

55
FROM node:${NODE_VERSION}-alpine AS base
6-
RUN apk add --no-cache cpio findutils git
6+
RUN apk add --no-cache cpio findutils git rsync
77
WORKDIR /src
88
RUN --mount=type=bind,target=.,rw \
99
--mount=type=cache,target=/src/.yarn/cache <<EOT
10+
set -e
1011
corepack enable
1112
yarn --version
1213
yarn config set --home enableTelemetry 0
@@ -34,18 +35,27 @@ RUN --mount=type=bind,target=.,rw <<EOT
3435
EOT
3536

3637
FROM deps AS build
37-
RUN --mount=type=bind,target=.,rw \
38+
RUN --mount=target=/context \
3839
--mount=type=cache,target=/src/.yarn/cache \
39-
--mount=type=cache,target=/src/node_modules \
40-
yarn run build && mkdir /out && cp -Rf dist /out/
40+
--mount=type=cache,target=/src/node_modules <<EOT
41+
set -e
42+
rsync -a /context/. .
43+
rm -rf dist
44+
yarn run build
45+
mkdir /out
46+
cp -r dist /out
47+
EOT
4148

4249
FROM scratch AS build-update
4350
COPY --from=build /out /
4451

4552
FROM build AS build-validate
46-
RUN --mount=type=bind,target=.,rw <<EOT
53+
RUN --mount=target=/context \
54+
--mount=target=.,type=tmpfs <<EOT
4755
set -e
56+
rsync -a /context/. .
4857
git add -A
58+
rm -rf dist
4959
cp -rf /out/* .
5060
if [ -n "$(git status --porcelain -- dist)" ]; then
5161
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
@@ -58,8 +68,7 @@ FROM deps AS format
5868
RUN --mount=type=bind,target=.,rw \
5969
--mount=type=cache,target=/src/.yarn/cache \
6070
--mount=type=cache,target=/src/node_modules \
61-
yarn run format \
62-
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' -not -path './.yarn/*' | cpio -pdm /out
71+
yarn run format && mkdir /out && find . -name '*.ts' -not -path './node_modules/*' -not -path './.yarn/*' | cpio -pdm /out
6372

6473
FROM scratch AS format-update
6574
COPY --from=format /out /
@@ -74,7 +83,7 @@ FROM deps AS test
7483
RUN --mount=type=bind,target=.,rw \
7584
--mount=type=cache,target=/src/.yarn/cache \
7685
--mount=type=cache,target=/src/node_modules \
77-
yarn run test --coverage --coverageDirectory=/tmp/coverage
86+
yarn run test --coverage --coverage.reportsDirectory=/tmp/coverage
7887

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

dist/index.js

Lines changed: 15 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {defineConfig} from 'eslint/config';
2+
import js from '@eslint/js';
3+
import tseslint from '@typescript-eslint/eslint-plugin';
4+
import vitest from '@vitest/eslint-plugin';
5+
import globals from 'globals';
6+
import eslintConfigPrettier from 'eslint-config-prettier/flat';
7+
import eslintPluginPrettier from 'eslint-plugin-prettier';
8+
9+
export default defineConfig([
10+
{
11+
ignores: ['.yarn/**/*', 'coverage/**/*', 'dist/**/*']
12+
},
13+
js.configs.recommended,
14+
...tseslint.configs['flat/recommended'],
15+
eslintConfigPrettier,
16+
{
17+
languageOptions: {
18+
globals: {
19+
...globals.node
20+
}
21+
}
22+
},
23+
{
24+
files: ['__tests__/**'],
25+
...vitest.configs.recommended,
26+
languageOptions: {
27+
globals: {
28+
...globals.node,
29+
...vitest.environments.env.globals
30+
}
31+
},
32+
rules: {
33+
...vitest.configs.recommended.rules,
34+
'vitest/no-conditional-expect': 'error',
35+
'vitest/no-disabled-tests': 0
36+
}
37+
},
38+
{
39+
plugins: {
40+
prettier: eslintPluginPrettier
41+
},
42+
rules: {
43+
'prettier/prettier': 'error',
44+
'@typescript-eslint/no-require-imports': [
45+
'error',
46+
{
47+
allowAsImport: true
48+
}
49+
]
50+
}
51+
}
52+
]);

0 commit comments

Comments
 (0)