Skip to content

Commit fb7a59b

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, headed by the pull request number and title, uploads the page to the CDN at semantic-diff/pr-<N>/index.html, and posts its link as a comment that replaces the previous one, so the newest link is the last comment on the pull request. The link carries the rendered head commit as a query string. Closing the pull request deletes the page. A pull request from a branch of this repository runs on pull_request, with its own workflow and renderer, from its first push and on any base branch. A pull request from a fork runs on pull_request_target. Security: pull_request_target takes the workflow from the default branch and runs it with the repository's secrets, so for forks the job runs only the default 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; the title reaches the shell only through an environment variable. Each pull request runs on one of the two events: the jobs compare the event with the head repository, and the concurrency group names the event. 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 Tests: none, because the workflow runs only on GitHub; its render step is the renderer that scripts/commitRecords.test.js covers PR: #8870 Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5ddbf9b commit fb7a59b

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

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

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

0 commit comments

Comments
 (0)