-
Notifications
You must be signed in to change notification settings - Fork 1
239 lines (202 loc) · 6.91 KB
/
Copy pathdevelopment.yml
File metadata and controls
239 lines (202 loc) · 6.91 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Development CI/CD
on:
push:
branches: [master]
pull_request: {}
env:
ARTIFACT_NAME: ${{ github.sha }}.zip
ARTIFACT_BUCKET: email-footer-template-development-app-builds
DEPLOY_BUCKET: email-footer-template-app
DEPLOY_URL: https://duuaiv9oid06y.cloudfront.net
TF_WORKSPACE: development
TF_INPUT: "0"
TF_IN_AUTOMATION: "1"
STATE_BUCKET: footer-template-development-state
defaults:
run:
working-directory: ./web
jobs:
lint:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache .npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('./package-lock.json') }}
restore-keys: ${{ runner.os }}-npm
- name: Setup Node.js 14
uses: actions/setup-node@v4
with:
node-version: "14"
- name: Install dependencies
run: npm ci
- name: Audit dependencies
run: npm run --silent audit
- name: ESLint
run: npm run --silent lint:eslint
- name: TypeScript
run: npm run --silent tsc
test:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache .npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('./package-lock.json') }}
restore-keys: ${{ runner.os }}-npm
- name: Setup Node.js 14
uses: actions/setup-node@v1
with:
node-version: "14"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run --silent test -- --passWithNoTests
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache .npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('./package-lock.json') }}
restore-keys: ${{ runner.os }}-npm
- name: Setup Node.js 14
uses: actions/setup-node@v1
with:
node-version: "14"
- name: Install dependencies
run: npm ci
- name: Cache node_modules/.cache
uses: actions/cache@v4
with:
path: ./node_modules/.cache
key: ${{ runner.os }}-build-cache
- name: Build app
run: npm run --silent build
env:
REACT_APP_API_URL: https://ucj9mv5eyg.execute-api.eu-central-1.amazonaws.com/dev/
REACT_APP_BASENAME: ${{ github.event_name == 'pull_request' && format('/PR-{0}', github.event.number) || '' }}
PUBLIC_URL: ${{ github.event_name == 'pull_request' && format('/PR-{0}', github.event.number) || '' }}
- name: Save build artifact
uses: actions/upload-artifact@v4
with:
path: web/build
name: build.zip
retention-days: 1
# terraform_lint:
# name: lint infrastructure
# runs-on: ubuntu-20.04
# defaults:
# run:
# working-directory: ./infrastructure
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Install terraform 1.0.0
# uses: hashicorp/setup-terraform@v1
# with:
# terraform_version: 1.0.0
# - name: terraform fmt
# run: terraform fmt -check -diff
# - name: Install terraform plugins and modules
# run: terraform init -backend=false
# - name: terraform validate
# run: terraform validate
deploy:
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
needs: [build]
steps:
- name: Checkout code
uses: actions/checkout@v4
# - name: Install terraform 1.0.0
# uses: hashicorp/setup-terraform@v1
# with:
# terraform_version: 1.0.0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.DEVELOPMENT_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEVELOPMENT_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build.zip
path: web/build
- name: Setup development environment
run: |
cat >>$GITHUB_ENV <<EOF
DEPLOY_BUCKET_PATH=$DEPLOY_BUCKET
EOF
- name: Setup preview environment
if: github.event_name == 'pull_request'
run: |
cat >>$GITHUB_ENV <<EOF
BASE_HREF=/PR-${{ github.event.number }}/
DEPLOY_BUCKET_PATH=${DEPLOY_BUCKET_PATH}/PR-${{ github.event.number }}
DEPLOY_URL=${DEPLOY_URL}/PR-${{ github.event.number }}
EOF
# - name: Initialize terraform
# working-directory: ./infrastructure
# run: |
# terraform init \
# -backend-config="bucket=$STATE_BUCKET" \
# -backend-config="dynamodb_table=$STATE_BUCKET-lock"
# - name: Plan infrastructure changes
# working-directory: ./infrastructure
# run: |
# mkdir -p plan
# terraform plan -out plan/tfplan
# - name: Apply infrastructure changes
# if: github.event_name != 'pull_request'
# working-directory: ./infrastructure
# run: terraform apply -auto-approve plan/tfplan
- name: Push build to S3
run: |
aws s3 sync \
build/static s3://${DEPLOY_BUCKET_PATH}/static/ \
--cache-control 'public,max-age=31536000'
aws s3 sync \
build s3://${DEPLOY_BUCKET_PATH}/ \
--exclude '*' \
--include 'favicon.ico' \
--include 'manifest.json' \
--cache-control 'public,max-age=3600'
aws s3 sync \
build s3://${DEPLOY_BUCKET_PATH}/ \
--exclude 'static/*' \
--exclude 'favicon.ico' \
--exclude 'manifest.json' \
--cache-control 'public,no-cache,no-store,must-revalidate'
- name: Post a link to the preview environment
if: github.event_name == 'pull_request'
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const {
issue: { number: issue_number },
repo: { owner, repo }
} = context
const body = `Preview deployed to ${ process.env.DEPLOY_URL }`
const commentsResponses = github.paginate.iterator(
github.issues.listComments,
{ owner, repo, issue_number }
)
for await (const commentsResponse of commentsResponses) {
const existingComment = commentsResponse.data.find(
comment => comment.body === body
)
if (existingComment) return
}
github.issues.createComment({ owner, repo, issue_number, body });