spruce up 'test' job in GitHub Action #116
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: build | |
on: [push] | |
jobs: | |
test: | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
go-version: [1.23] | |
name: Tests ${{ matrix.os }} @ Go ${{ matrix.go-version }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Check out Source | |
uses: actions/checkout@v4 | |
- name: Set up Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go-version }} | |
cache: true | |
- name: Display Go version | |
run: go version | |
- name: Test | |
run: go test -v -coverprofile=cover.out ./... | |
- name: Upload coverage reports to Codecov | |
uses: codecov/[email protected] | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
slug: jub0bs/cors | |
benchmark: | |
# Mostly to compare allocations; | |
# measurements of execution speed in GitHub Actions are unreliable. | |
needs: test | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
go-version: [1.23] | |
name: Benchmark comparison ${{ matrix.os }} @ Go ${{ matrix.go-version }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Check out Code (new) | |
uses: actions/checkout@v4 | |
with: | |
path: new | |
fetch-depth: '0' # fetch all history for all branches and tags | |
- name: Retrieve latest tag | |
id: latest-tag | |
run: | | |
cd new | |
echo "LATEST_TAG=$(git for-each-ref --sort=-version:refname --format='%(refname:lstrip=2)' --count=1 refs/tags)" >> "$GITHUB_OUTPUT" | |
- name: Check out Code (old) | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.latest-tag.outputs.LATEST_TAG }} | |
path: old | |
- name: Set up Go ${{ matrix.go-version }} | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Install benchstat | |
run: go install golang.org/x/perf/cmd/benchstat@latest | |
- name: Run Benchmark (old) | |
run: | | |
cd old | |
go test -run=^$ -bench=. -count=10 . -benchtime 10000x > bench_results.txt | |
- name: Run Benchmark (new) | |
run: | | |
cd new | |
go test -run=^$ -bench=. -count=10 . -benchtime 10000x > bench_results.txt | |
- name: Run benchstat for middleware initialization | |
run: | | |
benchstat -filter "/type:init" old/bench_results.txt new/bench_results.txt | |
- name: Run benchstat for middleware Config method | |
run: | | |
benchstat -filter "/type:config" old/bench_results.txt new/bench_results.txt | |
- name: Run benchstat for middleware execution | |
run: | | |
benchstat -filter "/type:exec" old/bench_results.txt new/bench_results.txt |