Skip to content

Commit 29e76dd

Browse files
committed
[ci] Display TODO errors in GitHub PR UI
gherrit-pr-id: I2d944fc641d1b3d122cf39ac5410718ecbce699c
1 parent 6b8562d commit 29e76dd

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ jobs:
778778
runs-on: ubuntu-latest
779779
name: Check for todo comments
780780
steps:
781+
- name: Install ripgrep
782+
run: |
783+
sudo apt-get update
784+
sudo apt-get install ripgrep
781785
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
782786
- name: Run todo check
783787
run: ./ci/check_todo.sh
@@ -788,6 +792,10 @@ jobs:
788792
steps:
789793
- name: Install yq (for YAML parsing)
790794
run: go install github.com/mikefarah/yq/v4@latest
795+
- name: Install ripgrep
796+
run: |
797+
sudo apt-get update
798+
sudo apt-get install ripgrep
791799
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
792800
- name: Run dependency check
793801
# Ensure that Git hooks execute successfully.

ci/check_todo.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ set -euo pipefail
1616
# would mean that we couldn't use XODO comments in this script.
1717
KEYWORD=$(echo XODO | sed -e 's/X/T/')
1818

19+
# Make sure `rg` is installed (if this fails, `set -e` above will cause the
20+
# script to exit).
21+
rg --version >/dev/null
22+
1923
# -H: Print filename (default for multiple files/recursive)
2024
# -n: Print line number
2125
# -w: Match whole words
@@ -25,6 +29,26 @@ if [ -n "$output" ]; then
2529
echo "Found $KEYWORD markers in the codebase." >&2
2630
echo "$KEYWORD is used for tasks that should be done before merging a PR; if you want to leave a message in the codebase, use FIXME." >&2
2731
echo "" >&2
28-
echo "$output" >&2
32+
if [ "${GITHUB_ACTIONS:-false}" == "true" ]; then
33+
echo "$output" | while IFS= read -r line; do
34+
# Parse format `file:line: message`
35+
file=$(echo "$line" | cut -d : -f 1)
36+
line=$(echo "$line" | cut -d : -f 2)
37+
message=$(echo "$line" | cut -d : -f 3-)
38+
39+
# Escape message for workflow command: % -> %25, \r -> %0D, \n -> %0A
40+
message="${message//'%'/'%25'}"
41+
message="${message//$'\r'/'%0D'}"
42+
message="${message//$'\n'/'%0A'}"
43+
44+
# Output the workflow command for GitHub Actions annotations. Use `::notice`
45+
# rather than `::error` so that the output is less visually distracting (the
46+
# `exit 1` below will still ensure that this causes CI to fail).
47+
echo "::notice file=${file},line=${line},endLine=${line},title=$KEYWORD Found::${message}"
48+
done
49+
else
50+
echo "$output" >&2
51+
fi
52+
2953
exit 1
3054
fi

0 commit comments

Comments
 (0)