Skip to content

Commit

Permalink
run unit tests on arm64 and ppc64le (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
maskarb authored Jan 25, 2024
1 parent ca87c25 commit d4acdd1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
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

0 comments on commit d4acdd1

Please sign in to comment.