-
Notifications
You must be signed in to change notification settings - Fork 191
214 lines (176 loc) · 5.66 KB
/
test-and-ship.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
209
210
211
212
213
214
name: Test & Ship
on:
- push
- pull_request
env:
CYPRESS_PROJECT_ID: "itz63b"
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
continue-on-error: false
strategy:
matrix:
node_version:
- 8.x
- 10.x
- 12.x
include:
- node_version: 8.x
run_lint_tests: "True"
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}
- name: Get npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v1
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: |
set -e;
npm install -g gulp;
npm run install:all;
- name: List installed dependencies
run: |
npm ls || true;
- name: Run lint tests
if: ${{ matrix.run_lint_tests }}
run: |
cd legacy ;
TEST_SUITE="lint" test/test.sh ;
- name: Run tests
run: |
npm run test;
e2e-run:
if: github.event_name == 'push' # not on fork PRs
continue-on-error: true # while tests stabilizing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: ushahidi/platform-e2e-testing
ref: main
path: e2e-testing/
## set up API endpoint
- name: Setup API endpoint
run: |
echo 'BACKEND_URL=https://master-api.staging.ush.zone' > .env
## same as above step
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Get npm cache directory
id: npm-cache
run: |
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v1
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: |
set -e;
npm install -g gulp;
npm run install:all;
- name: Run server
run: |
npm run serve &
- name: Wait until all modules are being served
run: |
retry() {
local -r -i max_attempts="$1"; shift
local -r cmd="$@"
local -i attempt_num=1
until $cmd
do
if (( attempt_num == max_attempts ))
then
echo "Attempt $attempt_num failed and there are no more attempts left!"
return 1
else
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $(( attempt_num++ ))
fi
done;
}
server='http://localhost:3000'
retry 60 timeout 1 curl --silent ${server}/importmap.json || { echo "Failed getting importmap!" && exit 1; }
for js in $(curl --silent ${server}/importmap.json | jq -r '.imports | .[]'); do
retry 60 timeout 1 curl --silent ${server}${js} || { echo "Failed waiting for module ${js}" && exit 1; }
done
- name: Patch cypress config
run: |
cd e2e-testing
jq '.projectId="'${CYPRESS_PROJECT_ID}'"' <<<$(cat cypress.json) > cypress.json
jq '.baseUrl="http://localhost:3000/"' <<<$(cat cypress.env.json) > cypress.env.json
- name: Cypress run
uses: cypress-io/github-action@v2
with:
browser: chrome
install-command: npm install
record: true
parallel: true
working-directory: e2e-testing
env:
CYPRESS_ush_admin_email: "${{secrets.e2e_ush_admin_email}}"
CYPRESS_ush_admin_pwd: "${{secrets.e2e_ush_admin_pwd}}"
CYPRESS_ush_user_name: "${{secrets.e2e_ush_user_name}}"
CYPRESS_ush_user_email: "${{secrets.e2e_ush_user_email}}"
CYPRESS_ush_user_pwd: "${{secrets.e2e_ush_user_pwd}}"
CYPRESS_RECORD_KEY: ${{ secrets.E2E_CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ship:
needs: [ test, e2e-run ]
if: github.event_name == 'push' # not PRs
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Login to AWS Container Registry
uses: docker/login-action@v1
with:
registry: 513259414768.dkr.ecr.eu-west-1.amazonaws.com
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
513259414768.dkr.ecr.eu-west-1.amazonaws.com/platform-client
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha
- name: Build and push to Amazon ECR
uses: docker/build-push-action@v2
with:
pull: true
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Logout from Amazon ECR
if: always()
run: docker logout ${{ steps.login-ecr.outputs.registry }}