-
Notifications
You must be signed in to change notification settings - Fork 11
120 lines (116 loc) · 4.41 KB
/
preview-deploy.yaml
File metadata and controls
120 lines (116 loc) · 4.41 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Preview
on:
pull_request:
branches:
- "*"
permissions:
id-token: write
contents: read
issues: write
pull-requests: write
env:
BUCKET_NAME: ds-preview-stac-map-${{ github.event.number }}
AWS_ROLE_ARN: arn:aws:iam::552819999234:role/stac-map-gh-preview
AWS_REGION: us-west-2
DIST_DIRECTORY: dist
jobs:
build:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version-file: ".node-version"
cache: "yarn"
- name: Post building comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { createDeployingComment } = require('./.github/workflows/github-pr-update.cjs')
await createDeployingComment({ github, context, core })
- name: Install
run: yarn install --ignore-engines
- name: Build
run: yarn build-preview
- name: Post error comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
if: failure()
with:
script: |
const { createFailedComment } = require('./.github/workflows/github-pr-update.cjs')
await createFailedComment({ github, context, core })
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
path: ${{ env.DIST_DIRECTORY }}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
path: ${{ env.DIST_DIRECTORY }}
- name: Check if bucket exists
id: check_bucket
run: |
if aws s3 ls "s3://${{ env.BUCKET_NAME }}" 2>&1 | grep -q 'NoSuchBucket'; then
echo "Bucket does not exist."
echo "exists=false" >> "$GITHUB_OUTPUT"
else
echo "Bucket exists."
echo "exists=true" >> "$GITHUB_OUTPUT"
fi
- name: Create S3 bucket
if: steps.check_bucket.outputs.exists == 'false'
run: |
aws s3 mb s3://${{ env.BUCKET_NAME }}
- name: Enable static website hosting
if: steps.check_bucket.outputs.exists == 'false'
run: |
aws s3 website \
s3://${{ env.BUCKET_NAME }} \
--index-document index.html \
--error-document index.html
- name: Sync files
run: |
aws s3 sync \
./${{env.DIST_DIRECTORY}} s3://${{ env.BUCKET_NAME }} \
--delete \
--quiet
- name: Make bucket public access
if: steps.check_bucket.outputs.exists == 'false'
run: |
aws s3api delete-public-access-block --bucket ${{ env.BUCKET_NAME }}
- name: Add bucket policy for public access
if: steps.check_bucket.outputs.exists == 'false'
run: |
echo '{
"Version": "2012-10-17",
"Statement": [{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${{ env.BUCKET_NAME }}/*"
}]
}' > bucket-policy.json
aws s3api put-bucket-policy --bucket ${{ env.BUCKET_NAME }} --policy file://bucket-policy.json
- name: Post comment with preview URL
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
if: success()
with:
script: |
const { createSuccessComment } = require('./.github/workflows/github-pr-update.cjs')
await createSuccessComment({ github, context, core })
- name: Post error comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
if: failure()
with:
script: |
const { createFailedComment } = require('./.github/workflows/github-pr-update.cjs')
await createFailedComment({ github, context, core })