-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (176 loc) · 6.63 KB
/
main.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
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
name: app-engine
env:
GCLOUD_PROJECT_ID: kvaapagarrot
NODE_ENV: production
on:
push:
branches:
- main-kampf
pull_request:
branches:
- main-kampf
types: [opened, synchronize, reopened]
jobs:
cancel-previous:
name: Cancel Previous Jobs
# Skip workflow entirely for [skip ci] commits
if: |
false == contains(github.event.commits[0].message, '[skip ci]') &&
false == contains(github.event.commits[0].message, '[no ci]')
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
lint:
name: Lint Code
# Skip workflow entirely for [skip ci] commits
if: |
false == contains(github.event.commits[0].message, '[skip ci]') &&
false == contains(github.event.commits[0].message, '[no ci]')
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
yarn-cache-dir: ${{ steps.yarn-cache-dir.outputs.dir }}
steps:
- name: Checkout
uses: actions/checkout@v2
# Preferable to use the same version as in GAE environment
- name: Set Node.js version
uses: actions/setup-node@v2
with:
node-version: '14.17.6'
- name: Get yarn cache directory path
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache yarn cache dir
uses: actions/[email protected]
with:
path: ${{ steps.yarn-cache-dir.outputs.dir }}
key: yarn-cache-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-cache-${{ runner.os }}-
yarn-cache-
- name: Cache node modules
uses: actions/[email protected]
with:
path: node_modules
key: node_modules-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
node_modules-${{ runner.os }}-
node_modules-
- name: Run linters
run: |
yarn install --production=false --frozen-lockfile --non-interactive
yarn lint
yarn slint
deploy-gae:
name: App Engine Deployment
environment: production
# Skip workflow entirely for [skip ci] commits
if: |
false == contains(github.event.commits[0].message, '[skip ci]') &&
false == contains(github.event.commits[0].message, '[no ci]')
runs-on: ubuntu-latest
needs: [lint]
# Map a step output to a job output
outputs:
version-url: ${{ steps.version-url.outputs.url }}
steps:
- name: Checkout
uses: actions/checkout@v2
# Preferable to use the same version as in GAE environment
- name: Set Node.js version
uses: actions/setup-node@v2
with:
node-version: '14.17.6'
- name: Cache yarn cache dir
uses: actions/[email protected]
with:
path: ${{needs.lint.outputs.yarn-cache-dir}}
key: yarn-cache-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-cache-${{ runner.os }}-
yarn-cache-
- name: Cache node modules
uses: actions/[email protected]
with:
path: node_modules
key: node_modules-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
node_modules-${{ runner.os }}-
node_modules-
- name: Build all
run: |
yarn install --production=false --frozen-lockfile --non-interactive
yarn build
rm public/dist/main.js
- name: Generate static route handlers
run: yarn static
- name: Save prod dependencies for GAE upload
run: |
yarn install --production=true --frozen-lockfile --non-interactive
tar -czf node_modules.tar.gz node_modules
ls -lah node_modules.tar.gz | awk '{print $5,$9}'
- name: Import Service Account key
run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}" | base64 -d > /tmp/auth.json
- name: GCloud Auth
run: |
gcloud --quiet auth \
activate-service-account "${{ secrets.GCP_SA_EMAIL }}" \
--key-file=/tmp/auth.json \
--project="${GCLOUD_PROJECT_ID}"
- name: Deploy
run: |
yarn deploy --no-promote --version "${GITHUB_ACTOR//[\[\]]/}-${GITHUB_SHA:0:7}"
- id: version-url
name: Get deployed app version URL
run: |
VERSION_URL=$(gcloud app versions describe "${GITHUB_ACTOR//[\[\]]/}-${GITHUB_SHA:0:7}" --service=default --format "value(versionUrl)")
echo $VERSION_URL
echo "::set-output name=url::$(echo $VERSION_URL)"
lighthouse:
name: Lighthouse Audit
environment: production
runs-on: ubuntu-latest
# Run only after successful deployment
needs: [deploy-gae]
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
LHCI_BUILD_CONTEXT__CURRENT_HASH: ${{ github.sha }}
steps:
- name: Set Lighthouse CI config
run: |
curl "https://raw.githubusercontent.com/irkfap/kvaapagarrot.com/${GITHUB_SHA}/lighthouserc.json" \
--silent --location --output "$GITHUB_WORKSPACE/lighthouserc.json"
- name: Warmup deployed instance
run: curl --silent --fail --head --write-out "%{http_code}" --request GET "${{needs.deploy-gae.outputs.version-url}}"
- name: Check static deployed
run: curl --silent --fail --include --request GET "${{needs.deploy-gae.outputs.version-url}}/robots.txt"
- name: Audit URLs using Lighthouse
uses: treosh/[email protected]
with:
urls: |
${{needs.deploy-gae.outputs.version-url}}
uploadArtifacts: true # save results as an action artifacts
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
configPath: ${{ github.workspace }}/lighthouserc.json
production:
name: Update Production
environment: production
runs-on: ubuntu-latest
# Run only after successful deployment and Lighthouse audit
needs: [deploy-gae, lighthouse]
# Run only on push to master
if: ${{ success() && github.ref == 'refs/heads/main-kampf' }}
steps:
- name: Import Service Account key
run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}" | base64 -d > /tmp/auth.json
- name: GCloud Auth
run: |
gcloud --quiet auth \
activate-service-account "${{ secrets.GCP_SA_EMAIL }}" \
--key-file=/tmp/auth.json \
--project="${GCLOUD_PROJECT_ID}"
- name: Promote deployed version to production
run: |
gcloud --quiet app versions migrate "${GITHUB_ACTOR//[\[\]]/}-${GITHUB_SHA:0:7}" --service=default