generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): add annotations to GH on Go test failures
- Loading branch information
1 parent
aeef03a
commit c1f3ed3
Showing
6 changed files
with
41 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ testdata/**/go.work.sum | |
**/_ftl | ||
buildengine/.gitignore | ||
go.work* | ||
junit*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hermit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.gotestsum-1.11.0.pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |