ci(.github/workflows): UDENG-5763-Add GitHub Actions workflows for code checks, QA, and git checks #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: QA & sanity checks | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "*" | |
pull_request: | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
GO_TESTS_TIMEOUT: 20m | |
jobs: | |
go-sanity: | |
name: "Go: Code sanity" | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-24.04, windows-2022, macos-13, macos-14] # Run on Ubuntu, Windows, Mac Intel, Mac ARM | |
steps: | |
- name: Install dependencies | |
run: | | |
sudo apt update | |
sudo apt install -y ${{ env.apt_deps }} | |
- uses: actions/checkout@v4 | |
- name: Go code sanity check | |
uses: canonical/desktop-engineering/gh-actions/go/code-sanity@main | |
with: | |
golangci-lint-configfile: ".golangci.yaml" | |
tools-directory: "tools" | |
go-tests: | |
name: "Go: Tests" | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
test: ["coverage", "race"] | |
os: [ubuntu-24.04, windows-2022, macos-13, macos-14] # Run on Ubuntu, Windows, Mac Intel, Mac ARM | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
- name: Install gotestfmt and our wrapper script | |
uses: canonical/desktop-engineering/gh-actions/go/gotestfmt@main | |
- name: Prepare tests artifacts path | |
run: | | |
set -eu | |
artifacts_dir=$(mktemp -d --tmpdir insights-test-artifacts-XXXXXX) | |
echo INSIGHTS_TEST_ARTIFACTS_PATH="${artifacts_dir}" >> $GITHUB_ENV | |
- name: Run tests (with coverage collection) | |
if: matrix.test == 'coverage' | |
env: | |
G_DEBUG: "fatal-criticals" | |
run: | | |
set -euo pipefail | |
# The coverage is not written if the output directory does not exist, so we need to create it. | |
cov_dir="$(pwd)/coverage" | |
cod_cov_dir="$(pwd)/coverage/codecov" | |
raw_cov_dir="${cov_dir}/raw" | |
mkdir -p "${raw_cov_dir}" "${cod_cov_dir}" | |
# Print executed commands to ease debugging | |
set -x | |
# Overriding the default coverage directory is not an exported flag of go test (yet), so | |
# we need to override it using the test.gocoverdir flag instead. | |
#TODO: Update when https://go-review.googlesource.com/c/go/+/456595 is merged. | |
go test -json -timeout ${GO_TESTS_TIMEOUT} -cover -covermode=set ./... -coverpkg=./... -shuffle=on -args -test.gocoverdir="${raw_cov_dir}" | \ | |
gotestfmt --logfile "${INSIGHTS_TEST_ARTIFACTS_PATH}/gotestfmt.cover.log" | |
# Convert the raw coverage data into textfmt | |
go tool covdata textfmt -i="${raw_cov_dir}" -o="${cov_dir}/coverage.out" | |
# Filter out the testutils package and the pb.go file | |
grep -v -e "testutils" -e "pb.go" "${cov_dir}/coverage.out" >"${cod_cov_dir}/coverage.out.filtered" | |
# Move gcov output to coverage dir | |
mv "${raw_cov_dir}"/*.gcov "${cod_cov_dir}" | |
- name: Run tests (with race detector) | |
if: matrix.test == 'race' | |
env: | |
GO_TESTS_TIMEOUT: 35m | |
run: | | |
go test -json -timeout ${GO_TESTS_TIMEOUT} -race ./... | \ | |
gotestfmt --logfile "${INSIGHTS_TEST_ARTIFACTS_PATH}/gotestfmt.race.log" | |
- name: Upload coverage to Codecov | |
if: matrix.test == 'coverage' | |
uses: codecov/codecov-action@v5 | |
with: | |
directory: ./coverage/codecov | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Upload test artifacts | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: insights-${{ github.job }}-${{ matrix.test }}-artifacts-${{ github.run_attempt }} | |
path: ${{ env.INSIGHTS_TEST_ARTIFACTS_PATH }} |