clob-l0-hook + l5: polish JA review feedback #38
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: openhl Cite Check | |
| # Verifies every `path/to/file.rs:LINE@SHA` cite in drafts/openhl_*.md | |
| # resolves at the pinned SHA in the openhl repo. The companion to | |
| # source-link-check (GitHub /blob/ URLs) and external-link-check | |
| # (everything else); this one watches for drift in the dual-repo | |
| # discipline between rethlab drafts and openhl source. | |
| # | |
| # Triggers: | |
| # - push to main: when drafts or the checker change | |
| # - pull_request: same paths, catch drift before merge | |
| # - workflow_dispatch: manual trigger | |
| # | |
| # Unlike the other link checkers (weekly cron + issue on failure), this | |
| # one runs on PR so cite drift is caught at review time. On main pushes | |
| # that fail, we still open an issue so the rot is visible. | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'drafts/openhl_*.md' | |
| - '.github/scripts/check-openhl-cites.ts' | |
| - '.github/workflows/openhl-cite-check.yml' | |
| pull_request: | |
| paths: | |
| - 'drafts/openhl_*.md' | |
| - '.github/scripts/check-openhl-cites.ts' | |
| - '.github/workflows/openhl-cite-check.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| check: | |
| name: Check openhl SHA-pinned cites | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out rethlab | |
| uses: actions/checkout@v4 | |
| with: | |
| path: rethlab | |
| - name: Check out openhl | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: psyto/openhl | |
| path: openhl | |
| # Full history so old SHAs cited in lessons still resolve. | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| cache-dependency-path: rethlab/package-lock.json | |
| - name: Install dependencies | |
| working-directory: rethlab | |
| run: npm ci | |
| - id: check | |
| name: Run openhl cite checker | |
| working-directory: rethlab | |
| env: | |
| OPENHL_REPO: ${{ github.workspace }}/openhl | |
| run: npx tsx .github/scripts/check-openhl-cites.ts | tee /tmp/openhl-cite-report.txt | |
| continue-on-error: true | |
| - name: Fail the job if the check failed | |
| if: steps.check.outcome == 'failure' | |
| run: exit 1 | |
| - name: Open issue on main failure | |
| if: steps.check.outcome == 'failure' && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const report = fs.readFileSync('/tmp/openhl-cite-report.txt', 'utf8'); | |
| const today = new Date().toISOString().slice(0, 10); | |
| const title = `openhl cite-check failed (${today})`; | |
| // Dedup: skip if an issue with the same title already exists. | |
| const { data: existing } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'openhl-cite-rot', | |
| }); | |
| if (existing.some((i) => i.title === title)) { | |
| console.log('Issue already open for today — skipping.'); | |
| return; | |
| } | |
| const body = [ | |
| 'The openhl cite-checker found one or more broken `file:line@SHA` cites', | |
| 'in `drafts/openhl_*.md`. Most likely an openhl SHA was force-pushed or', | |
| 'a draft was edited with a typo in the cite.', | |
| '', | |
| 'Full report:', | |
| '', | |
| '```', | |
| report.slice(-5000), | |
| '```', | |
| '', | |
| 'Workflow run: ' + `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | |
| ].join('\n'); | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title, | |
| body, | |
| labels: ['openhl-cite-rot'], | |
| }); |