Skip to content

Commit 44a37cb

Browse files
author
Nate Smith
authored
Merge pull request cli#723 from cli/go-ci-checks
Assert that running `go fmt` or `go mod tidy` produces no changes in CI
2 parents 0680bb5 + ad19051 commit 44a37cb

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

.github/workflows/go.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,29 @@ jobs:
1818
uses: actions/checkout@v2
1919

2020
- name: Verify dependencies
21-
run: go mod verify
21+
shell: bash
22+
run: |
23+
go mod verify
24+
go mod download
2225
23-
- name: Build
26+
- name: Run tests
2427
shell: bash
2528
run: |
26-
go test -race ./...
27-
go build -v ./cmd/gh
29+
assert-nothing-changed() {
30+
local diff
31+
git checkout -- .
32+
"$@" >/dev/null || true
33+
if ! diff="$(git diff -U1 --color --exit-code)"; then
34+
printf '\n\e[31mError: running `\e[1m%s\e[22m` results in modifications that you must check into version control:\e[0m\n%s\n' "$*" "$diff" >&2
35+
return 1
36+
fi
37+
}
38+
39+
STATUS=0
40+
go test -race ./... || STATUS=$?
41+
assert-nothing-changed go fmt ./... || STATUS=$?
42+
assert-nothing-changed go mod tidy || STATUS=$?
43+
exit $STATUS
44+
45+
- name: Build
46+
run: go build -v ./cmd/gh

0 commit comments

Comments
 (0)