-
Notifications
You must be signed in to change notification settings - Fork 2
26 lines (25 loc) · 1.3 KB
/
ci-cleanup.yml
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
name: CI Cleanup
on:
delete:
jobs:
cleanup:
runs-on: ubuntu-20.04
steps:
- name: Extract Branch Name
id: extract-branch
run: |
echo BRANCH_NAME=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | perl -pe 's/\W/-/g and s/-+$//g') >> $GITHUB_OUTPUT
- name: Check If DNS Record Exists
id: cloudflare-dns-check
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records?name=${{steps.extract-branch.outputs.BRANCH_NAME}}.${{secrets.FPJS_CI_DOMAIN}}&tags=owner:akamai-integration-ci'
method: 'GET'
customHeaders: '{"X-Auth-Email": "${{ secrets.CF_AUTH_EMAIL }}", "Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
- name: Delete Cloudflare DNS Record
if: ${{ fromJson(steps.cloudflare-dns-check.outputs.response).result_info.total_count < 1 }}
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records/${{ fromJson(steps.cloudflare-dns-check.outputs.response).result[0].id }}'
method: 'DELETE'
customHeaders: '{"X-Auth-Email": "${{ secrets.CF_AUTH_EMAIL }}", "Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'