-
Notifications
You must be signed in to change notification settings - Fork 0
48 lines (42 loc) · 1.62 KB
/
cloudflare-preview-cleanup.yml
File metadata and controls
48 lines (42 loc) · 1.62 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
name: Cleanup Cloudflare Preview
on:
pull_request:
types: [closed]
jobs:
cleanup-preview:
runs-on: ubuntu-latest
if: github.repository == 'doocs/md'
permissions:
pull-requests: write
steps:
- name: Delete preview deployment
id: delete
continue-on-error: true
run: |
WORKER_NAME="md-pr-${{ github.event.pull_request.number }}"
echo "Attempting to delete $WORKER_NAME"
RESPONSE=$(curl -s -X DELETE \
"https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/workers/scripts/$WORKER_NAME" \
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
-H "Content-Type: application/json")
echo "API Response: $RESPONSE"
if echo "$RESPONSE" | jq -e '.success == true' > /dev/null 2>&1; then
echo "Successfully deleted $WORKER_NAME"
echo "status=success" >> $GITHUB_OUTPUT
else
echo "Failed to delete $WORKER_NAME or worker doesn't exist"
echo "status=failed" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
if: steps.delete.outputs.status == 'success'
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.issue.number;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: '🗑️ Cloudflare Workers preview deployment has been cleaned up.'
});