Skip to content

Commit de3982d

Browse files
authored
Merge pull request #70 from crazy-max/switch-toolkit
switch to actions-toolkit implementation
2 parents 12d39e1 + fa840dd commit de3982d

20 files changed

+3055
-107
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/coverage
12
/node_modules

.eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"env": {
33
"node": true,
4-
"es2021": true
4+
"es2021": true,
5+
"jest": true
56
},
67
"extends": [
78
"eslint:recommended",
89
"plugin:@typescript-eslint/recommended",
10+
"plugin:jest/recommended",
911
"plugin:prettier/recommended"
1012
],
1113
"parser": "@typescript-eslint/parser",
@@ -15,6 +17,7 @@
1517
},
1618
"plugins": [
1719
"@typescript-eslint",
20+
"jest",
1821
"prettier"
1922
]
2023
}

.github/workflows/ci.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ name: ci
22

33
on:
44
schedule:
5-
- cron: '0 10 * * *' # everyday at 10am
5+
- cron: '0 10 * * *'
66
push:
77
branches:
88
- 'master'
99
- 'releases/v*'
1010
tags:
1111
- 'v*'
1212
pull_request:
13-
branches:
14-
- 'master'
15-
- 'releases/v*'
1613

1714
jobs:
1815
main:
@@ -40,9 +37,6 @@ jobs:
4037
-
4138
name: Available platforms
4239
run: echo ${{ steps.qemu.outputs.platforms }}
43-
-
44-
name: Dump context
45-
uses: crazy-max/ghaction-dump-context@v1
4640

4741
error:
4842
runs-on: ubuntu-latest
@@ -67,7 +61,3 @@ jobs:
6761
echo "::error::Should have failed"
6862
exit 1
6963
fi
70-
-
71-
name: Dump context
72-
if: always()
73-
uses: crazy-max/ghaction-dump-context@v1

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'releases/v*'
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v3
17+
-
18+
name: Test
19+
uses: docker/bake-action@v2
20+
with:
21+
targets: test
22+
-
23+
name: Upload coverage
24+
uses: codecov/codecov-action@v3
25+
with:
26+
file: ./coverage/clover.xml

.github/workflows/validate.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@ on:
66
- 'master'
77
- 'releases/v*'
88
pull_request:
9-
branches:
10-
- 'master'
11-
- 'releases/v*'
129

1310
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
targets: ${{ steps.targets.outputs.matrix }}
15+
steps:
16+
-
17+
name: Checkout
18+
uses: actions/checkout@v3
19+
-
20+
name: Targets matrix
21+
id: targets
22+
run: |
23+
echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT
24+
1425
validate:
1526
runs-on: ubuntu-latest
27+
needs:
28+
- prepare
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
target: ${{ fromJson(needs.prepare.outputs.targets) }}
1633
steps:
1734
-
1835
name: Checkout
@@ -21,4 +38,4 @@ jobs:
2138
name: Validate
2239
uses: docker/bake-action@v2
2340
with:
24-
targets: validate
41+
targets: ${{ matrix.target }}

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/.dev
21
node_modules
32
lib
43

