Skip to content

Commit ea84e71

Browse files
committed
ci: reusable test workflow
Signed-off-by: CrazyMax <[email protected]>
1 parent 214e98b commit ea84e71

File tree

3 files changed

+232
-238
lines changed

3 files changed

+232
-238
lines changed

.github/workflows/.test.yml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# reusable workflow
2+
name: .test
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
cache_scope:
8+
required: true
9+
type: string
10+
pkgs:
11+
required: true
12+
type: string
13+
kinds:
14+
required: true
15+
type: string
16+
tags:
17+
required: false
18+
type: string
19+
codecov_flags:
20+
required: false
21+
type: string
22+
includes:
23+
required: false
24+
type: string
25+
env:
26+
required: false
27+
type: string
28+
29+
env:
30+
REPO_SLUG_ORIGIN: "moby/buildkit:latest"
31+
TESTFLAGS: "-v --parallel=6 --timeout=30m"
32+
BUILDX_VERSION: "latest" # leave empty to use the one available on GitHub virtual environment
33+
GO_VERSION: "1.19"
34+
35+
jobs:
36+
prepare:
37+
runs-on: ubuntu-20.04
38+
outputs:
39+
pkgs: ${{ steps.set.outputs.pkgs }}
40+
kinds: ${{ steps.set.outputs.kinds }}
41+
tags: ${{ steps.set.outputs.tags }}
42+
includes: ${{ steps.set.outputs.includes }}
43+
steps:
44+
-
45+
name: Checkout
46+
uses: actions/checkout@v3
47+
-
48+
name: Expose GitHub Runtime
49+
uses: crazy-max/ghaction-github-runtime@v2
50+
-
51+
name: Set up QEMU
52+
uses: docker/setup-qemu-action@v2
53+
-
54+
name: Set up Docker Buildx
55+
uses: docker/setup-buildx-action@v2
56+
with:
57+
version: ${{ env.BUILDX_VERSION }}
58+
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
59+
buildkitd-flags: --debug
60+
-
61+
name: Deps
62+
run: |
63+
npm install js-yaml
64+
-
65+
name: Set outputs
66+
id: set
67+
uses: actions/github-script@v6
68+
with:
69+
script: |
70+
const yaml = require('js-yaml');
71+
await core.group(`Set pkgs matrix`, async () => {
72+
const pkgs = `${{ inputs.pkgs }}`.trim().split(/\r?\n/);
73+
core.info(JSON.stringify(pkgs, null, 2));
74+
core.setOutput('pkgs', JSON.stringify(pkgs));
75+
});
76+
await core.group(`Set kinds matrix`, async () => {
77+
const kinds = `${{ inputs.kinds }}`.trim().split(/\r?\n/);
78+
core.info(JSON.stringify(kinds, null, 2));
79+
core.setOutput('kinds', JSON.stringify(kinds));
80+
});
81+
await core.group(`Set tags matrix`, async () => {
82+
const tags = `${{ inputs.tags }}`.trim().split(/\r?\n/);
83+
core.info(JSON.stringify(tags, null, 2));
84+
core.setOutput('tags', JSON.stringify(tags));
85+
});
86+
await core.group(`Set includes`, async () => {
87+
const includes = yaml.load(`${{ inputs.includes }}`.trim());
88+
core.info(JSON.stringify(includes, null, 2));
89+
core.setOutput('includes', JSON.stringify(includes ?? []));
90+
});
91+
-
92+
name: Build
93+
run: |
94+
./hack/build_ci_first_pass integration-tests
95+
env:
96+
CACHE_FROM: type=gha,scope=${{ inputs.cache_scope }}
97+
CACHE_TO: type=gha,scope=${{ inputs.cache_scope }}
98+
99+
run:
100+
runs-on: ubuntu-20.04
101+
needs:
102+
- prepare
103+
strategy:
104+
fail-fast: false
105+
matrix:
106+
pkg: ${{ fromJson(needs.prepare.outputs.pkgs) }}
107+
kind: ${{ fromJson(needs.prepare.outputs.kinds) }}
108+
tags: ${{ fromJson(needs.prepare.outputs.tags) }}
109+
include: ${{ fromJson(needs.prepare.outputs.includes) }}
110+
worker:
111+
- containerd
112+
- containerd-rootless
113+
- containerd-1.6
114+
- containerd-snapshotter-stargz
115+
- oci
116+
- oci-rootless
117+
- oci-snapshotter-stargz
118+
steps:
119+
-
120+
name: Environment variables
121+
run: |
122+
for l in "${{ inputs.env }}"; do
123+
echo "${l?}" >> $GITHUB_ENV
124+
done
125+
-
126+
name: Checkout
127+
uses: actions/checkout@v3
128+
-
129+
name: Expose GitHub Runtime
130+
uses: crazy-max/ghaction-github-runtime@v2
131+
-
132+
name: Set up QEMU
133+
uses: docker/setup-qemu-action@v2
134+
-
135+
name: Set up Docker Buildx
136+
uses: docker/setup-buildx-action@v2
137+
with:
138+
version: ${{ env.BUILDX_VERSION }}
139+
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
140+
buildkitd-flags: --debug
141+
-
142+
name: Test
143+
continue-on-error: ${{ matrix.tags == 'nydus' }}
144+
run: |
145+
if [ -n "${{ matrix.tags }}" ]; then
146+
TESTFLAGS="${TESTFLAGS} --tags=${{ matrix.tags }}"
147+
export BUILDKITD_TAGS="${{ matrix.tags }}"
148+
fi
149+
if [ -n "${{ matrix.worker }}" ]; then
150+
export TESTFLAGS="${TESTFLAGS} --run=//worker=${{ matrix.worker }}$"
151+
fi
152+
./hack/test ${{ matrix.kind }}
153+
mv ./coverage/coverage.txt ./coverage/coverage-${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.skip-integration-tests }}-${{ matrix.kind }}-${{ matrix.worker }}-${{ matrix.tags }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]').txt
154+
env:
155+
TEST_COVERAGE: 1
156+
TESTPKGS: ${{ matrix.pkg }}
157+
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-integration-tests }}
158+
CACHE_FROM: type=gha,scope=${{ inputs.cache_scope }}
159+
-
160+
name: Upload coverage file
161+
continue-on-error: ${{ matrix.tags == 'nydus' }}
162+
uses: actions/upload-artifact@v3
163+
with:
164+
name: coverage
165+
path: ./coverage
166+
167+
upload-coverage:
168+
runs-on: ubuntu-20.04
169+
needs:
170+
- run
171+
steps:
172+
-
173+
name: Checkout
174+
uses: actions/checkout@v3
175+
-
176+
name: Download coverage files
177+
uses: actions/download-artifact@v3
178+
with:
179+
name: coverage
180+
path: ./coverage
181+
-
182+
name: List coverage files
183+
id: files
184+
uses: actions/github-script@v6
185+
with:
186+
result-encoding: string
187+
script: |
188+
return require('fs').readdirSync('./coverage', {withFileTypes: true})
189+
.filter(item => !item.isDirectory())
190+
.map(item => `./coverage/${item.name}`)
191+
.join(',');
192+
-
193+
name: Send to Codecov
194+
uses: codecov/codecov-action@v3
195+
with:
196+
files: ${{ steps.files.outputs.result }}
197+
flags: ${{ matrix.codecov_flags }}

