From 7ebd2a79ca18f0a24c3de31e0ed97499e65f041c Mon Sep 17 00:00:00 2001 From: Strokkur24 Date: Sun, 23 Nov 2025 12:54:45 +0100 Subject: [PATCH] ci: add diff link to this PR using the deployment URL --- .github/workflows/deploy-preview.yml | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c481b95..50287fd 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -28,6 +28,7 @@ jobs: run-id: ${{ github.event.workflow_run.id }} - name: "Deploy to Cloudflare Pages" uses: "AdrianGonz97/refined-cf-pages-action@v1" + id: "cloudflare-deploy" with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} @@ -35,3 +36,37 @@ jobs: projectName: "diffs" directory: ${{ steps.preview-build-artifact.outputs.download-path }}/web/.svelte-kit/cloudflare deploymentName: Preview + - name: "Comment self-diff preview link" + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + # language=typescript + script: | + const alias = '${{ steps.cloudflare-deploy.outputs.alias }}'; + const pr = '${{ github.repository }}/pull/${{ context.issue.number }}'; + const messageId = `self-diff-preview-link:comment:${context.repo.repo}`; + + const params = { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + per_page: 100 + }; + + const listComments = github.rest.issues.listComments; + let found: Awaited>['data'][number] | undefined; + + for await (const comments of github.paginate.iterator(listComments, params)) { + found = comments.data.find(({body}) => body?.includes(``)); + if (found) break; + } + + if (!found) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: ` + [Click here](${alias}?github_url=${encodeURIComponent(pr)}) to view this PR's diff using the preview of this PR!` + }); + }