Skip to content

Branch Cleanup

Branch Cleanup #6

name: Branch Cleanup
on:
delete:
branches:
# all branches created from issue
- "[0-9]+-**"
jobs:
cleanup:
name: Clean up S3
runs-on: ubuntu-latest
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
steps:
- name: Extract branch name
shell: bash
run: |
BRANCH=$(cat ${{ github.event_path }} | jq --raw-output '.ref')
echo "branch=${BRANCH#refs/heads/}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_CLI_ROLE_ARN }}
role-session-name: docs-site-template-branch-deploy
aws-region: ${{ env.AWS_REGION }}
- name: Remove from S3
uses: vitorsgomes/s3-rm-action@master
with:
args: --recursive
env:
AWS_S3_BUCKET: ${{ env.AWS_BUCKET_NAME }}
PATH_TO_DELETE: ${{ steps.extract_branch.outputs.branch }}
- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ env.AWS_DISTRIBUTION_ID }}
PATHS: "/${{ steps.extract_branch.outputs.branch }}/*"
- uses: strumwolf/delete-deployment-environment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: aws-development
ref: ${{ steps.extract_branch.outputs.branch }}
onlyDeactivateDeployments: true
- name: Output
run: |
echo "✔ Branch is successfully cleaned from AWS" >> $GITHUB_STEP_SUMMARY