Merge pull request #723 from cli/go-ci-checks

Assert that running `go fmt` or `go mod tidy` produces no changes in CI
This commit is contained in:
Nate Smith 2020-04-01 10:58:14 -05:00 committed by GitHub
commit 44a37cbba3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,10 +18,29 @@ jobs:
uses: actions/checkout@v2
- name: Verify dependencies
run: go mod verify
- name: Build
shell: bash
run: |
go test -race ./...
go build -v ./cmd/gh
go mod verify
go mod download
- name: Run tests
shell: bash
run: |
assert-nothing-changed() {
local diff
git checkout -- .
"$@" >/dev/null || true
if ! diff="$(git diff -U1 --color --exit-code)"; then
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
return 1
fi
}
STATUS=0
go test -race ./... || STATUS=$?
assert-nothing-changed go fmt ./... || STATUS=$?
assert-nothing-changed go mod tidy || STATUS=$?
exit $STATUS
- name: Build
run: go build -v ./cmd/gh