Schedule (SGID Index Validation) #114
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: Schedule (SGID Index Validation) | |
on: | |
schedule: | |
- cron: '0 0 * * 1-5' | |
workflow_dispatch: | |
issue_comment: | |
types: [created, edited] | |
permissions: | |
issues: write | |
jobs: | |
validate: | |
name: Validate SGID Index | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./src/scripts | |
env: | |
GOOGLE_PRIVATE_KEY: ${{ secrets.SA }} | |
RESULTS_COMMENT_TITLE: SGID Index Validation | |
steps: | |
- name: ✅ Check comment | |
if: github.event_name == 'issue_comment' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const commentBody = context.payload.comment.body; | |
if (commentBody.startsWith('/validate-sgid-index')) { | |
github.reactions.createForIssueComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: context.payload.comment.id, | |
content: '+1' | |
}); | |
console.log('Validating SGID Index'); | |
github.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.issue.number | |
}).then(({data}) => { | |
const comment = data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes(process.env.RESULTS_COMMENT_TITLE)); | |
if (comment) { | |
github.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: comment.id, | |
body: `### ${process.env.RESULTS_COMMENT_TITLE}\n\n♻️Processing...♻️` | |
}); | |
} | |
}); | |
} else { | |
console.log('Skipping SGID Index validation'); | |
process.exit(78); | |
} | |
- name: ⬇️ Set up code | |
uses: actions/checkout@v4 | |
with: | |
show-progress: false | |
- name: ⎔ Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
cache: npm | |
- name: 📦 Install script dependencies | |
run: npm install | |
- name: ✔ Running script | |
uses: gh640/command-result-action@v1 | |
id: validate | |
with: | |
command: node validate-sgid-index.mjs | |
cwd: ./src/scripts | |
- name: 📝 Create issue | |
id: create-issue | |
if: steps.validate.outputs.exitCode != 0 | |
uses: JasonEtco/create-an-issue@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
filename: .github/SGID_INDEX_ISSUE_TEMPLATE.md | |
update_existing: true | |
- name: Find Open Issues | |
uses: actions/github-script@v7 | |
id: find-issue | |
if: steps.validate.outputs.exitCode == 0 | |
with: | |
script: | | |
const { data: issues } = await github.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
labels: 'sgid index validation' | |
}); | |
const issueNumber = issues[0]?.number; | |
console.log('issueNumber: ' + issueNumber); | |
return issueNumber; | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Find Comment | |
uses: peter-evans/find-comment@v3 | |
if: steps.create-issue.outputs.number || steps.find-issue.outputs.result | |
id: find-comment | |
with: | |
issue-number: ${{ steps.create-issue.outputs.number || steps.find-issue.outputs.result }} | |
comment-author: github-actions[bot] | |
body-includes: ${{ env.RESULTS_COMMENT_TITLE}} | |
- name: 🕰 Timestamp | |
id: timestamp | |
run: echo "::set-output name=result::$(date +'%Y-%m-%d %H:%M:%S')" | |
- name: ✍️ Updating issue comment with results | |
if: steps.create-issue.outputs.number || steps.find-issue.outputs.result | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ steps.create-issue.outputs.number || steps.find-issue.outputs.result }} | |
comment-id: ${{ steps.find-comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
### ${{ env.RESULTS_COMMENT_TITLE }} | |
*last run time:* ${{ steps.timestamp.outputs.result }} | |
#### Script Output | |
``` | |
${{ steps.validate.outputs.stdout }} | |
``` | |
#### Validation Errors | |
${{ steps.validate.outputs.stderr }} | |
- name: 🚦 Check for errors | |
if: steps.validate.outputs.exitCode != 0 | |
run: | | |
echo "::error::Validate stderr${{ steps.validate.outputs.stderr }}" | |
exit ${{ steps.validate.outputs.exitCode }} | |
- name: 🎉 Close issue | |
if: steps.validate.outputs.exitCode == 0 && steps.find-issue.outputs.result | |
run: gh issue close --comment "All validations have passed successfully" "${{ steps.find-issue.outputs.result }}" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |