CI Cleanup #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}"}' |