Skip to content

Commit d868703

Browse files
committed
ci(ci): improve check-todos
1 parent f81bbe9 commit d868703

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@v3
3131
- name: Check for todos
32+
id: check-todos
3233
run: ./scripts/show-todos.sh
34+
- name: Comment PR
35+
uses: thollander/actions-comment-pull-request@v3
36+
with:
37+
message: ${{ steps.check-todos.outputs.pr-comment }}
38+
comment-tag: execution

scripts/show-todos.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ if [ "$LINEAR_ISSUE" = "" ]; then
1212
exit 0
1313
fi
1414

15-
echo "Searching todos for $LINEAR_ISSUE"
15+
# Locally, simply search and display
16+
if [ "$CI" != "true" ]; then
17+
echo "Searching todos for $LINEAR_ISSUE"
18+
grep "TODO($LINEAR_ISSUE)" . -Rni --color --exclude-dir=".git"
1619

17-
grep "TODO($LINEAR_ISSUE)" . -Rni --color --exclude-dir=".git"
20+
exit 0
21+
fi
22+
23+
# On the CI
24+
MATCHED_TODOS=$(grep "TODO($LINEAR_ISSUE)" . -Rni --exclude-dir=".git")
25+
26+
if [ "$MATCHED_TODOS" = "" ]; then
27+
exit 0
28+
fi
29+
30+
# Annotate files
31+
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-notice-message
32+
echo "$MATCHED_TODOS" | awk -F":" -v issue=$LINEAR_ISSUE {'print "::notice file="$1",line="$2",title=TODO for "issue"::"$4'}
33+
34+
PR_COMMENT=$(echo "$MATCHED_TODOS" | awk -F":" -v issue=$LINEAR_ISSUE -v branch=$BRANCH_NAME 'BEGIN{print "Found some TODO annotations for "issue":"} {print "- [ ] ["$4"](../blob/"branch"/"$1":"$2")\\"}')
35+
echo "pr-comment=$PR_COMMENT" >>"$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)