Skip to content

Commit

Permalink
chore(ci): add annotations to GH on Go test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Mar 6, 2024
1 parent aeef03a commit bc7e659
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Docker Compose
run: docker compose up -d --wait
- name: Test
run: go test ./...
run: go-test-annotate
sql:
name: SQL
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions bin/.gotestsum-1.11.0.pkg
1 change: 1 addition & 0 deletions bin/gotestsum
2 changes: 1 addition & 1 deletion buildengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestEngine(t *testing.T) {
expected := map[string][]string{
"alpha": {"another", "other", "builtin"},
"another": {"builtin"},
"other": {},
"other": {"alpha"},
"builtin": {},
}
graph, err := engine.Graph()
Expand Down
18 changes: 18 additions & 0 deletions scripts/go-test-annotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -exuo pipefail

fail=0
if ! gotestsum --format-hide-empty-pkg --junitfile junit-go.xml --junitfile-hide-empty-pkg -- -fullpath ./...; then
fail=1
fi

dir="$(pwd)"
yq -oj '.. | select(has("failure")) | .failure["+content"]' junit-go.xml | while read -r failure; do
line="$(echo "$failure" | jq -r | grep -E "$dir/.*\.go:[0-9]+" | sed -e "s,^[ ]*$dir/,,")"
file_path=$(echo "$line" | cut -d':' -f1)
line_number=$(echo "$line" | cut -d':' -f2)
# Output the warning message in the format expected by GitHub Actions
echo "::error file=$file_path,line=$line_number::$(echo "$failure" | jq -sRr @uri)"
done

exit "$fail"

0 comments on commit bc7e659

Please sign in to comment.