Skip to content

Commit 87a23ca

Browse files
committed
Run unit tests on macOS in CI
Combine the linux and windows unit test jobs into one matrix job and add a new matrix entry for macOS. Signed-off-by: Tom Wieczorek <[email protected]>
1 parent 07c4324 commit 87a23ca

File tree

1 file changed

+48
-55
lines changed

1 file changed

+48
-55
lines changed

.github/workflows/go.yml

+48-55
Original file line numberDiff line numberDiff line change
@@ -116,90 +116,83 @@ jobs:
116116
name: spdx.json
117117
path: sbom/spdx.json
118118

119-
120-
unittests-k0s-linux-amd64:
121-
name: "Unit tests :: linux-amd64"
122-
runs-on: ubuntu-22.04
123-
124-
steps:
125-
- name: Check out code into the Go module directory
126-
uses: actions/checkout@v4
127-
with:
128-
persist-credentials: false
129-
130-
- name: Cache GOCACHE
131-
uses: actions/cache@v4
132-
with:
133-
key: unittests-k0s-linux-amd64-gocache-${{ github.ref_name }}-${{ github.sha }}
134-
restore-keys: |
135-
unittests-k0s-linux-amd64-gocache-${{ github.ref_name }}-
136-
build-k0s-linux-amd64-gocache-${{ github.ref_name }}-
137-
path: |
138-
build/cache/go/build
139-
140-
- name: Cache GOMODCACHE
141-
uses: actions/cache@v4
142-
with:
143-
key: unittests-k0s-linux-amd64-gomodcache-${{ hashFiles('go.sum') }}
144-
restore-keys: |
145-
build-k0s-linux-amd64-gomodcache-${{ hashFiles('go.sum') }}
146-
path: |
147-
build/cache/go/mod
148-
149-
- name: Run unit tests
150-
env:
151-
EMBEDDED_BINS_BUILDMODE: none
152-
run: make check-unit
153-
154-
unittests-k0s-windows-amd64:
155-
name: "Unit tests :: windows-amd64"
156-
runs-on: windows-2022
119+
unittests-k0s:
120+
strategy:
121+
fail-fast: false
122+
matrix:
123+
include:
124+
- name: linux-amd64
125+
runs-on: ubuntu-22.04
126+
- name: windows-amd64
127+
runs-on: windows-2022
128+
target-os: windows
129+
- name: macos-arm64
130+
runs-on: macos-15
131+
target-os: darwin
132+
133+
name: "Unit tests :: k0s :: ${{ matrix.name }}"
134+
runs-on: "${{ matrix.runs-on }}"
157135

158136
defaults:
159137
run:
160138
shell: bash
161139

140+
env:
141+
EMBEDDED_BINS_BUILDMODE: none
142+
162143
steps:
163-
- name: Check out
144+
- name: Check out code into the Go module directory
164145
uses: actions/checkout@v4
165146
with:
166147
persist-credentials: false
167148

149+
- name: Prepare unit tests
150+
if: matrix.target-os != ''
151+
run: |
152+
cat <<EOF >>"$GITHUB_ENV"
153+
TARGET_OS=${{ matrix.target-os }}
154+
GO=go
155+
GO_ENV=
156+
GOCACHE=$GITHUB_WORKSPACE/build/cache/go/build
157+
GOMODCACHE=$GITHUB_WORKSPACE/build/cache/go/mod
158+
UNITTEST_EXTRA_ARGS=BUILD_GO_LDFLAGS_EXTRA=
159+
EOF
160+
161+
echo ::group::Build Environment
162+
cat -- "$GITHUB_ENV"
163+
echo ::endgroup::
164+
165+
mkdir -p build/cache
166+
make --touch .k0sbuild.docker-image.k0s
167+
168168
- name: Prepare build environment
169169
run: .github/workflows/prepare-build-env.sh
170170

171171
- name: Set up Go
172-
uses: actions/setup-go@v3
172+
uses: actions/setup-go@v5
173+
if: matrix.target-os != ''
173174
with:
174175
go-version: ${{ env.GO_VERSION }}
176+
cache: false
175177

176178
- name: Cache GOCACHE
177179
uses: actions/cache@v4
178180
with:
179-
key: unittests-k0s-windows-amd64-gocache-${{ github.ref_name }}-${{ github.sha }}
181+
key: unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}-${{ github.sha }}
180182
restore-keys: |
181-
unittests-k0s-windows-amd64-gocache-${{ github.ref_name }}-
183+
unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}-
182184
path: |
183-
~\AppData\Local\go-build
185+
build/cache/go/build
184186
185187
- name: Cache GOMODCACHE
186188
uses: actions/cache@v4
187189
with:
188-
key: unittests-k0s-windows-amd64-gomodcache-${{ hashFiles('go.sum') }}
189-
restore-keys: |
190-
build-k0s-windows-amd64-gomodcache-${{ hashFiles('go.sum') }}
190+
key: unittests-k0s-gomodcache-${{ hashFiles('go.sum') }}
191191
path: |
192-
~\go\pkg\mod
192+
build/cache/go/mod
193193
194194
- name: Run unit tests
195-
env:
196-
EMBEDDED_BINS_BUILDMODE: none
197-
TARGET_OS: windows
198-
GO: go
199-
GO_ENV: ''
200-
run: |
201-
make --touch .k0sbuild.docker-image.k0s
202-
make check-unit
195+
run: make check-unit $UNITTEST_EXTRA_ARGS
203196

204197
smoketests:
205198
strategy:

0 commit comments

Comments
 (0)