Skip to content

Commit a7f0b38

Browse files
cristianocclaude
andcommitted
Link a semantic diff page on each pull request
When a pull request is opened, reopened or pushed, the Semantic Diff workflow renders its commits with scripts/commitRecords.js, uploads the page to the CDN at semantic-diff/pr-<N>/index.html, and keeps one comment on the pull request with its link. The link carries the rendered head commit as a query string. Closing the pull request deletes the page. The workflow runs on pull_request_target, before and independently of CI, for pull requests from forks and for pull requests based on any branch. Security: pull_request_target runs with the repository's secrets, so the job runs only the base branch's code. It checks out the base commit without persisted credentials, fetches refs/pull/<N>/head as git objects, and renders them with the base branch's renderer, which reads git data and escapes all text it writes into the page. Review: Why the CDN and not GitHub Pages? Pages here is one deployment from master (the dev playground) that each deploy replaces whole; the CDN already holds the playground's per-pull-request bundles under dev-playground-bundles/pr-<N>/. Area: ci docs Changelog: none Output: unchanged Ran: dry run of the render step in a fresh blob:none clone of rescript-lang/rescript against refs/pull/8862/head (page written, both checks pass); YAML parse (ok); upload, comment and cleanup steps run only on GitHub Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 058c23b commit a7f0b38

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎.claude/skills/records/SKILL.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ node scripts/commitRecords.js --fragment --out part.html <rev>...
133133
the description of the work. A pull request description is a rendering of
134134
its range.
135135
- Before review or merge: render `master..<branch>` and hand over the page.
136+
- On GitHub, `.github/workflows/semantic_diff.yml` renders each pull
137+
request's range when it is opened or pushed, and comments the page's link
138+
(`Semantic diff: https://cdn.rescript-lang.org/semantic-diff/pr-<N>/…`).
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Semantic Diff
2+
3+
# Renders the commit records of each pull request (scripts/commitRecords.js)
4+
# as a review page on the CDN and links it from the pull request. It runs with
5+
# the repository's secrets, so it executes only the base branch's code: the
6+
# pull request's commits are fetched as git data and never checked out.
7+
8+
on:
9+
pull_request_target:
10+
types: [opened, synchronize, reopened, closed]
11+
12+
concurrency:
13+
group: semantic-diff-${{ github.event.pull_request.number }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
render:
18+
if: ${{ github.event.action != 'closed' }}
19+
runs-on: ubuntu-24.04
20+
permissions:
21+
contents: read
22+
pull-requests: write
23+
env:
24+
PR_NUMBER: ${{ github.event.pull_request.number }}
25+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
26+
steps:
27+
- name: Checkout base branch
28+
uses: actions/checkout@v7
29+
with:
30+
ref: ${{ github.event.pull_request.base.sha }}
31+
fetch-depth: 0
32+
filter: blob:none
33+
persist-credentials: false
34+
35+
- name: Render semantic diff
36+
id: render
37+
run: |
38+
git fetch --no-tags --filter=blob:none origin "refs/pull/${PR_NUMBER}/head:refs/heads/pr-${PR_NUMBER}"
39+
base=$(git merge-base "$BASE_SHA" "pr-${PR_NUMBER}")
40+
mkdir -p semantic-diff
41+
node scripts/commitRecords.js --out semantic-diff/index.html "${base}..pr-${PR_NUMBER}"
42+
echo "head=$(git rev-parse --short=9 "pr-${PR_NUMBER}")" >> "$GITHUB_OUTPUT"
43+
44+
- name: Setup Rclone
45+
uses: cometkim/rclone-actions/setup-rclone@main
46+
47+
- name: Configure Rclone remote
48+
uses: cometkim/rclone-actions/configure-remote/s3-provider@main
49+
with:
50+
name: rescript
51+
provider: Cloudflare
52+
endpoint: https://${{ vars.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
53+
access-key-id: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
54+
secret-access-key: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
55+
acl: private
56+
57+
- name: Upload semantic diff
58+
run: rclone copyto semantic-diff/index.html "rescript:cdn-assets/semantic-diff/pr-${PR_NUMBER}/index.html"
59+
60+
# The query string names the rendered commit, so each push gets a URL
61+
# that no cache has seen.
62+
- name: Comment semantic diff URL
63+
uses: thollander/actions-comment-pull-request@v3
64+
with:
65+
pr-number: ${{ github.event.pull_request.number }}
66+
comment-tag: semantic-diff
67+
message: |
68+
Semantic diff: https://cdn.rescript-lang.org/semantic-diff/pr-${{ github.event.pull_request.number }}/index.html?v=${{ steps.render.outputs.head }}
69+
70+
cleanup:
71+
if: ${{ github.event.action == 'closed' }}
72+
runs-on: ubuntu-24.04
73+
permissions: {}
74+
steps:
75+
- name: Setup Rclone
76+
uses: cometkim/rclone-actions/setup-rclone@main
77+
78+
- name: Configure Rclone remote
79+
uses: cometkim/rclone-actions/configure-remote/s3-provider@main
80+
with:
81+
name: rescript
82+
provider: Cloudflare
83+
endpoint: https://${{ vars.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
84+
access-key-id: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
85+
secret-access-key: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
86+
acl: private
87+
88+
- name: Delete semantic diff
89+
continue-on-error: true
90+
run: rclone purge "rescript:cdn-assets/semantic-diff/pr-${{ github.event.pull_request.number }}"

0 commit comments

Comments
 (0)