From a8894a074586b3b5a1b922452f37c13e50941d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 1 Apr 2020 14:20:58 +0200 Subject: [PATCH 1/4] Assert that running `go fmt` or `go mod tidy` produces no changes in CI This will help avoid introducing code changes that are not properly formatted, or `go mod` dependency changes that are untidy. Ref. 0680bb5c6c230ea6adccbc63c1374fe56d11d971 --- .github/workflows/go.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2789ade34..500bced8f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,8 +20,24 @@ jobs: - name: Verify dependencies run: go mod verify - - name: Build + - name: Run tests shell: bash run: | - go test -race ./... - go build -v ./cmd/gh + assert-nothing-changed() { + local diff + git checkout -- . + "$@" >/dev/null || true + if ! diff="$(git diff --exit-code)"; then + printf '\n\e[31mError: running `\e[31;1m%s\e[31;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 From 7dbc5e99e4b3433a6bf34492a83233ed3cec1279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 1 Apr 2020 14:42:32 +0200 Subject: [PATCH 2/4] go: download dependencies before running tests in CI --- .github/workflows/go.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 500bced8f..02b04922e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,7 +18,10 @@ jobs: uses: actions/checkout@v2 - name: Verify dependencies - run: go mod verify + shell: bash + run: | + go mod verify + go mod download - name: Run tests shell: bash From 228312a30d7c861eff39c87526b0edadfba468c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 1 Apr 2020 14:47:42 +0200 Subject: [PATCH 3/4] Have git diff produce colored output in CI --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 02b04922e..d4b95cafc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,7 +30,7 @@ jobs: local diff git checkout -- . "$@" >/dev/null || true - if ! diff="$(git diff --exit-code)"; then + if ! diff="$(git diff -U1 --color --exit-code)"; then printf '\n\e[31mError: running `\e[31;1m%s\e[31;22m` results in modifications that you must check into version control:\e[0m\n%s\n' "$*" "$diff" >&2 return 1 fi From ad190519c64b0f24e3ba74bbd6d6694f0e72bdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 1 Apr 2020 15:09:24 +0200 Subject: [PATCH 4/4] Simplify ANSI coloring --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d4b95cafc..e8098bcd8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -31,7 +31,7 @@ jobs: git checkout -- . "$@" >/dev/null || true if ! diff="$(git diff -U1 --color --exit-code)"; then - printf '\n\e[31mError: running `\e[31;1m%s\e[31;22m` results in modifications that you must check into version control:\e[0m\n%s\n' "$*" "$diff" >&2 + 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 }