Skip to content

Commit

Permalink
ci(ci): improve check-todos
Browse files Browse the repository at this point in the history
  • Loading branch information
fargito committed Jan 15, 2025
1 parent f81bbe9 commit 5347b7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
pull_request:
workflow_dispatch:

permissions:
issues: write

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -29,4 +32,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Check for todos
id: check-todos
run: ./scripts/show-todos.sh
- name: Comment PR
uses: thollander/actions-comment-pull-request@v3
with:
message: "${{ steps.check-todos.outputs.pr-comment }}"
comment-tag: execution
22 changes: 20 additions & 2 deletions scripts/show-todos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ if [ "$LINEAR_ISSUE" = "" ]; then
exit 0
fi

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

grep "TODO($LINEAR_ISSUE)" . -Rni --color --exclude-dir=".git"
exit 0
fi

# On the CI
MATCHED_TODOS=$(grep "TODO($LINEAR_ISSUE)" . -Rni --exclude-dir=".git")

if [ "$MATCHED_TODOS" = "" ]; then
exit 0
fi

# Annotate files
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-notice-message
echo "$MATCHED_TODOS" | awk -F":" -v issue=$LINEAR_ISSUE {'print "::notice file="$1",line="$2",title=TODO for "issue"::"$4'}

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")\\"}')
echo "pr-comment=$PR_COMMENT" >>"$GITHUB_OUTPUT"

0 comments on commit 5347b7d

Please sign in to comment.