Skip to content

Commit 687aac5

Browse files
committed
Refactor unit test workflow
Signed-off-by: apostasie <[email protected]>
1 parent f289b99 commit 687aac5

File tree

3 files changed

+103
-32
lines changed

3 files changed

+103
-32
lines changed

.github/workflows/job-test-unit.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Note: freebsd tests are not ran here (see integration instead)
2+
name: test-unit
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
timeout:
8+
required: true
9+
type: number
10+
go-version:
11+
required: true
12+
type: string
13+
runner:
14+
required: true
15+
type: string
16+
canary:
17+
required: false
18+
default: false
19+
type: boolean
20+
windows-cni-version:
21+
required: true
22+
type: string
23+
linux-cni-version:
24+
required: true
25+
type: string
26+
linux-cni-sha:
27+
required: true
28+
type: string
29+
30+
env:
31+
GOTOOLCHAIN: local
32+
# Windows fails without this
33+
CGO_ENABLED: 0
34+
35+
jobs:
36+
test-unit:
37+
name: ${{ format('{0}{1}', inputs.runner, inputs.canary && ' (go canary)' || '') }}
38+
timeout-minutes: ${{ inputs.timeout }}
39+
runs-on: "${{ inputs.runner }}"
40+
defaults:
41+
run:
42+
shell: bash
43+
44+
env:
45+
GO_VERSION: ${{ inputs.go-version }}
46+
47+
steps:
48+
- name: "Init: checkout"
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
with:
51+
fetch-depth: 1
52+
53+
# If canary is requested, check for the latest unstable release
54+
- if: ${{ inputs.canary }}
55+
name: "Init (canary): retrieve GO_VERSION"
56+
run: |
57+
latest_go="$(. ./hack/provisioning/version/fetch.sh; go::canary::for::go-setup)"
58+
printf "GO_VERSION=%s\n" "$latest_go" >> "$GITHUB_ENV"
59+
[ "$latest_go" != "" ] || \
60+
echo "::warning title=No canary go::There is currently no canary go version to test. Following steps will not run."
61+
62+
- if: ${{ env.GO_VERSION != '' }}
63+
name: "Init: install go"
64+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
65+
with:
66+
go-version: ${{ env.GO_VERSION }}
67+
check-latest: true
68+
69+
# Install CNI
70+
- if: ${{ env.GO_VERSION != '' }}
71+
name: "Init: set up CNI"
72+
run: |
73+
if [ "$RUNNER_OS" == "Windows" ]; then
74+
GOPATH=$(go env GOPATH) WINCNI_VERSION=${{ inputs.windows-cni-version }} ./hack/provisioning/windows/cni.sh
75+
elif [ "$RUNNER_OS" == "Linux" ]; then
76+
./hack/provisioning/linux/cni.sh "${{ inputs.linux-cni-version }}" "amd64" "${{ inputs.linux-cni-sha }}"
77+
fi
78+
79+
- if: ${{ env.GO_VERSION != '' }}
80+
name: "Run"
81+
run: |
82+
make test-unit

.github/workflows/test-canary.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ jobs:
4141
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
4242
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
4343
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
44-
- name: "Run unit tests"
45-
run: go test -v ./pkg/...
4644
- name: "Run integration tests"
4745
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=false
4846
- name: "Run integration tests (flaky)"

.github/workflows/test.yml renamed to .github/workflows/workflow-test.yml

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,31 @@ jobs:
5252
--target build-dependencies --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
5353
5454
test-unit:
55-
# FIXME:
56-
# Supposed to work: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#example-returning-a-json-data-type
57-
# Apparently does not
58-
# timeout-minutes: ${{ fromJSON(env.SHORT_TIMEOUT) }}
59-
timeout-minutes: 10
60-
name: unit | ${{ matrix.goos }}
61-
runs-on: "${{ matrix.os }}"
62-
defaults:
63-
run:
64-
shell: bash
55+
name: "unit${{ inputs.hack }}"
56+
uses: ./.github/workflows/job-test-unit.yml
6557
strategy:
6658
fail-fast: false
6759
matrix:
60+
# Run on all supported platforms but freebsd
61+
# Additionally run on canary for linux
6862
include:
69-
- os: windows-2022
70-
goos: windows
71-
- os: ubuntu-24.04
72-
goos: linux
73-
- os: macos-15
74-
goos: darwin
75-
steps:
76-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
77-
with:
78-
fetch-depth: 1
79-
- name: "Install go"
80-
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
81-
with:
82-
go-version: ${{ env.GO_VERSION }}
83-
check-latest: true
84-
- if: ${{ matrix.goos=='windows' }}
85-
name: "Set up CNI"
86-
run: GOPATH=$(go env GOPATH) ./hack/provisioning/windows/cni.sh
87-
- name: "Run unit tests"
88-
run: make test-unit
63+
- runner: "ubuntu-24.04"
64+
canary: false
65+
- runner: "macos-15"
66+
canary: false
67+
- runner: "windows-2025"
68+
canary: false
69+
- runner: "ubuntu-24.04"
70+
canary: true
71+
with:
72+
runner: ${{ matrix.runner }}
73+
canary: ${{ matrix.canary }}
74+
# Windows routinely go over 5 minutes
75+
timeout: 10
76+
go-version: 1.24
77+
windows-cni-version: v0.3.1
78+
linux-cni-version: v1.7.1
79+
linux-cni-sha: 1a28a0506bfe5bcdc981caf1a49eeab7e72da8321f1119b7be85f22621013098
8980

9081
test-integration:
9182
needs: build-dependencies

0 commit comments

Comments
 (0)