Skip to content

Commit 4680db1

Browse files
committed
ci: delete SSL certs upon PR close
1 parent 2924c69 commit 4680db1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.github/workflows/clean.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ jobs:
2222
env:
2323
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
2424
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
25+
ZONE_ID: ${{ secrets.ZONE_ID }}
26+
AUTH_KEY: ${{ secrets.AUTH_KEY }}
27+
AUTH_EMAIL: ${{ secrets.AUTH_EMAIL }}
2528
run: |
2629
echo 'Perform service deployment for feature'
2730
nix develop .#ci --command bash -c $'
2831
wrangler delete --name "polykey-docs-dev-$GITHUB_HEAD_REF" --force
32+
DOMAIN="$GITHUB_HEAD_REF.dev.polykey.com/docs" ./scripts/ssl.sh
2933
'

scripts/ssl.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#/bin/sh
2+
3+
response=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/ssl/certificate_packs" \
4+
-H "Content-Type: application/json" \
5+
-H "X-Auth-Key: $AUTH_KEY" \
6+
-H "X-Auth-Email: $AUTH_EMAIL")
7+
8+
cert_ids=$(echo "$response" | jq -r --arg domain "$DOMAIN" '.result[] | select(.hosts[] | contains($domain)) | .id')
9+
10+
echo "$cert_ids" | while read -r cert_id; do
11+
curl -X DELETE --url "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/ssl/certificate_packs/$cert_id" \
12+
-H "Content-Type: application/json" \
13+
-H "X-Auth-Key: $AUTH_KEY" \
14+
-H "X-Auth-Email: $AUTH_EMAIL"
15+
done

0 commit comments

Comments
 (0)