Skip to content

Commit

Permalink
gha: test older Go versions in CI
Browse files Browse the repository at this point in the history
In particular, we want to test our minimum (Go 1.18), as well as the
versions where have explicit compatibility handling (Go 1.20 and 1.21)
in order to make sure that builds with any mix of compatibility shims
work correctly.

One slight wrinkle is that -test.gocoverdir was only added in Go 1.20,
so for older Go versions we need to just skip generating coverage (in
theory you can collate coverage runs from older Go versions but the
format is different to the post-1.20 format and so would be too
complicated to deal with).

Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Dec 16, 2024
1 parent e11873c commit 31bfec2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
fail-fast: false
matrix:
go-version:
- "1.18"
- "1.20"
- "1.21"
- "1.22"
- "^1"
Expand All @@ -26,6 +28,8 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: mkdir gocoverdir
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
run: |
# mktemp --tmpdir -d gocoverdir.XXXXXXXX
function New-TemporaryDirectory {
Expand All @@ -42,8 +46,15 @@ jobs:
$GOCOVERDIR = (New-TemporaryDirectory -Prefix "gocoverdir")
echo "GOCOVERDIR=$GOCOVERDIR" >>"$env:GITHUB_ENV"
- name: unit tests
run: go test -v -cover '-test.gocoverdir' "$env:GOCOVERDIR" ./...
run: |
if (Test-Path 'env:GOCOVERDIR') {
go test -v -cover '-test.gocoverdir' "$env:GOCOVERDIR" ./...
} else {
go test -v ./...
}
- name: upload coverage
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
uses: actions/upload-artifact@v4
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
Expand All @@ -57,6 +68,8 @@ jobs:
- ubuntu-latest
- macos-latest
go-version:
- "1.18"
- "1.20"
- "1.21"
- "1.22"
- "^1"
Expand All @@ -67,14 +80,18 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: mkdir gocoverdir
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
run: |
GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
- name: go test
run: go test -v -cover -timeout=30m -test.gocoverdir="$GOCOVERDIR" ./...
run: go test -v -timeout=30m ${GOCOVERDIR:+-cover -test.gocoverdir="$GOCOVERDIR"} ./...
- name: sudo go test
run: sudo go test -v -cover -timeout=30m -test.gocoverdir="$GOCOVERDIR" ./...
run: sudo go test -v -timeout=30m ${GOCOVERDIR:+-cover -test.gocoverdir="$GOCOVERDIR"} ./...
- name: upload coverage
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
uses: actions/upload-artifact@v4
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
Expand Down

0 comments on commit 31bfec2

Please sign in to comment.