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

multi-arch unit tests #279

Merged
merged 19 commits into from
Jan 25, 2024
Merged
51 changes: 25 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
jobs:

validate-pr:
name: Validate PR
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
Expand All @@ -28,60 +27,64 @@ jobs:
run: make verify-manifests

unit-tests:
name: Unit Tests
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Display build environment
run: printenv

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Install kubebuilder
run : |
os=$(go env GOOS)
arch=$(go env GOARCH)
curl -L "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_${os}_${arch}.tar.gz" | tar -xz -C /tmp/
sudo mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder
export PATH=$PATH:/usr/local/kubebuilder/bin

- name: Run tests
run: |
make generate manifests
go test ./... -v -coverprofile cover.out -covermode=atomic

run: make test
- name: Upload test coverage file
uses: actions/upload-artifact@v4
with:
name: coverage
path: cover.out

unit-tests-qemu:
strategy:
matrix:
# arch: [arm64, s390x, ppc64le] # kubebuilder is not available for s390x yet
arch: [arm64, ppc64le]
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install QEMU
uses: docker/setup-qemu-action@v3
- name: Run tests via qemu/binfmt
run: |
go env
make test-qemu
env:
GOARCH: ${{ matrix.arch }}

coverage:
name: Coverage
needs: unit-tests
runs-on: ubuntu-22.04
steps:

- name: Checkout
# this checkout is required for the coverage report. If we don't do this, then
# the uploaded report is invalid and codecov doesn't know how to process it.
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download coverage result from unit-tests
uses: actions/download-artifact@v4
with:
name: coverage

- name: Upload coverage
uses: codecov/codecov-action@v3
with:
Expand All @@ -91,23 +94,19 @@ jobs:
fail_ci_if_error: true

sonarcloud:
name: SonarCloud
needs: [validate-pr,unit-tests]
runs-on: ubuntu-20.04
steps:

- name: Checkout
# this checkout is required for the coverage report. If we don't do this, then
# the uploaded report is invalid and codecov doesn't know how to process it.
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download coverage result from unit-tests
uses: actions/download-artifact@v4
with:
name: coverage

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ commit
# Ignore the testing directory for developing
testing/*
tmp/*
collector/test_files/test_reports/*
internal/collector/test_files/test_reports/*

# Mac OSX
.DS_Store
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ ENVTEST_K8S_VERSION = 1.28.0
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: test-qemu
test-qemu: envtest-not-local ## Run tests - specific for multiarch in github action
KUBEBUILDER_ASSETS="$(shell $(ENVTEST_NOT_LOCAL) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./...

##@ Build

.PHONY: build
Expand Down Expand Up @@ -338,6 +342,7 @@ KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
ENVTEST_NOT_LOCAL ?= $(shell go env GOPATH)/bin/$(shell go env GOOS)_$(shell go env GOARCH)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v5.1.1
Expand Down Expand Up @@ -367,6 +372,10 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: envtest-not-local
envtest-not-local: ## Download envtest-setup for qemu unit tests - specific to github action.
test -s setup-envtest || go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
Expand Down
Loading