-
Notifications
You must be signed in to change notification settings - Fork 4
89 lines (76 loc) · 3.32 KB
/
Copy pathci.yml
File metadata and controls
89 lines (76 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: ci
# Run the repo's checks on pull requests, and on pushes to main so a merge that
# breaks something is attributed to the merge rather than to the next PR.
#
# The checks mirror the Makefile targets a contributor runs locally (fmt, vet,
# test), so CI failing means the same command fails on their machine. gofmt is
# checked with -l rather than `make fmt`, which rewrites files: CI must report
# formatting, not silently fix it and test something the author never wrote.
#
# Tests are self-contained — they bind ephemeral localhost ports and set HOME to
# a temp dir, and the container tests assert on generated command strings without
# invoking a real runtime — so no services, credentials, or network egress are
# needed.
on:
pull_request:
push:
branches: [main]
# Read-only: nothing here writes to the repo, and the default token grants more.
permissions:
contents: read
# A force-push or a quick follow-up commit makes an in-flight run obsolete;
# cancel it rather than paying for a result nobody reads. Pushes to main are
# keyed per-ref, so consecutive merges do not cancel each other.
concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
# go.mod is the single source of the Go version, as in release.yml.
go-version-file: go.mod
# Before the build, so a formatting failure is reported in seconds rather
# than after the slowest step.
- name: Check formatting
run: |
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
echo "These files need gofmt:" >&2
echo "$unformatted" >&2
exit 1
fi
# `go mod tidy` writing nothing proves go.mod and go.sum match the imports.
# Checked against the real files rather than a copy so the diff names them.
- name: Check go.mod is tidy
run: |
go mod tidy
if ! git diff --quiet -- go.mod go.sum; then
echo "go.mod/go.sum are not tidy; run 'make tidy' and commit the result:" >&2
git diff -- go.mod go.sum >&2
exit 1
fi
- name: Vet
run: make vet
- name: Build
run: go build ./...
# -count=1 defeats the test cache, which would otherwise let a green result
# stand in for a run that never happened on this commit.
- name: Test
run: go test ./... -count=1
# A second pass under the race detector. Separate from the run above so a
# plain failure is not reported as a race, and because the suite is fast
# enough (a few seconds) that running it twice costs little.
- name: Test with the race detector
run: go test ./... -race -count=1
# Test order is a real source of flakes here: the suite mutates process
# state (HOME, XDG_CONFIG_HOME, cobra flag values), and cmd/root_test.go
# documents a pflag hazard where a flag's first Set in a later test can
# append rather than replace. Shuffling surfaces that in CI instead of on
# someone's unrelated PR.
- name: Test in a shuffled order
run: go test ./... -count=1 -shuffle=on