Skip to content

Commit 40cdc2d

Browse files
committed
ci: add GitHub Actions workflow for Go tests
Add a CI workflow modeled after tailscale/tailscale that runs on PRs, pushes to main, and merge groups. The test matrix covers amd64, amd64 with race detector, and 386. Also runs go vet and checks that build/test do not modify tracked files or create untracked files. A check_mergeability job gates on the full matrix for use as a required status check.
1 parent 3ad9bb1 commit 40cdc2d

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Main CI workflow. Runs build, vet, and tests on PRs and merged commits.
2+
name: CI
3+
4+
on:
5+
push:
6+
branches:
7+
- "main"
8+
pull_request:
9+
# all PRs on all branches
10+
merge_group:
11+
branches:
12+
- "main"
13+
14+
concurrency:
15+
# For PRs, later CI runs preempt previous ones. e.g. a force push on a PR
16+
# cancels running CI jobs and starts all new ones.
17+
#
18+
# For non-PR pushes, concurrency.group needs to be unique for every distinct
19+
# CI run we want to have happen. Use run_id, which in practice means all
20+
# non-PR CI runs will be allowed to run without preempting each other.
21+
group: ${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
test:
26+
strategy:
27+
fail-fast: false # don't abort the entire matrix if one element fails
28+
matrix:
29+
include:
30+
- goarch: amd64
31+
- goarch: amd64
32+
buildflags: "-race"
33+
- goarch: "386" # thanks yaml
34+
runs-on: ubuntu-24.04
35+
steps:
36+
- name: checkout
37+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
38+
39+
- name: setup Go
40+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
41+
with:
42+
go-version-file: go.mod
43+
44+
- name: build all
45+
if: matrix.buildflags == '' # skip on race builder
46+
run: go build ./...
47+
env:
48+
GOARCH: ${{ matrix.goarch }}
49+
50+
- name: vet
51+
if: matrix.buildflags == '' && matrix.goarch == 'amd64'
52+
run: go vet ./...
53+
54+
- name: test all
55+
run: go test ${{ matrix.buildflags }} ./...
56+
env:
57+
GOARCH: ${{ matrix.goarch }}
58+
59+
- name: check that no tracked files changed
60+
run: git diff --no-ext-diff --name-only --exit-code || (echo "Build/test modified the files above."; exit 1)
61+
62+
- name: check that no new files were added
63+
run: |
64+
# Note: The "error: pathspec..." you see below is normal!
65+
# In the success case in which there are no new untracked files,
66+
# git ls-files complains about the pathspec not matching anything.
67+
# That's OK. It's not worth the effort to suppress. Please ignore it.
68+
if git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*'
69+
then
70+
echo "Build/test created untracked files in the repo (file names above)."
71+
exit 1
72+
fi
73+
74+
check_mergeability:
75+
if: always()
76+
runs-on: ubuntu-24.04
77+
needs:
78+
- test
79+
steps:
80+
- name: Decide if change is okay to merge
81+
if: github.event_name != 'push'
82+
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
83+
with:
84+
jobs: ${{ toJSON(needs) }}

0 commit comments

Comments
 (0)