Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run unit tests on macOS in CI #5380

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 48 additions & 55 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF >>"$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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build unix

/*
Copyright 2024 k0s authors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !linux

/*
Copyright 2024 k0s authors

Expand All @@ -16,8 +18,12 @@ limitations under the License.

package cleanup

import "fmt"
import (
"errors"
"fmt"
"runtime"
)

func UnmountLazy(path string) error {
return fmt.Errorf("lazy unmount is not supported on Windows for path: %s", path)
func UnmountLazy(string) error {
return fmt.Errorf("%w on %s", errors.ErrUnsupported, runtime.GOOS)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows

/*
Copyright 2023 k0s authors

Expand Down
6 changes: 3 additions & 3 deletions pkg/constant/constant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ func TestRuncModuleVersions(t *testing.T) {
},
)

if runtime.GOOS == "windows" {
if runtime.GOOS == "linux" {
// The runc dependency is only a thing on Linux.
assert.Zero(t, numMatched, "Expected no packages to pass the filter on Windows.")
} else {
assert.NotZero(t, numMatched, "Not a single package passed the filter.")
} else {
assert.Zero(t, numMatched, "Expected no packages to pass the filter on Windows.")
}
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ func TestMultiThread(t *testing.T) {
}

func TestCleanupPIDFile_Gracefully(t *testing.T) {
if runtime.GOOS == "windows" {
switch runtime.GOOS {
case "windows":
t.Skip("PID file cleanup not yet implemented on Windows")
case "darwin":
t.Skip("FIXME: times out on macOS, needs debugging")
}

// Start some k0s-managed process.
Expand Down Expand Up @@ -279,8 +282,11 @@ func TestCleanupPIDFile_Gracefully(t *testing.T) {
}

func TestCleanupPIDFile_Forcefully(t *testing.T) {
if runtime.GOOS == "windows" {
switch runtime.GOOS {
case "windows":
t.Skip("PID file cleanup not yet implemented on Windows")
case "darwin":
t.Skip("FIXME: times out on macOS, needs debugging")
}

// Start some k0s-managed process that won't terminate gracefully.
Expand Down
Loading