-
Notifications
You must be signed in to change notification settings - Fork 8
47 lines (42 loc) · 1.31 KB
/
destroy.branch.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: Destroy temporary instance
on:
delete:
branches:
- feat/**
- feature/**
- fix/**
- hotfix/**
- docs/**
- style/**
- refactor/**
- perf/**
- test/**
- build/**
- ci/**
- chore/**
- revert/**
env:
AWS_ACCESS_KEY_ID: ${{ secrets.HYPHA_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.HYPHA_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: eu-west-1
NODE_ENV: development
jobs:
remove_bucket_and_distribution:
runs-on: ubuntu-latest
steps:
- name: Generate branch name
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Checkout Repository
uses: actions/checkout@v3
- name: Delete CloudFront Distribution
if: github.event.pull_request.merged == true
run: |
DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items[0]=='${{ env.BRANCH_NAME }}'].Id" --output text)
if [ ! -z "$DISTRIBUTION_ID" ]
then
aws cloudfront delete-distribution --id $DISTRIBUTION_ID
fi
- name: Delete S3 Bucket
if: github.event.pull_request.merged == true
run: |
aws s3api delete-bucket --bucket ${{ env.BRANCH_NAME }} --region ${{ secrets.AWS_REGION }}