Skip to content

Commit 3ed2aca

Browse files
authored
fix: cleanup cf worker (#1066)
1 parent 5497e70 commit 3ed2aca

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

.github/workflows/cloudflare-cleanup.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,35 @@ jobs:
1111
permissions:
1212
pull-requests: write
1313
steps:
14-
- name: Checkout
15-
uses: actions/checkout@v5
16-
17-
- name: Set up node
18-
uses: actions/setup-node@v6
19-
with:
20-
node-version: 22
21-
22-
- name: Setup pnpm
23-
uses: pnpm/action-setup@v4
24-
with:
25-
version: 10
26-
27-
- name: Install wrangler globally
28-
run: pnpm add -g wrangler
29-
3014
- name: Delete preview deployment
3115
id: delete
3216
continue-on-error: true
3317
run: |
34-
echo "Attempting to delete md-pr-${{ github.event.pull_request.number }}"
35-
wrangler delete md-pr-${{ github.event.pull_request.number }} --force
36-
env:
37-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
38-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
18+
WORKER_NAME="md-pr-${{ github.event.pull_request.number }}"
19+
echo "Attempting to delete $WORKER_NAME"
20+
RESPONSE=$(curl -s -X DELETE \
21+
"https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/workers/scripts/$WORKER_NAME" \
22+
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
23+
-H "Content-Type: application/json")
24+
25+
echo "API Response: $RESPONSE"
26+
27+
if echo "$RESPONSE" | grep -q '"success":true'; then
28+
echo "Successfully deleted $WORKER_NAME"
29+
echo "status=success" >> $GITHUB_OUTPUT
30+
else
31+
echo "Failed to delete $WORKER_NAME or worker doesn't exist"
32+
echo "status=failed" >> $GITHUB_OUTPUT
33+
fi
3934
4035
- name: Comment on PR
41-
if: steps.delete.outcome == 'success'
36+
if: steps.delete.outputs.status == 'success'
4237
uses: actions/github-script@v7
4338
with:
4439
github-token: ${{ secrets.GITHUB_TOKEN }}
4540
script: |
4641
const prNumber = context.issue.number;
47-
42+
4843
await github.rest.issues.createComment({
4944
owner: context.repo.owner,
5045
repo: context.repo.repo,

0 commit comments

Comments
 (0)