Deleting the temporary site upon branch deletion #12
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: Deleting the temporary site upon branch deletion | |
on: | |
delete: | |
workflow_dispatch: | |
jobs: | |
build: | |
if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'feature-') }} | |
runs-on: ubuntu-latest | |
environment: github-pages | |
steps: | |
- name: Installing dependencies | |
run: sudo apt-get install -y jq | |
- name: Getting the temporary CNAME record ID from the Repo and deleting it from Cloudflare | |
run: | | |
export CNAME_ID=$(curl -L \ | |
-H 'Accept: application/vnd.github+json' \ | |
-H 'Authorization: Bearer ${{ secrets.GENERATE_TEMPORARY_BRANCH_WEBSITE }}' \ | |
-H 'X-GitHub-Api-Version: 2022-11-28' \ | |
https://api.github.com/repos/Temporary-Feature-Branch/${{ github.ref_name }}-Simple | jq '.description') | |
export CNAME_ID=$(echo $CNAME_ID | tr -d '"') | |
curl --request DELETE \ | |
--url https://api.cloudflare.com/client/v4/zones/${{ secrets.CNAME_ZONE_ID }}/dns_records/$CNAME_ID \ | |
--header 'Content-Type: application/json' \ | |
--header 'X-Auth-Email: [email protected]' \ | |
--header 'X-Auth-Key: ${{ secrets.CNAME_API_KEY }}' | |
- name: Deleting the temporary GitHub repository | |
run: | | |
curl -L \ | |
-X DELETE \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GENERATE_TEMPORARY_BRANCH_WEBSITE }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/Temporary-Feature-Branch/${{ github.ref_name }}-Simple |