-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
107 lines (89 loc) · 3.55 KB
/
action.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
102
103
104
105
106
107
name: Deploy Single Page Application on S3
description: Github Action to deploy s3 by sam
branding:
icon: upload-cloud
color: red
inputs:
BucketName:
description: S3 Bucket Name
required: true
SAMSourceBucket:
description: AWS S3 bucket where artifacts referenced in the template are uploaded.
required: false
SAMToken:
description: The GITHUB Authentication token to use for calling the GITHUB Get the latest release API. Defaults to call the API as unauthenticated request if not specified.
required: false
Aliases:
description: AWS::CloudFront::Distribution DistributionConfig Properties, To apply this property, you must also enter `AcmCertificateArn` and `HostedZoneId`.
required: false
AcmCertificateArn:
description: AWS::CloudFront::Distribution ViewerCertificate Properties, To apply this property, you must also enter `Aliases` and `HostedZoneId`.
required: false
HostedZoneId:
description: AWS::Route53::RecordSetGroup Properties, To apply this property, you must also enter `Aliases`, `AcmCertificateArn`.
required: false
outputs:
DistributionId:
description: "The distribution's identifier. For example: E1U5RQF7T870K0."
value: ${{ steps.output.outputs.DistributionId }}
DomainName:
description: The domain name of the resource
value: ${{ steps.output.outputs.DomainName }}
runs:
using: composite
steps:
- shell: bash
run: aws sts get-caller-identity >/dev/null 2>&1
- shell: bash
id: path
run: echo "path=$GITHUB_ACTION_PATH" >> "$GITHUB_OUTPUT"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
token: ${{ inputs.SAMToken }}
- shell: bash
run: |
BUCKET=$(echo ${{ inputs.BucketName }} | tr '.' '-')
cat <<EOF > config.toml
version = 0.1
[default.build.parameters]
cached = true
parallel = true
[default.validate.parameters]
lint = true
[default.deploy.parameters]
capabilities = "CAPABILITY_IAM"
confirm_changeset = false
resolve_s3 = true
stack_name = "S3SPA-$BUCKET"
s3_prefix = "S3SPA-$BUCKET"
[default.package.parameters]
resolve_s3 = true
EOF
- uses: actions/setup-node@main
with:
node-version: 20
- shell: bash
run: node ${{ steps.path.outputs.path }}/index.js
env:
BucketName: ${{ inputs.BucketName }}
Aliases: ${{ inputs.Aliases }}
AcmCertificateArn: ${{ inputs.AcmCertificateArn }}
HostedZoneId: ${{ inputs.HostedZoneId }}
- shell: bash
run: |
sam build --config-file config.toml
sam validate --config-file config.toml
if [ -n "${{ inputs.SAMSourceBucket }}" ]; then
sam deploy --no-fail-on-empty-changeset --s3-bucket ${{ inputs.SAMSourceBucket }} --config-file config.toml --resolve-image-repos
else
sam deploy --no-fail-on-empty-changeset --config-file config.toml --resolve-image-repos
fi
- shell: bash
id: output
run: |
BUCKET=$(echo ${{ inputs.BucketName }} | tr '.' '-')
DistributionId=$(aws cloudformation describe-stacks --stack-name "S3SPA-$BUCKET" --query "Stacks[0].Outputs[?OutputKey=='DistributionId'].OutputValue" --output text)
DomainName=$(aws cloudformation describe-stacks --stack-name "S3SPA-$BUCKET" --query "Stacks[0].Outputs[?OutputKey=='DomainName'].OutputValue" --output text)
echo "DistributionId=$DistributionId" >> "$GITHUB_OUTPUT"
echo "DomainName=$DomainName" >> "$GITHUB_OUTPUT"