[iris] Move periodic checkpoint to its own thread, delay first run by one interval #1689
Workflow file for this run
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: Grug Variant Diff | |
| on: | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| outputs: | |
| should_run: ${{ steps.filter.outputs.relevant }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| filters: | | |
| relevant: | |
| - 'experiments/grug/**' | |
| - 'scripts/grug_dir_diff.py' | |
| - 'scripts/grug_variant_diff_ci.py' | |
| - '.github/workflows/grug-variant-diff.yaml' | |
| grug-variant-diff: | |
| needs: changes | |
| if: needs.changes.outputs.should_run == 'true' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Generate variant diff reports | |
| run: | | |
| python -m scripts.grug_variant_diff_ci \ | |
| --base-sha "${{ github.event.pull_request.base.sha }}" \ | |
| --head-sha "${{ github.event.pull_request.head.sha }}" \ | |
| --output-dir grug-diff-report \ | |
| --manifest-path grug-diff-report/manifest.json | |
| - name: Read manifest metadata | |
| id: manifest | |
| run: | | |
| python - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| manifest = json.loads(Path("grug-diff-report/manifest.json").read_text(encoding="utf-8")) | |
| report_count = int(manifest.get("report_count", 0)) | |
| has_reports = "true" if report_count > 0 else "false" | |
| with Path(os.environ["GITHUB_OUTPUT"]).open("a", encoding="utf-8") as output: | |
| output.write(f"report_count={report_count}\n") | |
| output.write(f"has_reports={has_reports}\n") | |
| PY | |
| - name: Upload report artifact | |
| id: artifact | |
| if: steps.manifest.outputs.has_reports == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: grug-variant-diff-pr-${{ github.event.pull_request.number }} | |
| path: grug-diff-report | |
| retention-days: 14 | |
| - name: Publish rendered report to gh-pages | |
| id: publish | |
| if: steps.manifest.outputs.has_reports == 'true' && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: grug-diff-report | |
| destination_dir: grug-diffs/pr-${{ github.event.pull_request.number }} | |
| keep_files: true | |
| - name: Post PR comment with report links | |
| if: "!cancelled() && github.event.pull_request.head.repo.full_name == github.repository" | |
| uses: actions/github-script@v7 | |
| env: | |
| ARTIFACT_URL: ${{ steps.artifact.outputs.artifact-url }} | |
| PAGES_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/grug-diffs/pr-${{ github.event.pull_request.number }} | |
| PAGES_PUBLISHED: ${{ steps.publish.outcome == 'success' }} | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const marker = '<!-- grug-variant-diff-report -->'; | |
| const manifest = JSON.parse(fs.readFileSync('grug-diff-report/manifest.json', 'utf8')); | |
| const reportCount = Number(manifest.report_count || 0); | |
| const pagesUrl = process.env.PAGES_URL; | |
| const pagesPublished = process.env.PAGES_PUBLISHED === 'true'; | |
| const artifactUrl = process.env.ARTIFACT_URL || ''; | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner, | |
| repo, | |
| issue_number, | |
| per_page: 100, | |
| }); | |
| const existing = comments.find((comment) => comment.body && comment.body.includes(marker)); | |
| if (reportCount === 0) { | |
| if (existing) { | |
| await github.rest.issues.deleteComment({ | |
| owner, | |
| repo, | |
| comment_id: existing.id, | |
| }); | |
| } | |
| return; | |
| } | |
| let body = '🤖 Grug variant diff report\n'; | |
| body += `${marker}\n\n`; | |
| if (!pagesPublished) { | |
| body += 'Rendered GitHub Pages links were not published for this run.\n\n'; | |
| } | |
| body += '| New Variant | Closest Existing Variant | Distance Score | Diff |\n'; | |
| body += '|---|---|---:|---|\n'; | |
| for (const report of manifest.reports) { | |
| const variant = report.variant; | |
| const closest = report.closest_variant; | |
| const score = report.distance_score; | |
| const link = pagesPublished | |
| ? `[Open](${pagesUrl}/${variant}/index.html)` | |
| : `artifact:\`${report.report_relpath}\``; | |
| body += `| \`${variant}\` | \`${closest}\` | ${score} | ${link} |\n`; | |
| } | |
| if (artifactUrl) { | |
| body += `\nArtifact fallback: [Download report bundle](${artifactUrl})\n`; | |
| } | |
| if (!pagesPublished) { | |
| body += '\nFor fork PRs, this workflow usually cannot publish to `gh-pages`; artifact link remains available.'; | |
| } | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } |