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 fca0327
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
19 changes: 5 additions & 14 deletions .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 Expand Up @@ -61,11 +61,11 @@ jobs:
- name: Build Cache
uses: ./.github/actions/build-cache
- name: golangci-lint
run: golangci-lint run
run: golangci-lint run --out-format github-actions ./...
- name: go-check-sumtype
run: go-check-sumtype ./...
run: go-check-sumtype ./... | to-annotation
- name: actionlint
run: actionlint --oneline
run: actionlint --oneline | to-annotation
# Too annoying to disable individual warnings
# - name: staticcheck
# run: staticcheck ./...
Expand All @@ -82,16 +82,7 @@ jobs:
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Proto Breaking Change Check
run: |
buf breaking --against 'https://github.com/TBD54566975/ftl.git#branch=main' | while read -r line; do
# Extract the file path, line number, and column number from the warning message
file_path=$(echo "$line" | cut -d':' -f1)
line_number=$(echo "$line" | cut -d':' -f2)
column_number=$(echo "$line" | cut -d':' -f3)
# Output the warning message in the format expected by GitHub Actions
echo "::error file=$file_path,line=$line_number,col=$column_number::$line"
done
run: buf breaking --against 'https://github.com/TBD54566975/ftl.git#branch=main' | to-annotation
console:
name: Console
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ testdata/**/go.work.sum
**/_ftl
buildengine/.gitignore
go.work*
junit*.xml
1 change: 1 addition & 0 deletions bin/.gotestsum-1.11.0.pkg
1 change: 1 addition & 0 deletions bin/gotestsum
23 changes: 23 additions & 0 deletions scripts/go-test-annotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -euo pipefail

# This is convoluted because Go's -json output is basically just a JSON struct
# per line of output, and gotestsum doesn't include structured line output in
# the junit.xml file. So we parse the XML, extracting the failure messages and
# then match lines containing lines that look like error messages.

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 -r . | sed -e "s,$dir/,," | sed -e 's,$,%0A,g' | tr -d '\n')"
done

exit "$fail"
10 changes: 10 additions & 0 deletions scripts/to-annotation
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -euo pipefail
dir="$(pwd)"
sed -e "s,$dir/,," | while read line; do
file_path=$(echo "$line" | cut -d':' -f1)
line_number=$(echo "$line" | cut -d':' -f2)
column_number=$(echo "$line" | cut -d':' -f3)
line=$(echo "$line" | cut -d':' -f4-)
echo "::error file=$file_path,line=$line_number,col=$column_number::$line"
done

0 comments on commit fca0327

Please sign in to comment.