Skip to content

Commit 0c8192c

Browse files
ci: split tests into separate workflow to avoid running on irrelevant changes
Moved the `prepare_test_image_testdata`, `tests`, and `docker` jobs from `checks.yml` into a new `tests.yml` workflow file. Configured `paths-ignore` for the `tests.yml` workflow so that these long-running tests are skipped if changes only affect markdown files, documentation, scripts, or other unrelated GitHub Actions workflows. This prevents unnecessary test runs while still executing quick lint and formatting checks in `checks.yml`. Co-authored-by: another-rex <106129829+another-rex@users.noreply.github.com>
1 parent 89bf42d commit 0c8192c

2 files changed

Lines changed: 138 additions & 90 deletions

File tree

.github/workflows/checks.yml

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -97,93 +97,3 @@ jobs:
9797
check-latest: true
9898
- name: Run lint action
9999
uses: ./.github/workflows/lint-action
100-
prepare_test_image_testdata:
101-
permissions:
102-
contents: read # to fetch code (actions/checkout)
103-
runs-on: ubuntu-latest
104-
steps:
105-
- name: Check out code
106-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
107-
with:
108-
persist-credentials: false
109-
- run: scripts/build_test_images.sh
110-
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
111-
with:
112-
name: image-testdata-${{ github.run_number }}-${{ github.run_attempt }}
113-
path: cmd/osv-scanner/scan/image/testdata/*.tar
114-
retention-days: 1
115-
tests:
116-
permissions:
117-
contents: read # to fetch code (actions/checkout)
118-
needs:
119-
- prepare_test_image_testdata
120-
name: Run unit tests
121-
strategy:
122-
fail-fast: false
123-
matrix:
124-
os: [ubuntu-latest, macos-latest, windows-latest]
125-
runs-on: ${{ matrix.os }}
126-
steps:
127-
- name: Check out code
128-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
129-
with:
130-
persist-credentials: false
131-
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
132-
with:
133-
pattern: image-testdata-${{ github.run_number }}-*
134-
path: cmd/osv-scanner/scan/image/testdata/
135-
- name: Set up Go
136-
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
137-
with:
138-
go-version-file: "go.mod"
139-
check-latest: true
140-
- name: Run test action
141-
uses: ./.github/workflows/test-action
142-
with:
143-
codecov_token: ${{ secrets.CODECOV_TOKEN }}
144-
docker:
145-
permissions:
146-
contents: read # to fetch code (actions/checkout)
147-
runs-on: ubuntu-latest
148-
env:
149-
# Required for buildx on docker 19.x
150-
DOCKER_CLI_EXPERIMENTAL: "enabled"
151-
steps:
152-
- name: Checkout
153-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
154-
with:
155-
fetch-depth: 0
156-
- name: Set up Go
157-
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
158-
with:
159-
go-version-file: "go.mod"
160-
check-latest: true
161-
- uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
162-
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
163-
- name: Run GoReleaser
164-
id: run-goreleaser
165-
uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
166-
with:
167-
distribution: goreleaser
168-
version: "~> v2"
169-
args: release --clean --snapshot
170-
- env:
171-
ARTIFACTS: ${{ steps.run-goreleaser.outputs.artifacts }}
172-
run: |
173-
echo "$ARTIFACTS" > output.json
174-
jq -r '.[] | select(
175-
.type == "Docker Image" and
176-
.goarch == "amd64" and
177-
.goos == "linux" and
178-
.extra.DockerConfig.dockerfile == "goreleaser.dockerfile"
179-
) | .name' output.json | while read -r image; do
180-
echo "Testing image $image"
181-
182-
exit_code=0
183-
docker run -v ${PWD}:/src $image -L /src/go.mod || exit_code=$?
184-
185-
# fail if we get a non-zero exit code other than "vulnerabilities were found"
186-
if [[ $exit_code -ne 0 && $exit_code -ne 1 ]]; then
187-
exit $exit_code
188-
fi
189-
done

.github/workflows/tests.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Tests
16+
17+
on:
18+
push:
19+
branches: ["main", "v1", "mcp"]
20+
paths-ignore:
21+
- '**/*.md'
22+
- 'docs/**'
23+
- '.github/workflows/*'
24+
- '!.github/workflows/tests.yml'
25+
- '!.github/workflows/test-action/**'
26+
- 'scripts/**'
27+
pull_request:
28+
# The branches below must be a subset of the branches above
29+
branches: ["main", "v1", "mcp"]
30+
paths-ignore:
31+
- '**/*.md'
32+
- 'docs/**'
33+
- '.github/workflows/*'
34+
- '!.github/workflows/tests.yml'
35+
- '!.github/workflows/test-action/**'
36+
- 'scripts/**'
37+
workflow_dispatch:
38+
39+
concurrency:
40+
# Pushing new changes to a branch will cancel any in-progress CI runs
41+
group: ${{ github.workflow }}-${{ github.ref }}
42+
cancel-in-progress: true
43+
44+
# Restrict jobs in this workflow to have no permissions by default; permissions
45+
# should be granted per job as needed using a dedicated `permissions` block
46+
permissions: {}
47+
48+
jobs:
49+
prepare_test_image_testdata:
50+
permissions:
51+
contents: read # to fetch code (actions/checkout)
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Check out code
55+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
56+
with:
57+
persist-credentials: false
58+
- run: scripts/build_test_images.sh
59+
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
60+
with:
61+
name: image-testdata-${{ github.run_number }}-${{ github.run_attempt }}
62+
path: cmd/osv-scanner/scan/image/testdata/*.tar
63+
retention-days: 1
64+
tests:
65+
permissions:
66+
contents: read # to fetch code (actions/checkout)
67+
needs:
68+
- prepare_test_image_testdata
69+
name: Run unit tests
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
os: [ubuntu-latest, macos-latest, windows-latest]
74+
runs-on: ${{ matrix.os }}
75+
steps:
76+
- name: Check out code
77+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
78+
with:
79+
persist-credentials: false
80+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
81+
with:
82+
pattern: image-testdata-${{ github.run_number }}-*
83+
path: cmd/osv-scanner/scan/image/testdata/
84+
- name: Set up Go
85+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
86+
with:
87+
go-version-file: "go.mod"
88+
check-latest: true
89+
- name: Run test action
90+
uses: ./.github/workflows/test-action
91+
with:
92+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
93+
docker:
94+
permissions:
95+
contents: read # to fetch code (actions/checkout)
96+
runs-on: ubuntu-latest
97+
env:
98+
# Required for buildx on docker 19.x
99+
DOCKER_CLI_EXPERIMENTAL: "enabled"
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
103+
with:
104+
fetch-depth: 0
105+
- name: Set up Go
106+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
107+
with:
108+
go-version-file: "go.mod"
109+
check-latest: true
110+
- uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
111+
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
112+
- name: Run GoReleaser
113+
id: run-goreleaser
114+
uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7.0.0
115+
with:
116+
distribution: goreleaser
117+
version: "~> v2"
118+
args: release --clean --snapshot
119+
- env:
120+
ARTIFACTS: ${{ steps.run-goreleaser.outputs.artifacts }}
121+
run: |
122+
echo "$ARTIFACTS" > output.json
123+
jq -r '.[] | select(
124+
.type == "Docker Image" and
125+
.goarch == "amd64" and
126+
.goos == "linux" and
127+
.extra.DockerConfig.dockerfile == "goreleaser.dockerfile"
128+
) | .name' output.json | while read -r image; do
129+
echo "Testing image $image"
130+
131+
exit_code=0
132+
docker run -v ${PWD}:/src $image -L /src/go.mod || exit_code=$?
133+
134+
# fail if we get a non-zero exit code other than "vulnerabilities were found"
135+
if [[ $exit_code -ne 0 && $exit_code -ne 1 ]]; then
136+
exit $exit_code
137+
fi
138+
done

0 commit comments

Comments
 (0)