-
Notifications
You must be signed in to change notification settings - Fork 34
191 lines (168 loc) · 5.83 KB
/
frontend.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
# for comment on PR, follow instruction for: https://github.com/marketplace/actions/sticky-pull-request-comment
name: PRISM CI - Frontend
on:
# Run on all pull requests and on pushes to master.
pull_request:
push:
branches:
- master
jobs:
frontend_tests:
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
name: frontend_tests
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-2024-2-${{ hashFiles('**/frontend/yarn.lock') }}-${{ hashFiles('**/common/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-2024-2
- name: Install dependencies if needed.
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
cd frontend
yarn install --frozen-lockfile --network-timeout 100000
yarn setup:common
- name: Lint
run: cd frontend && yarn lint
- name: Test
run: cd frontend && yarn test
- name: JSON check
run: cd frontend && yarn prettier:json-check
- name: Layer availability check
if: matrix.os == 'ubuntu-latest'
run: |
cd frontend && yarn preprocess-layers
DIFF=$(git diff --name-only)
if [ "$DIFF" != "" ]; then
echo "Files have changed. Make sure to run yarn preprocess-layers and commit changes."
echo "$DIFF"
exit 1
fi
- name: Check boundary keys
run: cd frontend && yarn check-boundary-keys
- name: Build
run: cd frontend && yarn build
frontend_build_and_deploy:
needs: frontend_tests
if: github.event_name == 'pull_request'
name: frontend_build_and_deploy
runs-on: ubuntu-latest
env:
surge_url: prism-${{ github.event.pull_request.number }}.surge.sh
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-2024-${{ hashFiles('**/frontend/yarn.lock') }}-${{ hashFiles('**/common/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-2024
- name: Install dependencies if needed.
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
cd frontend
yarn install --frozen-lockfile
yarn setup:common
- name: Find country variable
id: country_regex
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.event.pull_request.title }}
regex: 'COUNTRY=(\w+)'
- name: Echo country variable
run: echo "Country env is ${{ steps.country_regex.outputs.group1 }}"
- name: build frontend
run: |
cd frontend
GENERATE_SOURCEMAP=false REACT_APP_COUNTRY=${{ steps.country_regex.outputs.group1 || 'mozambique'}} yarn build
- name: Deploy on surge
uses: dswistowski/surge-sh-action@v1
with:
domain: ${{ env.surge_url }}
project: "frontend/build/."
login: ${{ secrets.surge_login }}
token: ${{ secrets.surge_token }}
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H:%M:%S')"
- name: Comment PR
uses: marocchino/sticky-pull-request-comment@v1
continue-on-error: true
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: |
Build succeeded and deployed at https://${{ env.surge_url }}
(hash ${{ github.event.pull_request.head.sha }} deployed at ${{ steps.date.outputs.date }})
master_frontend_build_and_deploy:
needs: frontend_tests
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
name: master_frontend_build_and_deploy
runs-on: ubuntu-latest
strategy:
matrix:
country: [mozambique, cambodia, rbd]
env:
REACT_APP_SENTRY_URL: ${{ secrets.REACT_APP_SENTRY_URL }}
surge_url: prism-master-${{ matrix.country }}.surge.sh
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: |
**/node_modules
**/.eslintcache
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/frontend/yarn.lock') }}-${{ hashFiles('**/common/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies if needed.
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
cd frontend
yarn install --frozen-lockfile
yarn setup:common
- name: build frontend
run: |
cd frontend
GENERATE_SOURCEMAP=false REACT_APP_COUNTRY=${{ matrix.country }} yarn build
- name: Deploy on surge
uses: dswistowski/surge-sh-action@v1
with:
domain: ${{ env.surge_url }}
project: "frontend/build/."
login: ${{ secrets.surge_login }}
token: ${{ secrets.surge_token }}