|
| 1 | +# Description |
| 2 | +# Checks designated GitHub documentation pages for content changes and files an issue when detected. |
| 3 | + |
| 4 | +name: GitHub Docs Watch |
| 5 | + |
| 6 | +on: |
| 7 | + # Run every 14 days at 09:00 UTC and allow manual runs for verification. |
| 8 | + schedule: |
| 9 | + - cron: '0 9 */14 * *' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + # Read repo contents and open issues on detected changes. |
| 14 | + contents: read |
| 15 | + issues: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + check: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + # Checkout repository contents for local hashes and metadata. |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Setup Node.js |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: 20.x |
| 29 | + |
| 30 | + - name: Check documentation hashes |
| 31 | + id: check |
| 32 | + run: node scripts/check-github-docs.mjs --output docs/github-documentation/docs-check.json --write-summary |
| 33 | + |
| 34 | + - name: Create issue if docs changed |
| 35 | + # Avoid opening duplicate issues by title when changes are detected. |
| 36 | + if: steps.check.outputs.changed == 'true' |
| 37 | + uses: actions/github-script@v7 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const fs = require('fs'); |
| 41 | + const data = JSON.parse(fs.readFileSync('docs/github-documentation/docs-check.json', 'utf8')); |
| 42 | + const changed = data.results.filter((item) => item.changed); |
| 43 | +
|
| 44 | + const title = 'GitHub documentation change detected'; |
| 45 | + const { owner, repo } = context.repo; |
| 46 | +
|
| 47 | + const existing = await github.rest.issues.listForRepo({ |
| 48 | + owner, |
| 49 | + repo, |
| 50 | + state: 'open', |
| 51 | + per_page: 100, |
| 52 | + }); |
| 53 | +
|
| 54 | + if (existing.data.some((issue) => issue.title === title)) { |
| 55 | + console.log('Existing issue found; skipping creation.'); |
| 56 | + return; |
| 57 | + } |
| 58 | +
|
| 59 | + const lines = [ |
| 60 | + 'The scheduled documentation check detected changes in these files:', |
| 61 | + '', |
| 62 | + ]; |
| 63 | +
|
| 64 | + for (const item of changed) { |
| 65 | + lines.push(`- ${item.file}`); |
| 66 | + lines.push(` - redirect: ${item.redirect_link}`); |
| 67 | + lines.push(` - expected: ${item.expected_hash ?? 'missing'}`); |
| 68 | + lines.push(` - actual: ${item.actual_hash}`); |
| 69 | + lines.push(''); |
| 70 | + } |
| 71 | +
|
| 72 | + lines.push( |
| 73 | + `Run: ${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`, |
| 74 | + ); |
| 75 | +
|
| 76 | + await github.rest.issues.create({ |
| 77 | + owner, |
| 78 | + repo, |
| 79 | + title, |
| 80 | + body: lines.join('\n'), |
| 81 | + }); |
0 commit comments