Check content freshness #22
This file contains hidden or 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: Check content freshness | |
| on: | |
| schedule: | |
| - cron: "47 2 * * *" | |
| workflow_dispatch: | |
| jobs: | |
| check-content: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| issues: write | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - name: Run freshness check | |
| id: freshness | |
| continue-on-error: true | |
| run: | | |
| set -o pipefail | |
| python3 scripts/check_sources.py | tee freshness-report.txt | |
| - name: Open or update issue on failure | |
| if: steps.freshness.outcome == 'failure' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require("fs"); | |
| const title = "Content freshness check failed"; | |
| const report = fs.readFileSync("freshness-report.txt", "utf8").trim(); | |
| const body = [ | |
| "The scheduled content check found a mismatch between this repo and one or more upstream BSides pages.", | |
| "", | |
| report, | |
| "", | |
| "## Workflow", | |
| "", | |
| `Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | |
| ].join("\n"); | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: "open", | |
| per_page: 100, | |
| }); | |
| const existing = issues.find((issue) => issue.title === title); | |
| if (existing) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existing.number, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title, | |
| body, | |
| labels: ["content-drift"], | |
| }); | |
| } | |
| - name: Close issue after successful run | |
| if: steps.freshness.outcome == 'success' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = "Content freshness check failed"; | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: "open", | |
| per_page: 100, | |
| }); | |
| const existing = issues.find((issue) => issue.title === title); | |
| if (existing) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existing.number, | |
| body: "Scheduled content check passed again. Closing this issue automatically.", | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existing.number, | |
| state: "closed", | |
| }); | |
| } | |
| - name: Fail workflow if check failed | |
| if: steps.freshness.outcome == 'failure' | |
| run: exit 1 |