.github/workflows/build.yml

Lines changed: 22 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ env:
2323
REPO_SLUG_ORIGIN: "moby/buildkit:latest"
2424
REPO_SLUG_TARGET: "moby/buildkit"
2525
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le,linux/riscv64"
26-
CACHE_GHA_SCOPE_IT: "build-integration-tests"
2726
CACHE_GHA_SCOPE_BINARIES: "binaries"
2827
CACHE_GHA_SCOPE_CROSS: "cross"
29-
TESTFLAGS: "-v --parallel=6 --timeout=30m"
3028
BUILDX_VERSION: "latest" # leave empty to use the one available on GitHub virtual environment
3129
GO_VERSION: "1.19"
3230

@@ -57,124 +55,30 @@ jobs:
5755
env:
5856
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }}
5957
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }}
60-
-
61-
name: Build ${{ env.CACHE_GHA_SCOPE_IT }}
62-
run: |
63-
./hack/build_ci_first_pass integration-tests
64-
env:
65-
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
66-
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
6758

6859
test:
69-
runs-on: ubuntu-20.04
70-
needs:
71-
- base
72-
strategy:
73-
fail-fast: false
74-
matrix:
75-
pkg:
76-
- ./client ./cmd/buildctl ./worker/containerd ./solver ./frontend
77-
worker:
78-
- containerd
79-
- containerd-rootless
80-
- containerd-1.6
81-
- containerd-snapshotter-stargz
82-
- oci
83-
- oci-rootless
84-
- oci-snapshotter-stargz
85-
typ:
86-
- integration
87-
tags:
88-
- ''
89-
include:
90-
- pkg: ./...
91-
skip-integration-tests: 1
92-
typ: integration gateway
93-
- pkg: ./client
94-
worker: containerd
95-
tags: nydus
96-
typ: integration
97-
- pkg: ./client
98-
worker: oci
99-
tags: nydus
100-
typ: integration
101-
- pkg: ./...
102-
tags: nydus
103-
skip-integration-tests: 1
104-
typ: integration
105-
steps:
106-
-
107-
name: Checkout
108-
uses: actions/checkout@v3
109-
-
110-
name: Expose GitHub Runtime
111-
uses: crazy-max/ghaction-github-runtime@v2
112-
-
113-
name: Set up QEMU
114-
uses: docker/setup-qemu-action@v2
115-
-
116-
name: Set up Docker Buildx
117-
uses: docker/setup-buildx-action@v2
118-
with:
119-
version: ${{ env.BUILDX_VERSION }}
120-
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
121-
buildkitd-flags: --debug
122-
-
123-
name: Test
124-
continue-on-error: ${{ matrix.tags == 'nydus' }}
125-
run: |
126-
if [ -n "${{ matrix.tags }}" ]; then
127-
TESTFLAGS="${TESTFLAGS} --tags=${{ matrix.tags }}"
128-
export BUILDKITD_TAGS="${{ matrix.tags }}"
129-
fi
130-
if [ -n "${{ matrix.worker }}" ]; then
131-
export TESTFLAGS="${TESTFLAGS} --run=//worker=${{ matrix.worker }}$"
132-
fi
133-
./hack/test ${{ matrix.typ }}
134-
mv ./coverage/coverage.txt ./coverage/coverage-${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.skip-integration-tests }}-${{ matrix.typ }}-${{ matrix.worker }}-${{ matrix.tags }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]').txt
135-
env:
136-
TEST_COVERAGE: 1
137-
TESTPKGS: ${{ matrix.pkg }}
138-
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-integration-tests }}
139-
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
140-
-
141-
name: Upload coverage file
142-
continue-on-error: ${{ matrix.tags == 'nydus' }}
143-
uses: actions/upload-artifact@v3
144-
with:
145-
name: coverage
146-
path: ./coverage
147-
148-
upload-coverage:
149-
runs-on: ubuntu-20.04
150-
needs:
151-
- test
152-
steps:
153-
-
154-
name: Checkout
155-
uses: actions/checkout@v3
156-
-
157-
name: Download coverage files
158-
uses: actions/download-artifact@v3
159-
with:
160-
name: coverage
161-
path: ./coverage
162-
-
163-
name: List coverage files
164-
uses: actions/github-script@v6
165-
id: files
166-
with:
167-
result-encoding: string
168-
script: |
169-
return require('fs').readdirSync('./coverage', {withFileTypes: true})
170-
.filter(item => !item.isDirectory())
171-
.map(item => `./coverage/${item.name}`)
172-
.join(',');
173-
-
174-
name: Send to Codecov
175-
uses: codecov/codecov-action@v3
176-
with:
177-
files: ${{ steps.files.outputs.result }}
60+
uses: ./.github/workflows/.test.yml
61+
with:
62+
cache_scope: build-integration-tests
63+
pkgs: ./client ./cmd/buildctl ./worker/containerd ./solver ./frontend
64+
kinds: integration
65+
codecov_flags: core
66+
includes: |
67+
- pkg: ./...
68+
skip-integration-tests: 1
69+
typ: integration gateway
70+
- pkg: ./client
71+
worker: containerd
72+
tags: nydus
73+
typ: integration
74+
- pkg: ./client
75+
worker: oci
76+
tags: nydus
77+
typ: integration
78+
- pkg: ./...
79+
tags: nydus
80+
skip-integration-tests: 1
81+
typ: integration
17882
17983
cross:
18084
runs-on: ubuntu-20.04

0 commit comments

Comments
 (0)