-
Notifications
You must be signed in to change notification settings - Fork 1
101 lines (90 loc) · 4.05 KB
/
pr-closed.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Cleanup Merged PR
on:
pull_request:
types:
- closed
branches:
- main
workflow_dispatch:
# Limit concurrency to 1, with queueing, per workflow
# Limit concurrency to 1, with queueing, per workflow per PR
concurrency:
group: build-${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: false
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
NODE_ENV: prod
AWS_REGION: us-east-2
jobs:
cleanup-pr:
if: github.actor != 'dependabot[bot]'
environment:
name: ghpublic
strategy:
matrix:
deployName:
- microapps-core
- microapps-basic
- microapps-basic-prefix
name: deploy-${{ matrix.deployName }}
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
#
# Cleanup the Lambda Resource Policy allowing Child Deployer
# to invoke the Parent Deployer, when applicable
#
- name: Change to Parent Account
if: ${{ matrix.deployName == 'microapps-core' }}
uses: aws-actions/configure-aws-credentials@v2
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Destroy Parent Privilege CDK Stack for Child Deploy
if: ${{ matrix.deployName == 'microapps-core' }}
run: |
aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghchild-priv-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghchild-priv-${NODE_ENV}-pr-${PR_NUMBER}"
#
# Cleanup the Child Deployer, when applicable
#
- name: Change to Child Account
if: ${{ matrix.deployName == 'microapps-core' }}
uses: aws-actions/configure-aws-credentials@v2
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID_CHILD }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Destroy Child CDK Stack
if: ${{ matrix.deployName == 'microapps-core' }}
run: |
aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghchild-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghchild-${NODE_ENV}-pr-${PR_NUMBER}"
#
# Cleanup the Lambda Resource Policy allowing Child Deployer
# to invoke the Parent Deployer, when applicable
#
- name: Change to Parent Account
uses: aws-actions/configure-aws-credentials@v2
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}
- name: Destroy Parent CDK Stack
run: |
aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
# TODO - Need to get the stack name from the parent stack export
# - name: Destroy Parent Edge to Origin Stack
# run: |
# aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
# aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
# Example:
# microapps-core-ghpublic-prod-pr-303-edge-role
# - name: Destroy Parent Edge to Origin Stack
# run: |
# aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}-edge-role"
# aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}-edge-role"