From e9792b6e4a9c0cf2d2199913e4e760b42c65e8f5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 4 Aug 2026 04:32:02 +0800 Subject: [PATCH 1/2] Add Cloudflare PR previews --- .github/workflows/ci.yml | 19 +++++++++++++++++++ README.md | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71a9100..fe4be80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,11 @@ on: permissions: contents: read + deployments: write + +concurrency: + group: ci-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: test-and-build: @@ -29,3 +34,17 @@ jobs: run: | npm ci npm run build + - name: Deploy PR preview + if: >- + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + id: preview + uses: cloudflare/wrangler-action@v4 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} + command: >- + pages deploy dist + --project-name=display-list-explorer + --branch=pr-${{ github.event.number }} + gitHubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 5820d85..ca53564 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ swift test The Pages workflow deploys every push to `main` and can also be run manually from any branch through `workflow_dispatch`. It tests the converter, builds the SwiftWasm package, bundles the site with the repository's Pages base path, and deploys the `dist` artifact to . +## Pull request previews + +Pull requests opened from branches in this repository are deployed to an isolated Cloudflare Pages preview after CI succeeds. Each pull request receives a stable branch alias such as `https://pr-42.display-list-explorer.pages.dev`, while every update also creates an immutable deployment URL. GitHub attaches the resulting URL to the pull request as a deployment. + +The workflow expects a `CLOUDFLARE_API_TOKEN` repository secret with Cloudflare Pages edit access and a `CLOUDFLARE_ACCOUNT_ID` repository variable. Pull requests from forks still run the converter and site build, but skip deployment because repository secrets are not exposed to fork workflows. + ## License DisplayList Explorer is available under the MIT License. Third-party attributions are listed in [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md). From 09999f7eb59baf412f23bdc6b55eeac4b0d38ae0 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 4 Aug 2026 16:13:21 +0800 Subject: [PATCH 2/2] Show stable and immutable preview URLs --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe4be80..744fb83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: permissions: contents: read deployments: write + pull-requests: write concurrency: group: ci-${{ github.event.pull_request.number || github.ref }} @@ -48,3 +49,36 @@ jobs: --project-name=display-list-explorer --branch=pr-${{ github.event.number }} gitHubToken: ${{ secrets.GITHUB_TOKEN }} + - name: Comment preview URLs + if: >- + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository && + steps.preview.outcome == 'success' + uses: actions/github-script@v9 + env: + COMMIT_SHA: ${{ github.event.pull_request.head.sha }} + SNAPSHOT_URL: ${{ steps.preview.outputs.deployment-url }} + STABLE_URL: ${{ steps.preview.outputs.pages-deployment-alias-url }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const sha = process.env.COMMIT_SHA; + const snapshotUrl = process.env.SNAPSHOT_URL; + const stableUrl = process.env.STABLE_URL; + const shortSha = sha.slice(0, 7); + const commitUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/commit/${sha}`; + const body = [ + "## Cloudflare Pages preview", + "", + `- **Latest PR preview:** [${stableUrl}](${stableUrl})`, + `- **Snapshot for [\`${shortSha}\`](${commitUrl}):** [${snapshotUrl}](${snapshotUrl})`, + "", + "The PR URL always points to the latest deployment; the commit snapshot is immutable.", + ].join("\n"); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body, + }); diff --git a/README.md b/README.md index ca53564..be0db37 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ The Pages workflow deploys every push to `main` and can also be run manually fro ## Pull request previews -Pull requests opened from branches in this repository are deployed to an isolated Cloudflare Pages preview after CI succeeds. Each pull request receives a stable branch alias such as `https://pr-42.display-list-explorer.pages.dev`, while every update also creates an immutable deployment URL. GitHub attaches the resulting URL to the pull request as a deployment. +Pull requests opened from branches in this repository are deployed to an isolated Cloudflare Pages preview after CI succeeds. Each pull request receives a stable branch alias such as `https://pr-42.display-list-explorer.pages.dev`, while every update also creates an immutable deployment URL. GitHub attaches the resulting URL to the pull request as a deployment and posts both URLs in a commit-specific PR comment, preserving access to earlier snapshots as new commits are pushed. The workflow expects a `CLOUDFLARE_API_TOKEN` repository secret with Cloudflare Pages edit access and a `CLOUDFLARE_ACCOUNT_ID` repository variable. Pull requests from forks still run the converter and site build, but skip deployment because repository secrets are not exposed to fork workflows.