parsing exomol linelists #101
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
name: TODOs | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
find-todos: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Find TODOs | |
id: find_todos | |
run: | | |
TODO_LIST=$(grep -r -n -A 3 -E "TODO|@show " --include="*.jl" --include="*.ipynb" || true) | |
echo "todo_list<<EOF" >> $GITHUB_OUTPUT | |
echo "$TODO_LIST" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
if [ -n "$TODO_LIST" ]; then | |
echo "has_todos=true" >> $GITHUB_OUTPUT | |
else | |
echo "has_todos=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Update or Create Comment | |
if: steps.find_todos.outputs.has_todos == 'true' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const todoList = process.env.TODO_LIST; | |
const body = `## TODOs and @show instances found in this PR:\n\n\`\`\`\n${todoList}\n\`\`\``; | |
const { data: comments } = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const botComment = comments.find(comment => | |
comment.user.type === 'Bot' && comment.body.includes('instances found in this PR')); | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
comment_id: botComment.id, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}); | |
} | |
env: | |
TODO_LIST: ${{ steps.find_todos.outputs.todo_list }} | |
- name: Remove Comment if No TODOs | |
if: steps.find_todos.outputs.has_todos == 'false' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const { data: comments } = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const botComment = comments.find(comment => | |
comment.user.type === 'Bot' && comment.body.includes('instances found in this PR')); | |
if (botComment) { | |
await github.rest.issues.deleteComment({ | |
comment_id: botComment.id, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
} | |
- name: TODO Check | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const hasTodos = '${{ steps.find_todos.outputs.has_todos }}' === 'true'; | |
if (hasTodos) { | |
core.setFailed('TODOs found in this PR'); | |
} |