-
Notifications
You must be signed in to change notification settings - Fork 2
271 lines (220 loc) · 9.53 KB
/
integration-tester.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
name: Integration Tester
# This workflow is automatically synchronized to this file from the integration tester repository. Any local changes will be overwritten.
on:
push:
pull_request:
schedule:
- cron: "0 9 * * 0-6"
workflow_dispatch:
jobs:
cancel_if_duplicate:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
sandbox_tests_exist:
timeout-minutes: 10
runs-on: ubuntu-latest
needs: cancel_if_duplicate
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Read Test Config
run: echo "TEST_CONFIG_RUN=$(cat .github/workflows/integration-tests/generated/tests-config.json | jq '.run')" >> $GITHUB_ENV
#fails if no custom tests present
- name: check for custom tests if no sync tests added
if: ${{env.TEST_CONFIG_RUN=='none'}}
run: test -f .github/workflows/integration-tests/custom/**sandbox-test.js || exit 1
- name: Notify
uses: homoluctus/slatify@master
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && failure()
with:
type: ${{ job.status }}
job_name: "*No Sandbox Tests Found*"
url: ${{ secrets.BX_SLACK_BX_CHANNEL }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
staging_tests_exist:
timeout-minutes: 10
runs-on: ubuntu-latest
needs: cancel_if_duplicate
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Read Test Config
run: echo "TEST_CONFIG_RUN=$(cat .github/workflows/integration-tests/generated/tests-config.json | jq '.run')" >> $GITHUB_ENV
#fails if no custom tests present
- name: check for custom tests if no sync tests added
if: ${{env.TEST_CONFIG_RUN=='none'}}
run: test -f .github/workflows/integration-tests/custom/**staging-test.js || exit 1
- name: Notify
uses: homoluctus/slatify@master
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && failure()
with:
type: ${{ job.status }}
job_name: "*No Staging Tests Found*"
url: ${{ secrets.BX_SLACK_BX_CHANNEL }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
sandbox_tests:
timeout-minutes: 30
needs: sandbox_tests_exist
runs-on: ubuntu-latest
env:
#below sets default to true and will confirm later in workflow
HAS_CUSTOM_TESTS: true
strategy:
matrix:
node-version: [14.x]
os: [windows-latest, ubuntu-latest, macOS-latest]
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Env
run: |
echo "Event name: ${{ github.event_name }}"
echo "Git ref: ${{ github.ref }}"
echo "GH actor: ${{ github.actor }}"
echo "SHA: ${{ github.sha }}"
VER=`node --version`; echo "Node ver: $VER"
VER=`npm --version`; echo "npm ver: $VER"
- name: Look for needed runtimes
run: echo "CONFIG_RUNTIMES=$(cat .github/workflows/integration-tests/generated/runtime-config.json | jq '.runtime')" >> $GITHUB_ENV
- name: Add Deno if needed
#TODO: double quotes should be fixed in the check for this variable.
if: ${{env.CONFIG_RUNTIMES == '"deno"'}}
uses: denoland/setup-deno@main
with:
deno-version: v1.x
- name: Install
run: npm install
- name: Install Architect
run: npm i @architect/architect
- name: Install Test Dependencies
run: npm i tape tap-spec tiny-json-http
- name: Build if needed
run: npm run build --if-present
- name: Read Test Config
run: echo "TEST_CONFIG_RUN=$(cat .github/workflows/integration-tests/generated/tests-config.json | jq '.run')" >> $GITHUB_ENV
- name: Check for custom tests
run: test -f .github/workflows/integration-tests/custom/**sandbox-test.js || echo "HAS_CUSTOM_TESTS=false" >> $GITHUB_ENV
- name: Run Custom Sandbox Tests
if: ${{env.HAS_CUSTOM_TESTS == true}}
run: QUIET=1 npx tape .github/workflows/integration-tests/custom/**sandbox-test.js | npx tap-spec
- name: Run Basic Tests
#TODO: double quotes should be fixed in the check for this variable.
if: ${{env.TEST_CONFIG_RUN == '"basic"'}}
run: QUIET=1 npx tape .github/workflows/integration-tests/generated/**sandbox-test.js | npx tap-spec
- name: Notify
uses: homoluctus/slatify@master
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && failure()
with:
type: ${{ job.status }}
job_name: "*Sandbox Integration Tests*"
url: ${{ secrets.BX_SLACK_BX_CHANNEL }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
check_user_permission:
outputs:
has-permission: ${{ steps.check.outputs.has-permission }}
runs-on: ubuntu-latest
name: A job to check user's permission level
steps:
# Check for write permission
- name: Check user permission
id: check
uses: scherermichael-oss/action-has-permission@master
with:
required-permission: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Use the output from the `check` step
- name: Run only if user has sufficient permissions
if: steps.check.outputs.has-permission
run: echo "HAS_PERMISSION=true"
- name: Run only if user has NOT sufficient permissions
if: "! steps.check.outputs.has-permission"
run: echo "HAS_PERMISSION=false"
staging_tests:
timeout-minutes: 30
if: needs.check_user_permission.outputs.has-permission
runs-on: ubuntu-latest
env:
#below sets default to true and will confirm later in workflow
HAS_CUSTOM_TESTS: true
needs: [staging_tests_exist, sandbox_tests, check_user_permission]
strategy:
matrix:
node-version: [14.x]
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Env
run: |
echo "Event name: ${{ github.event_name }}"
echo "Git ref: ${{ github.ref }}"
echo "GH actor: ${{ github.actor }}"
echo "SHA: ${{ github.sha }}"
VER=`node --version`; echo "Node ver: $VER"
VER=`npm --version`; echo "npm ver: $VER"
- name: Configure AWS credentials from Test account
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BX_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BX_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Install
run: npm install
- name: Install Architect
run: npm i @architect/architect
- name: Build if needed
run: npm run build --if-present
- name: Install Test Dependencies
run: npm i tape tap-spec tiny-json-http
- name: Install Script Dependencies
run: npm i yargs
- name: Set Stack Name
run: echo "UNIQUE_STACK=b${GITHUB_SHA::7}$(date +%d)" >> $GITHUB_ENV
- name: Find App Name
run: echo "APP_NAME=$(node .github/workflows/integration-tests/scripts/get-app-name.js )" >> $GITHUB_ENV
- name: Calculate Stack Name
run: echo "AWS_STACK_NAME=$(node .github/workflows/integration-tests/scripts/get-stack-name.js --app-name ${{env.APP_NAME}} --unique-stack ${{env.UNIQUE_STACK}})" >> $GITHUB_ENV
- name: Deploy Staging
run: npx arc deploy --name ${{env.UNIQUE_STACK}}
- name: Find Stack Url
run: echo "STAGING_URL=$(aws cloudformation describe-stacks --stack-name ${{env.AWS_STACK_NAME}} | node .github/workflows/integration-tests/scripts/get-staging-url.js)" >> $GITHUB_ENV
- name: Read Test Config
run: echo "TEST_CONFIG_RUN=$(cat .github/workflows/integration-tests/generated/tests-config.json | jq '.run')" >> $GITHUB_ENV
- name: Run Basic Tests
if: ${{env.TEST_CONFIG_RUN == '"basic"'}}
run: QUIET=1 STAGING_URL=${{ env.STAGING_URL }} npx tape .github/workflows/integration-tests/generated/**staging-test.js | npx tap-spec
- name: Check for custom tests
run: test -f .github/workflows/integration-tests/custom/**sandbox-test.js || echo "HAS_CUSTOM_TESTS=false" >> $GITHUB_ENV
- name: Run Custom Staging Tests
if: ${{env.HAS_CUSTOM_TESTS == true}}
run: QUIET=1 STAGING_URL=${{ env.STAGING_URL }} npx tape .github/workflows/integration-tests/custom/**staging-test.js | npx tap-spec
- name: Destroy Infrastructure
if: ${{ always() }}
run: npx arc destroy --app ${{ env.APP_NAME }} --name ${{env.UNIQUE_STACK}} --force --now
# - name: Delete Stack if Destroy Failed
# if: ${{ always() }}
# run: aws cloudformation delete-stack --stack-name ${{env.AWS_STACK_NAME}}
- name: Notify
uses: homoluctus/slatify@master
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && failure()
with:
type: ${{ job.status }}
job_name: "*Staging Integration Tests*"
url: ${{ secrets.BX_SLACK_BX_CHANNEL }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}