-
Notifications
You must be signed in to change notification settings - Fork 87
56 lines (52 loc) · 1.81 KB
/
delete-test-app.yaml
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
on:
pull_request:
types:
- unlabeled
- closed
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
remove-test:
if: contains(github.event.label.name, 'testing') || contains(github.event.pull_request.labels.*.name, 'testing')
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Delete Cloudflare Page
steps:
- name: Set Project Name
run: |
export NAME=$(echo ${{ env.BRANCH_NAME }} | tr -d -c '[:alnum:]' | tr '[:upper:]' '[:lower:]')
echo "PROJECT_NAME=widget-${NAME:0:10}" >> $GITHUB_ENV
- name: Delete project if present
uses: actions/github-script@v7
with:
script: |
fetch('https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects/${{ env.PROJECT_NAME }}', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${{ secrets.CF_PAGES_API_TOKEN }}'
},
})
.then(r => r.json())
.then(r => {
if (!r || !r.success || !r.result) {
console.log(r)
process.exit(1)
}
fetch('https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects/${{ env.PROJECT_NAME }}', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${{ secrets.CF_PAGES_API_TOKEN }}'
},
})
.then(r => r.json())
.then(r => {
if (!r?.success) {
console.log(r)
process.exit(1)
}
})
})