Skip to content

Commit 4cdfbb8

Browse files
committed
[ci] Display TODO errors in GitHub PR UI
Also ensure that `rg` is installed in CI. gherrit-pr-id: I2d944fc641d1b3d122cf39ac5410718ecbce699c
1 parent 6b8562d commit 4cdfbb8

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ 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+
# TODO
20+
21+
# Make sure `rg` is installed (if this fails, `set -e` above will cause the
22+
# script to exit).
23+
rg --version >/dev/null
24+
1925
# -H: Print filename (default for multiple files/recursive)
2026
# -n: Print line number
2127
# -w: Match whole words
@@ -25,6 +31,26 @@ if [ -n "$output" ]; then
2531
echo "Found $KEYWORD markers in the codebase." >&2
2632
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
2733
echo "" >&2
28-
echo "$output" >&2
34+
if [ "${GITHUB_ACTIONS:-false}" == "true" ]; then
35+
echo "$output" | while IFS= read -r output; do
36+
# Parse format `file:line: message`
37+
file=$(echo "$output" | cut -d : -f 1)
38+
line=$(echo "$output" | cut -d : -f 2)
39+
message=$(echo "$output" | cut -d : -f 3-)
40+
41+
# Escape message for workflow command: % -> %25, \r -> %0D, \n -> %0A
42+
message="${message//'%'/'%25'}"
43+
message="${message//$'\r'/'%0D'}"
44+
message="${message//$'\n'/'%0A'}"
45+
46+
# Output the workflow command for GitHub Actions annotations. Use `::notice`
47+
# rather than `::error` so that the output is less visually distracting (the
48+
# `exit 1` below will still ensure that this causes CI to fail).
49+
echo "::notice file=${file},line=${line},endLine=${line},title=$KEYWORD Found::${message}"
50+
done
51+
else
52+
echo "$output" >&2
53+
fi
54+
2955
exit 1
3056
fi

0 commit comments

Comments
 (0)