Skip to content

Commit 45de2ea

Browse files
authored
Enhance workflow (#151)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent 6d4e7db commit 45de2ea

File tree

8 files changed

+136
-121
lines changed

8 files changed

+136
-121
lines changed

.dockerignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
/.dev
21
/coverage
3-
/dist
4-
/lib
52
/node_modules
6-
/.env

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ 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*'
10+
tags:
11+
- 'v*'
1012
pull_request:
1113
branches:
1214
- 'master'
15+
- 'releases/v*'
1316

1417
jobs:
1518
ci:

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ on:
55
branches:
66
- 'master'
77
- 'releases/v*'
8-
paths-ignore:
9-
- '**.md'
108
pull_request:
119
branches:
1210
- 'master'
13-
paths-ignore:
14-
- '**.md'
11+
- 'releases/v*'
1512

1613
jobs:
1714
test:
@@ -21,11 +18,15 @@ jobs:
2118
name: Checkout
2219
uses: actions/checkout@v2
2320
-
24-
name: Install
25-
run: yarn install
21+
name: Validate
22+
uses: docker/bake-action@v1
23+
with:
24+
targets: validate
2625
-
2726
name: Test
28-
run: yarn run test
27+
uses: docker/bake-action@v1
28+
with:
29+
targets: test
2930
env:
3031
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3132
-

.github/workflows/validate.yml

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

Dockerfile.dev

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

docker-bake.hcl

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,77 @@
11
variable "GITHUB_REPOSITORY" {
22
default = "crazy-max/ghaction-github-labeler"
33
}
4+
variable "NODE_VERSION" {
5+
default = "12"
6+
}
7+
8+
target "_common" {
9+
args = {
10+
NODE_VERSION = NODE_VERSION
11+
GITHUB_REPOSITORY = GITHUB_REPOSITORY
12+
}
13+
}
414

515
group "default" {
616
targets = ["build"]
717
}
818

919
group "pre-checkin" {
10-
targets = ["update-yarn", "format", "build"]
20+
targets = ["vendor-update", "format", "build"]
1121
}
1222

1323
group "validate" {
14-
targets = ["validate-format", "validate-build", "validate-yarn"]
24+
targets = ["vendor-validate", "format-validate", "build-validate"]
1525
}
1626

17-
target "dockerfile" {
18-
dockerfile = "Dockerfile.dev"
27+
target "vendor-update" {
28+
inherits = ["_common"]
29+
dockerfile = "./hack/build.Dockerfile"
30+
target = "vendor-update"
31+
output = ["."]
1932
}
2033

21-
target "update-yarn" {
22-
inherits = ["dockerfile"]
23-
target = "update-yarn"
24-
output = ["."]
34+
target "vendor-validate" {
35+
inherits = ["_common"]
36+
dockerfile = "./hack/build.Dockerfile"
37+
target = "vendor-validate"
2538
}
2639

2740
target "build" {
28-
inherits = ["dockerfile"]
29-
target = "dist"
41+
inherits = ["_common"]
42+
dockerfile = "./hack/build.Dockerfile"
43+
target = "build-update"
3044
output = ["."]
3145
}
3246

33-
//target "test" {
34-
// args = {
35-
// GITHUB_REPOSITORY = "${GITHUB_REPOSITORY}"
36-
// }
37-
// inherits = ["dockerfile"]
38-
// secret = ["id=github_token,src=.dev/.ghtoken"]
39-
// target = "test-coverage"
40-
// output = ["."]
41-
//}
47+
target "build-validate" {
48+
inherits = ["_common"]
49+
dockerfile = "./hack/build.Dockerfile"
50+
target = "build-validate"
51+
}
4252

4353
target "format" {
44-
inherits = ["dockerfile"]
45-
target = "format"
54+
inherits = ["_common"]
55+
dockerfile = "./hack/build.Dockerfile"
56+
target = "format-update"
4657
output = ["."]
4758
}
4859

49-
target "validate-format" {
50-
inherits = ["dockerfile"]
51-
target = "validate-format"
60+
target "format-validate" {
61+
inherits = ["_common"]
62+
dockerfile = "./hack/build.Dockerfile"
63+
target = "format-validate"
5264
}
5365

54-
target "validate-build" {
55-
inherits = ["dockerfile"]
56-
target = "validate-build"
66+
target "test" {
67+
inherits = ["_common"]
68+
dockerfile = "./hack/test.Dockerfile"
69+
secret = ["id=GITHUB_TOKEN,env=GITHUB_TOKEN"]
70+
target = "test-coverage"
71+
output = ["./coverage"]
5772
}
5873

59-
target "validate-yarn" {
60-
inherits = ["dockerfile"]
61-
target = "validate-yarn"
74+
target "test-local" {
75+
inherits = ["test"]
76+
secret = ["id=GITHUB_TOKEN,src=.dev/.ghtoken"]
6277
}

hack/build.Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# syntax=docker/dockerfile:1.3
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 && mkdir /vendor && cp yarn.lock /vendor
12+
13+
FROM scratch AS vendor-update
14+
COPY --from=deps /vendor /
15+
16+
FROM deps AS vendor-validate
17+
RUN --mount=type=bind,target=.,rw \
18+
git add -A && cp -rf /vendor/* .; \
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
24+
25+
FROM deps AS build
26+
RUN --mount=type=bind,target=.,rw \
27+
--mount=type=cache,target=/src/node_modules \
28+
yarn run build && mkdir /out && cp -Rf dist /out/
29+
30+
FROM scratch AS build-update
31+
COPY --from=build /out /
32+
33+
FROM build AS build-validate
34+
RUN --mount=type=bind,target=.,rw \
35+
git add -A && cp -rf /out/* .; \
36+
if [ -n "$(git status --porcelain -- dist)" ]; then \
37+
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'; \
38+
git status --porcelain -- dist; \
39+
exit 1; \
40+
fi
41+
42+
FROM deps AS format
43+
RUN --mount=type=bind,target=.,rw \
44+
--mount=type=cache,target=/src/node_modules \
45+
yarn run format \
46+
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out
47+
48+
FROM scratch AS format-update
49+
COPY --from=format /out /
50+
51+
FROM deps AS format-validate
52+
RUN --mount=type=bind,target=.,rw \
53+
--mount=type=cache,target=/src/node_modules \
54+
yarn run format-check \

hack/test.Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# syntax=docker/dockerfile:1.3
2+
ARG NODE_VERSION
3+
ARG GITHUB_REPOSITORY
4+
5+
FROM node:${NODE_VERSION}-alpine AS base
6+
RUN apk add --no-cache git
7+
WORKDIR /src
8+
9+
FROM base AS deps
10+
RUN --mount=type=bind,target=.,rw \
11+
--mount=type=cache,target=/src/node_modules \
12+
yarn install
13+
14+
FROM deps AS test
15+
ENV RUNNER_TEMP=/tmp/github_runner
16+
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
17+
ARG GITHUB_REPOSITORY
18+
ENV GITHUB_REPOSITORY=${GITHUB_REPOSITORY}
19+
RUN --mount=type=bind,target=.,rw \
20+
--mount=type=cache,target=/src/node_modules \
21+
--mount=type=secret,id=GITHUB_TOKEN \
22+
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test --coverageDirectory=/tmp/coverage
23+
24+
FROM scratch AS test-coverage
25+
COPY --from=test /tmp/coverage /

0 commit comments

Comments
 (0)