-
Notifications
You must be signed in to change notification settings - Fork 163
77 lines (66 loc) · 2.68 KB
/
preview-cloudformation-deploy.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
name: Deploy CloudFormation Stack for Preview Branch
on:
pull_request:
types: [opened, reopened]
concurrency:
group: pr-${{ github.event.pull_request.number }}-deploy-cloudformation
jobs:
deploy_cloudformation:
permissions:
contents: read
id-token: write
runs-on: blacksmith-2vcpu-ubuntu-2204
env:
STACK_NAME: preview-pr-${{ github.event.pull_request.number }}
STACK_PARAMS: >-
ParameterKey=LicenseKey,ParameterValue=5a32bd8a-409e-4733-8846-1868c568a813
ParameterKey=ImageTag,ParameterValue=pr-${{ github.event.pull_request.number }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Deploy CloudFormation Stack
run: |
# Check if stack exists
if aws cloudformation describe-stacks --stack-name $STACK_NAME 2>/dev/null; then
# Update existing stack
aws cloudformation update-stack \
--stack-name $STACK_NAME \
--template-body file://infra/aws-cloudformation/preview.yml \
--parameters $STACK_PARAMS \
--capabilities CAPABILITY_IAM \
--no-fail-on-empty-changeset
else
# Create new stack
aws cloudformation create-stack \
--stack-name $STACK_NAME \
--template-body file://infra/aws-cloudformation/preview.yml \
--parameters $STACK_PARAMS \
--capabilities CAPABILITY_IAM
# Wait for stack creation to complete
aws cloudformation wait stack-create-complete --stack-name $STACK_NAME
fi
- name: Get Stack Outputs
id: stack-output
run: |
DOMAIN=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].Outputs[?OutputKey==`DomainRecord`].OutputValue' \
--output text)
echo "PREVIEW_URL=https://$DOMAIN" >> $GITHUB_OUTPUT
- name: Comment Preview URL
uses: actions/github-script@v7
with:
script: |
const previewUrl = '${{ steps.stack-output.outputs.PREVIEW_URL }}';
const message = `Preview URL: ${previewUrl}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.name,
body: message
});