5-
# Jetbrains
6-
/.idea
7-
/*.iml
8-
94
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
105
# Logs
116
logs

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[![GitHub release](https://img.shields.io/github/release/docker/setup-qemu-action.svg?style=flat-square)](https://github.com/docker/setup-qemu-action/releases/latest)
22
[![GitHub marketplace](https://img.shields.io/badge/marketplace-docker--setup--qemu-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/docker-setup-qemu)
33
[![CI workflow](https://img.shields.io/github/actions/workflow/status/docker/setup-qemu-action/ci.yml?branch=master&label=ci&logo=github&style=flat-square)](https://github.com/docker/setup-qemu-action/actions?workflow=ci)
4+
[![Test workflow](https://img.shields.io/github/actions/workflow/status/docker/setup-qemu-action/test.yml?branch=master&label=test&logo=github&style=flat-square)](https://github.com/docker/setup-qemu-action/actions?workflow=test)
5+
[![Codecov](https://img.shields.io/codecov/c/github/docker/setup-qemu-action?logo=codecov&style=flat-square)](https://codecov.io/gh/docker/setup-qemu-action)
46

57
## About
68

@@ -39,10 +41,10 @@ jobs:
3941
4042
Following inputs can be used as `step.with` keys
4143

42-
| Name | Type | Description |
43-
|-------------|--------|---------------------------------------------------------------------------------------------------------------------------|
44-
| `image` | String | QEMU static binaries Docker image (default [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags)) |
45-
| `platforms` | String | Platforms to install (e.g. `arm64,riscv64,arm` ; default `all`) |
44+
| Name | Type | Default | Description |
45+
|-------------|--------|-------------------------------------------------------------------------------|--------------------------------------------------|
46+
| `image` | String | [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags) | QEMU static binaries Docker image |
47+
| `platforms` | String | `all` | Platforms to install (e.g., `arm64,riscv64,arm`) |
4648

4749
### outputs
4850

__tests__/context.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {beforeEach, describe, expect, test} from '@jest/globals';
2+
3+
import * as context from '../src/context';
4+
5+
describe('getInputs', () => {
6+
beforeEach(() => {
7+
process.env = Object.keys(process.env).reduce((object, key) => {
8+
if (!key.startsWith('INPUT_')) {
9+
object[key] = process.env[key];
10+
}
11+
return object;
12+
}, {});
13+
});
14+
15+
// prettier-ignore
16+
test.each([
17+
[
18+
0,
19+
new Map<string, string>([]),
20+
{
21+
image: 'tonistiigi/binfmt:latest',
22+
platforms: 'all',
23+
} as context.Inputs
24+
],
25+
[
26+
1,
27+
new Map<string, string>([
28+
['image', 'docker/binfmt:latest'],
29+
['platforms', 'arm64,riscv64,arm'],
30+
]),
31+
{
32+
image: 'docker/binfmt:latest',
33+
platforms: 'arm64,riscv64,arm',
34+
} as context.Inputs
35+
],
36+
[
37+
2,
38+
new Map<string, string>([
39+
['platforms', 'arm64, riscv64, arm '],
40+
]),
41+
{
42+
image: 'tonistiigi/binfmt:latest',
43+
platforms: 'arm64,riscv64,arm',
44+
} as context.Inputs
45+
]
46+
])(
47+
'[%d] given %p as inputs, returns %p',
48+
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
49+
inputs.forEach((value: string, name: string) => {
50+
setInput(name, value);
51+
});
52+
const res = await context.getInputs();
53+
expect(res).toEqual(expected);
54+
}
55+
);
56+
});
57+
58+
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
59+
function getInputName(name: string): string {
60+
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
61+
}
62+
63+
function setInput(name: string, value: string): void {
64+
process.env[getInputName(name)] = value;
65+
}

codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment: false
2+
github_checks:
3+
annotations: false

dev.Dockerfile

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ COPY --from=deps /vendor /
1616

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

2929
FROM deps AS build
@@ -36,14 +36,14 @@ COPY --from=build /out /
3636

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

4949
FROM deps AS format
@@ -59,3 +59,11 @@ FROM deps AS lint
5959
RUN --mount=type=bind,target=.,rw \
6060
--mount=type=cache,target=/src/node_modules \
6161
yarn run lint
62+
63+
FROM deps AS test
64+
RUN --mount=type=bind,target=.,rw \
65+
--mount=type=cache,target=/src/node_modules \
66+
yarn run test --coverageDirectory=/tmp/coverage
67+
68+
FROM scratch AS test-coverage
69+
COPY --from=test /tmp/coverage /

dist/index.js

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/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.

0 commit comments

Comments
 (0)