From 87a23ca3a57ca79c73f228a407539acaed9e5ba3 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Dec 2024 18:12:56 +0100 Subject: [PATCH] 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 --- .github/workflows/go.yml | 103 ++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7f270e62c472..c43ab8fe57f6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -116,90 +116,83 @@ jobs: name: spdx.json path: sbom/spdx.json - - unittests-k0s-linux-amd64: - name: "Unit tests :: linux-amd64" - runs-on: ubuntu-22.04 - - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Cache GOCACHE - uses: actions/cache@v4 - with: - key: unittests-k0s-linux-amd64-gocache-${{ github.ref_name }}-${{ github.sha }} - restore-keys: | - unittests-k0s-linux-amd64-gocache-${{ github.ref_name }}- - build-k0s-linux-amd64-gocache-${{ github.ref_name }}- - path: | - build/cache/go/build - - - name: Cache GOMODCACHE - uses: actions/cache@v4 - with: - key: unittests-k0s-linux-amd64-gomodcache-${{ hashFiles('go.sum') }} - restore-keys: | - build-k0s-linux-amd64-gomodcache-${{ hashFiles('go.sum') }} - path: | - build/cache/go/mod - - - name: Run unit tests - env: - EMBEDDED_BINS_BUILDMODE: none - run: make check-unit - - unittests-k0s-windows-amd64: - name: "Unit tests :: windows-amd64" - runs-on: windows-2022 + unittests-k0s: + strategy: + fail-fast: false + matrix: + include: + - name: linux-amd64 + runs-on: ubuntu-22.04 + - name: windows-amd64 + runs-on: windows-2022 + target-os: windows + - name: macos-arm64 + runs-on: macos-15 + target-os: darwin + + name: "Unit tests :: k0s :: ${{ matrix.name }}" + runs-on: "${{ matrix.runs-on }}" defaults: run: shell: bash + env: + EMBEDDED_BINS_BUILDMODE: none + steps: - - name: Check out + - name: Check out code into the Go module directory uses: actions/checkout@v4 with: persist-credentials: false + - name: Prepare unit tests + if: matrix.target-os != '' + run: | + cat <>"$GITHUB_ENV" + TARGET_OS=${{ matrix.target-os }} + GO=go + GO_ENV= + GOCACHE=$GITHUB_WORKSPACE/build/cache/go/build + GOMODCACHE=$GITHUB_WORKSPACE/build/cache/go/mod + UNITTEST_EXTRA_ARGS=BUILD_GO_LDFLAGS_EXTRA= + EOF + + echo ::group::Build Environment + cat -- "$GITHUB_ENV" + echo ::endgroup:: + + mkdir -p build/cache + make --touch .k0sbuild.docker-image.k0s + - name: Prepare build environment run: .github/workflows/prepare-build-env.sh - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 + if: matrix.target-os != '' with: go-version: ${{ env.GO_VERSION }} + cache: false - name: Cache GOCACHE uses: actions/cache@v4 with: - key: unittests-k0s-windows-amd64-gocache-${{ github.ref_name }}-${{ github.sha }} + key: unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}-${{ github.sha }} restore-keys: | - unittests-k0s-windows-amd64-gocache-${{ github.ref_name }}- + unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}- path: | - ~\AppData\Local\go-build + build/cache/go/build - name: Cache GOMODCACHE uses: actions/cache@v4 with: - key: unittests-k0s-windows-amd64-gomodcache-${{ hashFiles('go.sum') }} - restore-keys: | - build-k0s-windows-amd64-gomodcache-${{ hashFiles('go.sum') }} + key: unittests-k0s-gomodcache-${{ hashFiles('go.sum') }} path: | - ~\go\pkg\mod + build/cache/go/mod - name: Run unit tests - env: - EMBEDDED_BINS_BUILDMODE: none - TARGET_OS: windows - GO: go - GO_ENV: '' - run: | - make --touch .k0sbuild.docker-image.k0s - make check-unit + run: make check-unit $UNITTEST_EXTRA_ARGS smoketests: strategy: