-
Notifications
You must be signed in to change notification settings - Fork 100
57 lines (49 loc) · 1.8 KB
/
Copy pathpreview-cleanup.yml
File metadata and controls
57 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Preview Cleanup
on:
pull_request:
types: [closed]
jobs:
cleanup-preview:
name: Remove preview (PR #${{ github.event.pull_request.number }})
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
deployments: write
steps:
- uses: actions/checkout@v4
- name: Delete Cloudflare Pages deployment
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deployment delete --project-name=notify-chain-dashboard --branch=pr-${{ github.event.pull_request.number }} --yes
- name: Update PR comment to mark preview removed
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(process.env.PR_NUMBER),
});
const marker = '<!-- notify-chain-preview-bot -->';
const existing = comments.find(c => c.body.includes(marker));
if (!existing) return;
const reason = context.payload.pull_request.merged ? 'merged' : 'closed';
const body = [
marker,
'## 🚀 Preview Deployment',
'',
`| | |`,
`|---|---|`,
`| **Status** | 🗑️ Removed (PR ${reason}) |`,
].join('\n');
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});