Skip to content

Merge branch 'main' into marc/ci-go-cache #7354

Merge branch 'main' into marc/ci-go-cache

Merge branch 'main' into marc/ci-go-cache #7354

Workflow file for this run

name: Go CI
on:
workflow_dispatch:
push:
jobs:
go-test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Go version from mise
id: mise
run: echo "go-version=$(grep 'golang' mise.toml | cut -d'"' -f2)" >> $GITHUB_OUTPUT
shell: bash
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: ${{ steps.mise.outputs.go-version }}
# setup-go's built-in cache keys on go.sum alone, has no fallback
# when go.sum changes, and shares one key across every job on the
# same OS, so the first job to finish (even one that compiled
# nothing) decides what everyone else restores. See the explicit
# cache step below instead.
cache: false
- name: Find Go cache directories
id: go-cache
shell: bash
run: |
echo "build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
echo "modules=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
- name: Cache Go modules and build output
uses: actions/cache@v6
with:
path: |
${{ steps.go-cache.outputs.modules }}
${{ steps.go-cache.outputs.build }}
key: ${{ github.job }}-${{ runner.os }}-${{ runner.arch }}-go${{ steps.mise.outputs.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ github.job }}-${{ runner.os }}-${{ runner.arch }}-go${{ steps.mise.outputs.go-version }}-
# bash on every OS: the default pwsh on Windows does not fail the step
# when a command in a multi-line script exits non-zero.
- run: go test -race -v ./...
shell: bash
# This job provides a stable name for branch protection rules
# It will only pass if all Go CI matrix tests above pass
go-test-complete:
runs-on: ubuntu-latest
needs: go-test
if: always()
steps:
- name: Check Go CI results
run: |
if [[ "${{ needs.go-test.result }}" != "success" ]]; then
echo "One or more Go CI tests failed"
exit 1
fi
echo "All Go CI tests passed"