Skip to content

Commit 7ebd2a7

Browse files
committed
ci: add diff link to this PR using the deployment URL
1 parent dd93e61 commit 7ebd2a7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

.github/workflows/deploy-preview.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,45 @@ jobs:
2828
run-id: ${{ github.event.workflow_run.id }}
2929
- name: "Deploy to Cloudflare Pages"
3030
uses: "AdrianGonz97/refined-cf-pages-action@v1"
31+
id: "cloudflare-deploy"
3132
with:
3233
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
3334
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
3435
githubToken: ${{ secrets.GITHUB_TOKEN }}
3536
projectName: "diffs"
3637
directory: ${{ steps.preview-build-artifact.outputs.download-path }}/web/.svelte-kit/cloudflare
3738
deploymentName: Preview
39+
- name: "Comment self-diff preview link"
40+
uses: actions/github-script@v7
41+
with:
42+
github-token: ${{ secrets.GITHUB_TOKEN }}
43+
# language=typescript
44+
script: |
45+
const alias = '${{ steps.cloudflare-deploy.outputs.alias }}';
46+
const pr = '${{ github.repository }}/pull/${{ context.issue.number }}';
47+
const messageId = `self-diff-preview-link:comment:${context.repo.repo}`;
48+
49+
const params = {
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
issue_number: context.issue.number,
53+
per_page: 100
54+
};
55+
56+
const listComments = github.rest.issues.listComments;
57+
let found: Awaited<ReturnType<typeof listComments>>['data'][number] | undefined;
58+
59+
for await (const comments of github.paginate.iterator(listComments, params)) {
60+
found = comments.data.find(({body}) => body?.includes(`<!-- ${messageId} -->`));
61+
if (found) break;
62+
}
63+
64+
if (!found) {
65+
github.rest.issues.createComment({
66+
issue_number: context.issue.number,
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
body: `<!-- ${messageId} -->
70+
[Click here](${alias}?github_url=${encodeURIComponent(pr)}) to view this PR's diff using the preview of this PR!`
71+
});
72+
}

0 commit comments

Comments
 (0)