Skip to content

Commit cb02c5f

Browse files
committedApr 1, 2021
Enhance workflow
Signed-off-by: CrazyMax <[email protected]>
1 parent f0d07f4 commit cb02c5f

15 files changed

+184
-149
lines changed
 

‎.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/coverage
2+
/node_modules

‎.github/CONTRIBUTING.md

+11-22
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,24 @@
22

33
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
44

5-
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
5+
Contributions to this project are [released](https://docs.github.com/en/github/site-policy/github-terms-of-service#6-contributions-under-repository-license)
6+
to the public under the [project's open source license](LICENSE).
67

78
## Submitting a pull request
89

910
1. [Fork](https://github.com/docker/setup-buildx-action/fork) and clone the repository
1011
2. Configure and install the dependencies: `yarn install`
1112
3. Create a new branch: `git checkout -b my-branch-name`
12-
4. Make your change, add tests, and make sure the tests still pass
13-
5. Run pre-checkin: `yarn run pre-checkin`
14-
6. Push to your fork and [submit a pull request](https://github.com/docker/setup-buildx-action/compare)
15-
7. Pat yourself on the back and wait for your pull request to be reviewed and merged.
16-
17-
## Container based developer flow
18-
19-
If you don't want to maintain a Node developer environment that fits this project you can use containerized commands instead of invoking yarn directly.
20-
21-
```
22-
# format code and build javascript artifacts
23-
docker buildx bake pre-checkin
24-
25-
# validate all code has correctly formatted and built
26-
docker buildx bake validate
27-
28-
# run tests
29-
docker buildx bake test
30-
```
13+
4. Make your changes
14+
5. Make sure the tests pass: `docker buildx bake test`
15+
6. Format code and build javascript artifacts: `docker buildx bake pre-checkin`
16+
7. Validate all code has correctly formatted and built: `docker buildx bake validate`
17+
8. Push to your fork and [submit a pull request](https://github.com/docker/setup-buildx-action/compare)
18+
9. Pat your self on the back and wait for your pull request to be reviewed and merged.
3119

3220
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
3321

22+
- Write tests.
3423
- Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.
3524
- We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
3625
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as **separate pull requests**.
@@ -39,5 +28,5 @@ Here are a few things you can do that will increase the likelihood of your pull
3928
## Resources
4029

4130
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
42-
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
43-
- [GitHub Help](https://help.github.com)
31+
- [Using Pull Requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests)
32+
- [GitHub Help](https://docs.github.com/en)

‎.github/ISSUE_TEMPLATE/bug_report.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ about: Create a report to help us improve
3030

3131
### Logs
3232

33-
> Download the [log file of your build](https://help.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run#downloading-logs) and [attach it](https://help.github.com/en/github/managing-your-work-on-github/file-attachments-on-issues-and-pull-requests) to this issue.
33+
> Download the [log file of your build](https://docs.github.com/en/actions/managing-workflow-runs/using-workflow-run-logs#downloading-logs)
34+
> and [attach it](https://docs.github.com/en/github/managing-your-work-on-github/file-attachments-on-issues-and-pull-requests) to this issue.

‎.github/setup-buildx-action.png

565 Bytes
Loading

‎.github/workflows/ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name: ci
22

33
on:
4+
schedule:
5+
- cron: '0 10 * * *' # everyday at 10am
46
push:
57
branches:
6-
- master
7-
- releases/v*
8-
paths-ignore:
9-
- "**.md"
8+
- 'master'
9+
- 'releases/v*'
10+
tags:
11+
- 'v*'
1012
pull_request:
1113
branches:
12-
- master
13-
- releases/v*
14-
paths-ignore:
15-
- "**.md"
14+
- 'master'
15+
- 'releases/v*'
1616

1717
jobs:
1818
main:

‎.github/workflows/test.yml

+12-24
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,32 @@ name: test
33
on:
44
push:
55
branches:
6-
- master
7-
- releases/v*
8-
paths-ignore:
9-
- "**.md"
6+
- 'master'
7+
- 'releases/v*'
108
pull_request:
11-
paths-ignore:
12-
- "**.md"
9+
branches:
10+
- 'master'
11+
- 'releases/v*'
1312

1413
jobs:
15-
test-containerized:
16-
runs-on: ubuntu-latest
17-
steps:
18-
-
19-
name: Checkout
20-
uses: actions/checkout@v2
21-
-
22-
name: Validate
23-
run: docker buildx bake validate
24-
-
25-
name: Test
26-
run: docker buildx bake test
27-
2814
test:
2915
runs-on: ubuntu-latest
3016
steps:
3117
-
3218
name: Checkout
3319
uses: actions/checkout@v2
3420
-
35-
name: Install
36-
run: yarn install
21+
name: Validate
22+
uses: docker/bake-action@v1
23+
with:
24+
targets: validate
3725
-
3826
name: Test
39-
run: yarn run test
27+
uses: docker/bake-action@v1
28+
with:
29+
targets: test
4030
-
4131
name: Upload coverage
4232
uses: codecov/codecov-action@v1
43-
if: success()
4433
with:
45-
token: ${{ secrets.CODECOV_TOKEN }}
4634
file: ./coverage/clover.xml

‎Dockerfile

-52
This file was deleted.

‎dist/index.js

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docker-bake.hcl

+43-18
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,67 @@
1+
variable "NODE_VERSION" {
2+
default = "12"
3+
}
4+
5+
target "node-version" {
6+
args = {
7+
NODE_VERSION = NODE_VERSION
8+
}
9+
}
10+
111
group "default" {
212
targets = ["build"]
313
}
414

515
group "pre-checkin" {
6-
targets = ["update-yarn", "format", "build"]
16+
targets = ["vendor-update", "format", "build"]
717
}
818

919
group "validate" {
10-
targets = ["validate-format", "validate-build", "validate-yarn"]
11-
}
12-
13-
target "update-yarn" {
14-
target = "update-yarn"
15-
output = ["."]
20+
targets = ["format-validate", "build-validate", "vendor-validate"]
1621
}
1722

1823
target "build" {
19-
target = "dist"
24+
inherits = ["node-version"]
25+
dockerfile = "./hack/build.Dockerfile"
26+
target = "build-update"
2027
output = ["."]
2128
}
2229

23-
target "test" {
24-
target = "test"
30+
target "build-validate" {
31+
inherits = ["node-version"]
32+
dockerfile = "./hack/build.Dockerfile"
33+
target = "build-validate"
2534
}
2635

2736
target "format" {
28-
target = "format"
37+
inherits = ["node-version"]
38+
dockerfile = "./hack/build.Dockerfile"
39+
target = "format-update"
2940
output = ["."]
3041
}
3142

32-
target "validate-format" {
33-
target = "validate-format"
43+
target "format-validate" {
44+
inherits = ["node-version"]
45+
dockerfile = "./hack/build.Dockerfile"
46+
target = "format-validate"
47+
}
48+
49+
target "vendor-update" {
50+
inherits = ["node-version"]
51+
dockerfile = "./hack/vendor.Dockerfile"
52+
target = "update"
53+
output = ["."]
3454
}
3555

36-
target "validate-build" {
37-
target = "validate-build"
56+
target "vendor-validate" {
57+
inherits = ["node-version"]
58+
dockerfile = "./hack/vendor.Dockerfile"
59+
target = "validate"
3860
}
3961

40-
target "validate-yarn" {
41-
target = "validate-yarn"
42-
}
62+
target "test" {
63+
inherits = ["node-version"]
64+
dockerfile = "./hack/test.Dockerfile"
65+
target = "test-coverage"
66+
output = ["./coverage"]
67+
}

‎hack/build.Dockerfile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# syntax=docker/dockerfile:1.2
2+
ARG NODE_VERSION
3+
4+
FROM node:${NODE_VERSION}-alpine AS base
5+
RUN apk add --no-cache cpio findutils git
6+
WORKDIR /src
7+
8+
FROM base AS deps
9+
RUN --mount=type=bind,target=.,rw \
10+
--mount=type=cache,target=/src/node_modules \
11+
yarn install
12+
13+
FROM deps AS build
14+
RUN --mount=type=bind,target=.,rw \
15+
--mount=type=cache,target=/src/node_modules \
16+
yarn run build && mkdir /out && cp -Rf dist /out/
17+
18+
FROM scratch AS build-update
19+
COPY --from=build /out /
20+
21+
FROM build AS build-validate
22+
RUN --mount=type=bind,target=.,rw \
23+
git add -A && cp -rf /out/* .; \
24+
if [ -n "$(git status --porcelain -- dist)" ]; then \
25+
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'; \
26+
git status --porcelain -- dist; \
27+
exit 1; \
28+
fi
29+
30+
FROM deps AS format
31+
RUN --mount=type=bind,target=.,rw \
32+
--mount=type=cache,target=/src/node_modules \
33+
yarn run format \
34+
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out
35+
36+
FROM scratch AS format-update
37+
COPY --from=format /out /
38+
39+
FROM deps AS format-validate
40+
RUN --mount=type=bind,target=.,rw \
41+
--mount=type=cache,target=/src/node_modules \
42+
yarn run format-check \

‎hack/shell

-6
This file was deleted.

‎hack/test.Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# syntax=docker/dockerfile:1.2
2+
ARG NODE_VERSION
3+
4+
FROM node:${NODE_VERSION}-alpine AS base
5+
RUN apk add --no-cache git
6+
WORKDIR /src
7+
8+
FROM base AS deps
9+
RUN --mount=type=bind,target=.,rw \
10+
--mount=type=cache,target=/src/node_modules \
11+
yarn install
12+
13+
FROM deps AS test
14+
ENV RUNNER_TEMP=/tmp/github_runner
15+
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
16+
RUN --mount=type=bind,target=.,rw \
17+
--mount=type=cache,target=/src/node_modules \
18+
--mount=type=bind,from=crazymax/docker,source=/usr/libexec/docker/cli-plugins/docker-buildx,target=/usr/libexec/docker/cli-plugins/docker-buildx \
19+
--mount=type=bind,from=crazymax/docker,source=/usr/local/bin/docker,target=/usr/bin/docker \
20+
yarn run test --coverageDirectory=/tmp/coverage
21+
22+
FROM scratch AS test-coverage
23+
COPY --from=test /tmp/coverage /

‎hack/vendor.Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# syntax=docker/dockerfile:1.2
2+
ARG NODE_VERSION
3+
4+
FROM node:${NODE_VERSION}-alpine AS base
5+
RUN apk add --no-cache git
6+
WORKDIR /src
7+
8+
FROM base AS vendored
9+
RUN --mount=type=bind,target=.,rw \
10+
--mount=type=cache,target=/src/node_modules \
11+
yarn install && mkdir /out && cp yarn.lock /out
12+
13+
FROM scratch AS update
14+
COPY --from=vendored /out /
15+
16+
FROM vendored AS validate
17+
RUN --mount=type=bind,target=.,rw \
18+
git add -A && cp -rf /out/* .; \
19+
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then \
20+
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \
21+
git status --porcelain -- yarn.lock; \
22+
exit 1; \
23+
fi

‎src/buildx.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function install(inputVersion: string, dockerConfigHome: string): P
5252
if (!release) {
5353
throw new Error(`Cannot find buildx ${inputVersion} release`);
5454
}
55-
core.debug(`Release found: ${release.tag_name}`);
55+
core.debug(`Release ${release.tag_name} found`);
5656
const version = release.tag_name.replace(/^v+|v+$/g, '');
5757

5858
let toolPath: string;
@@ -76,7 +76,7 @@ export async function install(inputVersion: string, dockerConfigHome: string): P
7676
core.debug(`Plugin path is ${pluginPath}`);
7777
fs.copyFileSync(path.join(toolPath, filename), pluginPath);
7878

79-
core.info('🔨 Fixing perms...');
79+
core.info('Fixing perms');
8080
fs.chmodSync(pluginPath, '0755');
8181

8282
return pluginPath;
@@ -92,7 +92,7 @@ async function download(version: string): Promise<string> {
9292
let downloadPath: string;
9393

9494
try {
95-
core.info(`⬇️ Downloading ${downloadUrl}...`);
95+
core.info(`Downloading ${downloadUrl}`);
9696
downloadPath = await tc.downloadTool(downloadUrl);
9797
core.debug(`Downloaded to ${downloadPath}`);
9898
} catch (error) {

‎src/main.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ async function run(): Promise<void> {
1919
const dockerConfigHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
2020

2121
if (!(await buildx.isAvailable()) || inputs.version) {
22-
core.startGroup(`👉 Installing Buildx`);
22+
core.startGroup(`Installing buildx`);
2323
await buildx.install(inputs.version || 'latest', dockerConfigHome);
2424
core.endGroup();
2525
}
2626

2727
const buildxVersion = await buildx.getVersion();
28-
core.info(`📣 Buildx version: ${buildxVersion}`);
28+
core.info(`Using buildx ${buildxVersion}`);
2929

3030
const builderName: string = inputs.driver == 'docker' ? 'default' : `builder-${require('uuid').v4()}`;
3131
core.setOutput('name', builderName);
3232
stateHelper.setBuilderName(builderName);
3333

3434
if (inputs.driver !== 'docker') {
35-
core.startGroup(`🔨 Creating a new builder instance`);
35+
core.startGroup(`Creating a new builder instance`);
3636
let createArgs: Array<string> = ['buildx', 'create', '--name', builderName, '--driver', inputs.driver];
3737
if (semver.satisfies(buildxVersion, '>=0.3.0')) {
3838
await context.asyncForEach(inputs.driverOpts, async driverOpt => {
@@ -51,7 +51,7 @@ async function run(): Promise<void> {
5151
await exec.exec('docker', createArgs);
5252
core.endGroup();
5353

54-
core.startGroup(`🏃 Booting builder`);
54+
core.startGroup(`Booting builder`);
5555
let bootstrapArgs: Array<string> = ['buildx', 'inspect', '--bootstrap'];
5656
if (semver.satisfies(buildxVersion, '>=0.4.0')) {
5757
bootstrapArgs.push('--builder', builderName);
@@ -61,12 +61,12 @@ async function run(): Promise<void> {
6161
}
6262

6363
if (inputs.install) {
64-
core.startGroup(`🤝 Setting buildx as default builder`);
64+
core.startGroup(`Setting buildx as default builder`);
6565
await exec.exec('docker', ['buildx', 'install']);
6666
core.endGroup();
6767
}
6868

69-
core.startGroup(`🛒 Extracting available platforms`);
69+
core.startGroup(`Extracting available platforms`);
7070
const platforms = await buildx.platforms();
7171
core.info(`${platforms}`);
7272
core.setOutput('platforms', platforms);

0 commit comments

Comments
 (0)
Please sign in to comment.