Skip to content

Commit 6997452

Browse files
authored
Merge pull request moby#49817 from AkihiroSuda/fix-49816
CI: deduplicate execution of unit tests
2 parents 972c391 + fd5e772 commit 6997452

File tree

3 files changed

+130
-132
lines changed

3 files changed

+130
-132
lines changed

.github/workflows/.test-unit.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# reusable workflow
2+
name: .test-unit
3+
4+
# TODO: hide reusable workflow from the UI. Tracked in https://github.com/community/community/discussions/12025
5+
6+
# Default to 'contents: read', which grants actions to read commits.
7+
#
8+
# If any permission is set, any permission not included in the list is
9+
# implicitly set to "none".
10+
#
11+
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
12+
permissions:
13+
contents: read
14+
15+
on:
16+
workflow_call:
17+
18+
env:
19+
GO_VERSION: "1.23.8"
20+
GOTESTLIST_VERSION: v0.3.1
21+
TESTSTAT_VERSION: v0.1.25
22+
SETUP_BUILDX_VERSION: edge
23+
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
24+
25+
jobs:
26+
unit:
27+
runs-on: ubuntu-24.04
28+
timeout-minutes: 120 # guardrails timeout for the whole job
29+
continue-on-error: ${{ github.event_name != 'pull_request' }}
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
mode:
34+
- ""
35+
- firewalld
36+
steps:
37+
-
38+
name: Checkout
39+
uses: actions/checkout@v4
40+
-
41+
name: Set up runner
42+
uses: ./.github/actions/setup-runner
43+
-
44+
name: Prepare
45+
run: |
46+
CACHE_DEV_SCOPE=dev
47+
if [[ "${{ matrix.mode }}" == *"firewalld"* ]]; then
48+
echo "FIREWALLD=true" >> $GITHUB_ENV
49+
CACHE_DEV_SCOPE="${CACHE_DEV_SCOPE}firewalld"
50+
fi
51+
echo "CACHE_DEV_SCOPE=${CACHE_DEV_SCOPE}" >> $GITHUB_ENV
52+
-
53+
name: Set up Docker Buildx
54+
uses: docker/setup-buildx-action@v3
55+
with:
56+
version: ${{ env.SETUP_BUILDX_VERSION }}
57+
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
58+
buildkitd-flags: --debug
59+
-
60+
name: Build dev image
61+
uses: docker/bake-action@v6
62+
with:
63+
targets: dev
64+
set: |
65+
dev.cache-from=type=gha,scope=${{ env.CACHE_DEV_SCOPE }}
66+
-
67+
name: Test
68+
run: |
69+
make -o build test-unit
70+
-
71+
name: Prepare reports
72+
if: always()
73+
run: |
74+
mkdir -p bundles /tmp/reports
75+
find bundles -type f \( -name '*-report.json' -o -name '*.log' -o -name '*.out' -o -name '*.prof' -o -name '*-report.xml' \) -print | xargs sudo tar -czf /tmp/reports.tar.gz
76+
tar -xzf /tmp/reports.tar.gz -C /tmp/reports
77+
sudo chown -R $(id -u):$(id -g) /tmp/reports
78+
tree -nh /tmp/reports
79+
-
80+
name: Send to Codecov
81+
uses: codecov/codecov-action@v4
82+
with:
83+
directory: ./bundles
84+
env_vars: RUNNER_OS
85+
flags: unit
86+
token: ${{ secrets.CODECOV_TOKEN }} # used to upload coverage reports: https://github.com/moby/buildkit/pull/4660#issue-2142122533
87+
-
88+
name: Upload reports
89+
if: always()
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: test-reports-unit--${{ matrix.mode }}
93+
path: /tmp/reports/*
94+
retention-days: 1
95+
96+
unit-report:
97+
runs-on: ubuntu-24.04
98+
timeout-minutes: 10
99+
continue-on-error: ${{ github.event_name != 'pull_request' }}
100+
if: always()
101+
needs:
102+
- unit
103+
steps:
104+
-
105+
name: Set up Go
106+
uses: actions/setup-go@v5
107+
with:
108+
go-version: ${{ env.GO_VERSION }}
109+
cache-dependency-path: vendor.sum
110+
-
111+
name: Download reports
112+
uses: actions/download-artifact@v4
113+
with:
114+
pattern: test-reports-unit-*
115+
path: /tmp/reports
116+
-
117+
name: Install teststat
118+
run: |
119+
go install github.com/vearutop/teststat@${{ env.TESTSTAT_VERSION }}
120+
-
121+
name: Create summary
122+
run: |
123+
find /tmp/reports -type f -name '*-go-test-report.json' -exec teststat -markdown {} \+ >> $GITHUB_STEP_SUMMARY

.github/workflows/.test.yml

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -32,138 +32,6 @@ env:
3232
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
3333

3434
jobs:
35-
unit-prepare:
36-
runs-on: ubuntu-24.04
37-
timeout-minutes: 10 # guardrails timeout for the whole job
38-
continue-on-error: ${{ github.event_name != 'pull_request' }}
39-
outputs:
40-
includes: ${{ steps.set.outputs.includes }}
41-
steps:
42-
-
43-
name: Create matrix includes
44-
id: set
45-
uses: actions/github-script@v7
46-
with:
47-
script: |
48-
let includes = [
49-
{ mode: '' },
50-
{ mode: 'systemd' },
51-
];
52-
if ("${{ inputs.storage }}" == "snapshotter") {
53-
includes.push({ mode: 'firewalld' });
54-
}
55-
await core.group(`Set matrix`, async () => {
56-
core.info(`matrix: ${JSON.stringify(includes)}`);
57-
core.setOutput('includes', JSON.stringify(includes));
58-
});
59-
-
60-
name: Show matrix
61-
run: |
62-
echo ${{ steps.set.outputs.includes }}
63-
64-
unit:
65-
runs-on: ubuntu-24.04
66-
timeout-minutes: 120 # guardrails timeout for the whole job
67-
continue-on-error: ${{ github.event_name != 'pull_request' }}
68-
needs:
69-
- unit-prepare
70-
strategy:
71-
fail-fast: false
72-
matrix:
73-
include: ${{ fromJson(needs.unit-prepare.outputs.includes) }}
74-
steps:
75-
-
76-
name: Checkout
77-
uses: actions/checkout@v4
78-
-
79-
name: Set up runner
80-
uses: ./.github/actions/setup-runner
81-
-
82-
name: Prepare
83-
run: |
84-
CACHE_DEV_SCOPE=dev
85-
if [[ "${{ matrix.mode }}" == *"firewalld"* ]]; then
86-
echo "FIREWALLD=true" >> $GITHUB_ENV
87-
CACHE_DEV_SCOPE="${CACHE_DEV_SCOPE}firewalld"
88-
fi
89-
if [[ "${{ matrix.mode }}" == *"systemd"* ]]; then
90-
echo "SYSTEMD=true" >> $GITHUB_ENV
91-
CACHE_DEV_SCOPE="${CACHE_DEV_SCOPE}systemd"
92-
fi
93-
echo "CACHE_DEV_SCOPE=${CACHE_DEV_SCOPE}" >> $GITHUB_ENV
94-
-
95-
name: Set up Docker Buildx
96-
uses: docker/setup-buildx-action@v3
97-
with:
98-
version: ${{ env.SETUP_BUILDX_VERSION }}
99-
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
100-
buildkitd-flags: --debug
101-
-
102-
name: Build dev image
103-
uses: docker/bake-action@v6
104-
with:
105-
targets: dev
106-
set: |
107-
dev.cache-from=type=gha,scope=dev
108-
-
109-
name: Test
110-
run: |
111-
make -o build test-unit
112-
-
113-
name: Prepare reports
114-
if: always()
115-
run: |
116-
mkdir -p bundles /tmp/reports
117-
find bundles -path '*/root/*overlay2' -prune -o -type f \( -name '*-report.json' -o -name '*.log' -o -name '*.out' -o -name '*.prof' -o -name '*-report.xml' \) -print | xargs sudo tar -czf /tmp/reports.tar.gz
118-
tar -xzf /tmp/reports.tar.gz -C /tmp/reports
119-
sudo chown -R $(id -u):$(id -g) /tmp/reports
120-
tree -nh /tmp/reports
121-
-
122-
name: Send to Codecov
123-
uses: codecov/codecov-action@v4
124-
with:
125-
directory: ./bundles
126-
env_vars: RUNNER_OS
127-
flags: unit
128-
token: ${{ secrets.CODECOV_TOKEN }} # used to upload coverage reports: https://github.com/moby/buildkit/pull/4660#issue-2142122533
129-
-
130-
name: Upload reports
131-
if: always()
132-
uses: actions/upload-artifact@v4
133-
with:
134-
name: test-reports-unit-${{ inputs.storage }}-${{ matrix.mode }}
135-
path: /tmp/reports/*
136-
retention-days: 1
137-
138-
unit-report:
139-
runs-on: ubuntu-24.04
140-
timeout-minutes: 10
141-
continue-on-error: ${{ github.event_name != 'pull_request' }}
142-
if: always()
143-
needs:
144-
- unit
145-
steps:
146-
-
147-
name: Set up Go
148-
uses: actions/setup-go@v5
149-
with:
150-
go-version: ${{ env.GO_VERSION }}
151-
cache-dependency-path: vendor.sum
152-
-
153-
name: Download reports
154-
uses: actions/download-artifact@v4
155-
with:
156-
pattern: test-reports-unit-${{ inputs.storage }}-*
157-
path: /tmp/reports
158-
-
159-
name: Install teststat
160-
run: |
161-
go install github.com/vearutop/teststat@${{ env.TESTSTAT_VERSION }}
162-
-
163-
name: Create summary
164-
run: |
165-
find /tmp/reports -type f -name '*-go-test-report.json' -exec teststat -markdown {} \+ >> $GITHUB_STEP_SUMMARY
166-
16735
docker-py:
16836
runs-on: ubuntu-24.04
16937
timeout-minutes: 120 # guardrails timeout for the whole job

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ jobs:
8383
with:
8484
storage: ${{ matrix.storage }}
8585

86+
test-unit:
87+
needs:
88+
- build-dev
89+
- validate-dco
90+
uses: ./.github/workflows/.test-unit.yml
91+
secrets: inherit
92+
8693
validate-prepare:
8794
runs-on: ubuntu-24.04
8895
timeout-minutes: 10 # guardrails timeout for the whole job

0 commit comments

Comments
 (0)