Skip to content

Commit

Permalink
[CI] Add steps in pipeline to run unit tests with MacOS ARM (#1207)
Browse files Browse the repository at this point in the history
Add new steps in the CI pipeline to run unit tests in MacOS ARM.
Updated environment variables used for defining the agent images
used in the Buildkite steps to use consitent namings.
  • Loading branch information
mrodm authored Aug 21, 2024
1 parent e4fad86 commit f55de74
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 30 deletions.
67 changes: 45 additions & 22 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json

env:
SETUP_MAGE_VERSION: '1.14.0'
SETUP_GVM_VERSION: 'v0.5.2' # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
SETUP_MAGE_VERSION: '1.15.0'
DOCKER_REGISTRY: 'docker.elastic.co'
DOCKER_IMG: "${DOCKER_REGISTRY}/package-registry/package-registry"
DOCKER_IMG_PR: "${DOCKER_REGISTRY}/observability-ci/package-registry"
# Agent images used in pipeline steps
LINUX_GOLANG_AGENT_IMAGE: "golang:${SETUP_GOLANG_VERSION}"
WINDOWS_AGENT_IMAGE: "family/core-windows-2022"
MACOS_ARM_AGENT_IMAGE: "generic-13-ventura-arm"

steps:
- label: ":golangci-lint: Checks formatting / linting"
key: lint
command:
- ".buildkite/scripts/lint.sh"
agents:
image: "golang:${SETUP_GOLANG_VERSION}"
image: "${LINUX_GOLANG_AGENT_IMAGE}"
cpu: "8"
memory: "4G"

Expand All @@ -21,44 +26,60 @@ steps:
command:
- ".buildkite/scripts/build.sh"
agents:
image: "golang:${SETUP_GOLANG_VERSION}"
image: "${LINUX_GOLANG_AGENT_IMAGE}"
cpu: "8"
memory: "4G"

- label: ":linux: Test on Linux"
key: test-linux
command:
- ".buildkite/scripts/run-tests.sh"
agents:
image: "golang:${SETUP_GOLANG_VERSION}"
cpu: "8"
memory: "4G"
artifact_paths:
- "tests-report-linux.xml"
- group: ":go: Run Unit tests"
key: unit-tests
steps:
- label: ":linux: Test on Linux"
key: test-linux
command:
- ".buildkite/scripts/run-tests.sh"
agents:
image: "${LINUX_GOLANG_AGENT_IMAGE}"
cpu: "8"
memory: "4G"
artifact_paths:
- "tests-report-linux.xml"

- label: ":windows: Test on Windows"
key: test-win
command:
- ".buildkite/scripts/run-tests.ps1"
agents:
provider: "gcp"
image: "family/core-windows-2022"
artifact_paths:
- "tests-report-win.xml"
- label: ":windows: Test on Windows"
key: test-win
command:
- ".buildkite/scripts/run-tests.ps1"
agents:
provider: "gcp"
image: "${WINDOWS_AGENT_IMAGE}"
artifact_paths:
- "tests-report-win.xml"

- label: ":macos: Test on Macos ARM"
key: test-macos-arm
command:
- ".buildkite/scripts/run-tests.sh"
agents:
provider: "orka"
imagePrefix: "${MACOS_ARM_AGENT_IMAGE}"
artifact_paths:
- "tests-report-darwin.xml"

- label: ":junit: Junit annotate"
plugins:
- junit-annotate#v2.5.0:
artifacts: "tests-report-*.xml"
fail-build-on-error: true
report-skipped: true
always-annotate: true
agents:
provider: "gcp" #junit plugin requires docker
depends_on:
- step: "test-linux"
allow_failure: true
- step: "test-win"
allow_failure: true
- step: "test-macos-arm"
allow_failure: true

- label: "Publish docker image"
key: "publish"
Expand All @@ -70,6 +91,8 @@ steps:
allow_failure: false
- step: "test-win"
allow_failure: false
- step: "test-macos-arm"
allow_failure: false
- step: "build"
allow_failure: false
- step: "lint"
Expand Down
50 changes: 46 additions & 4 deletions .buildkite/scripts/pre-install-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ source .buildkite/scripts/tooling.sh

set -euo pipefail

platform_type="$(uname)"
hw_type="$(uname -m)"
platform_type_lowercase="$(echo "${platform_type}" | tr '[:upper:]' '[:lower:]')"

check_platform_architecture() {
case "${hw_type}" in
"x86_64")
arch_type="amd64"
;;
"aarch64")
arch_type="arm64"
;;
"arm64")
arch_type="arm64"
;;
*)
echo "The current platform/OS type is unsupported yet"
;;
esac
}

create_bin_folder() {
mkdir -p "${WORKSPACE}/bin"
}
Expand All @@ -12,16 +33,37 @@ add_bin_path(){
export PATH="${WORKSPACE}/bin:${PATH}"
}

with_mage() {
with_go() {
create_bin_folder
retry 5 curl -sL -o "${WORKSPACE}/bin/mage.tar.gz" "https://github.com/magefile/mage/releases/download/v${SETUP_MAGE_VERSION}/mage_${SETUP_MAGE_VERSION}_Linux-64bit.tar.gz"
check_platform_architecture

echo "--- Install Golang"
echo "GVM ${SETUP_GVM_VERSION} (platform ${platform_type_lowercase} arch ${arch_type}"
retry 5 curl -sL -o "${WORKSPACE}/bin/gvm" "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-${platform_type_lowercase}-${arch_type}"

chmod +x "${WORKSPACE}/bin/gvm"
eval "$(gvm "$(cat .go-version)")"
go version
which go
PATH="${PATH}:$(go env GOPATH)/bin"
export PATH
}

with_mage() {
check_platform_architecture

if [[ "${platform_type_lowercase}" == "darwin" ]]; then
# MacOS ARM VM images do not have golang installed by default
with_go
fi

tar -xvf "${WORKSPACE}/bin/mage.tar.gz" -C "${WORKSPACE}/bin"
chmod +x "${WORKSPACE}/bin/mage"
echo "--- Install mage"
go install "github.com/magefile/mage@v${SETUP_MAGE_VERSION}"
mage --version
}

with_go_junit_report() {
echo "--- Install go-junit-report"
go install github.com/jstemmer/go-junit-report/v2@latest
}

Expand Down
12 changes: 8 additions & 4 deletions .buildkite/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ add_bin_path
with_mage
with_go_junit_report

platform_type="$(uname | tr '[:upper:]' '[:lower:]')"
tests_report_txt_file="tests-report-${platform_type}.txt"
tests_report_xml_file="tests-report-${platform_type}.xml"
echo "--- Run Unit tests"
set +e
mage -debug test > tests-report-linux.txt
mage -debug test > "${tests_report_txt_file}"
exit_code=$?
set -e

# Buildkite collapse logs under --- symbols
# need to change --- to anything else or switch off collapsing (note: not available at the moment of this commit)
awk '{gsub("---", "----"); print }' tests-report-linux.txt
awk '{gsub("---", "----"); print }' "${tests_report_txt_file}"

# Create Junit report for junit annotation plugin
go-junit-report > tests-report-linux.xml < tests-report-linux.txt
echo "Create Junit report for junit annotation plugin ${tests_report_xml_file}"
go-junit-report > "${tests_report_xml_file}" < "${tests_report_txt_file}"
exit $exit_code

0 comments on commit f55de74

Please sign in to comment.