-
Notifications
You must be signed in to change notification settings - Fork 21
309 lines (290 loc) · 13.2 KB
/
azure_automation_test.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# if you want to debug this and trigger it on PRs against dev
# uncomment the 2 pull_request lines below
name: Azure automation tests
on:
# pull_request:
# branches: [ develop ]
schedule:
# run twice a day at 10:00 and 22:00 UTC every day of the week
- cron: "0 10/12 * * *"
workflow_dispatch:
# automation-branch refers to the version of the automation test application to be used, running on the gha runner
# app-version refers to the version of the leonardo app that will be tested against, usually running in a BEE
# these are often the same, and live in the same repo, but are distinct instances of code.
inputs:
automation-branch:
description: 'Branch of leo automation to run tests from'
required: true
default: 'develop'
type: string
app-version:
description: 'Branch of leo app to be deployed'
required: true
default: 'develop'
type: string
delete-bee:
description: 'Delete created bee after running tests'
required: true
default: true
type: boolean
owner-subject:
description: 'Owner subject (used for creating billing project in E2E testing)'
required: true
default: 'hermione.owner@quality.firecloud.org'
type: string
student-subjects:
description: 'A JSON array of Student subjects used for E2E testing'
required: true
default: '["harry.potter@quality.firecloud.org","ron.weasley@quality.firecloud.org"]'
type: string
service-account:
description: 'Email address or unique identifier of the Google Cloud service account for which to generate credentials'
required: true
default: 'firecloud-qa@broad-dsde-qa.iam.gserviceaccount.com'
type: string
env:
BEE_NAME: '${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt}}-dev'
TOKEN: '${{ secrets.BROADBOT_TOKEN }}' # github token for access to kick off a job in the private repo
LEO_BUILD_RUN_NAME: 'leonardo-build-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
LEO_SWAT_TESTS_RUN_NAME: 'leonardo-swat-tests-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
BEE_CREATE_RUN_NAME: 'bee-create-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
BEE_DESTROY_RUN_NAME: 'bee-destroy-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
ATTACH_BP_TO_LZ_RUN_NAME: 'attach-billing-project-to-landing-zone-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
DEL_BP_V2_RUN_NAME: 'delete-billing-project-v2-from-bee-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
E2E_ENV: 'azure_e2e.env'
jobs:
#
# Setup
#
init-github-context:
runs-on: ubuntu-latest
outputs:
automation-branch: ${{ steps.prepare-outputs.outputs.automation-branch }}
app-version: ${{ steps.prepare-outputs.outputs.app-version }}
delete-bee: ${{ steps.prepare-outputs.outputs.delete-bee }}
owner-subject: ${{ steps.prepare-outputs.outputs.owner-subject }}
student-subjects: ${{ steps.prepare-outputs.outputs.student-subjects }}
service-account: ${{ steps.prepare-outputs.outputs.service-account }}
log-results: ${{ steps.prepare-outputs.outputs.log-results }}
test-context: ${{ steps.prepare-outputs.outputs.test-context }}
steps:
- name: Get inputs and/or set defaults
id: prepare-outputs
run: |
echo "automation-branch=${{ inputs.automation-branch || 'develop' }}" >> "$GITHUB_OUTPUT"
echo "app-version=${{ inputs.app-version || 'develop' }}" >> "$GITHUB_OUTPUT"
echo "delete-bee=${{ inputs.delete-bee || false }}" >> "$GITHUB_OUTPUT"
echo "owner-subject=${{ inputs.owner-subject || 'hermione.owner@quality.firecloud.org' }}" >> "$GITHUB_OUTPUT"
echo "student-subjects=${{ toJson(inputs.student-subjects || '["harry.potter@quality.firecloud.org","ron.weasley@quality.firecloud.org"]') }}" >> "$GITHUB_OUTPUT"
echo "service-account=${{ inputs.service-account || 'firecloud-qa@broad-dsde-qa.iam.gserviceaccount.com' }}" >> "$GITHUB_OUTPUT"
echo "log-results=true" >> $GITHUB_OUTPUT
echo "test-context=azure-e2e" >> $GITHUB_OUTPUT
create-bee-workflow:
runs-on: ubuntu-latest
needs: [ init-github-context ]
permissions:
contents: 'read'
id-token: 'write'
steps:
# format the app version string to be usable by create-bee
- name: Render Leonardo version
id: render-leo-version
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
echo "$GITHUB_CONTEXT"
echo 'custom-version-json={\"leonardo\":{\"appVersion\":\"${{ needs.init-github-context.outputs.app-version }}\"}}' >> $GITHUB_OUTPUT
- name: dispatch to terra-github-workflows
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.BEE_CREATE_RUN_NAME }}"
workflow: bee-create
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ env.TOKEN }}
inputs: '{
"run-name": "${{ env.BEE_CREATE_RUN_NAME }}",
"bee-name": "${{ env.BEE_NAME }}",
"bee-template-name": "rawls-e2e-azure-tests",
"version-template": "dev",
"custom-version-json": "${{ steps.render-leo-version.outputs.custom-version-json }}"
}'
# This job can be used for generating parameters for E2E tests (e.g. a random project name).
params-gen:
runs-on: ubuntu-latest
outputs:
project-name: ${{ steps.gen.outputs.project_name }}
steps:
- uses: 'actions/checkout@v3'
- name: Generate a random billing project name
id: 'gen'
run: |
project_name=$(echo "tmp-billing-project-$(uuidgen)" | cut -c -30)
echo "project_name=${project_name}" >> $GITHUB_OUTPUT
# Azure Managed App Coordinates are defined in the following workflow:
# https://github.com/broadinstitute/terra-github-workflows/blob/main/.github/workflows/attach-landing-zone-to-bee.yaml
attach-billing-project-to-landing-zone-workflow:
runs-on: ubuntu-latest
needs: [ init-github-context, create-bee-workflow, params-gen ]
steps:
- name: dispatch to terra-github-workflows
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.ATTACH_BP_TO_LZ_RUN_NAME }}"
workflow: attach-billing-project-to-landing-zone.yaml
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ env.TOKEN }}
inputs: '{
"run-name": "${{ env.ATTACH_BP_TO_LZ_RUN_NAME }}",
"mrg-id": "e2e-8n6xqg",
"landing-zone-id": "c6489e53-85b6-4bf1-ada1-d05f9602315d",
"bee-name": "${{ env.BEE_NAME }}",
"billing-project": "${{ needs.params-gen.outputs.project-name }}",
"billing-project-creator": "${{ needs.init-github-context.outputs.owner-subject }}",
"service-account": "${{ needs.init-github-context.outputs.service-account }}"
}'
#
# Test Run
#
leo-automation-test-job:
runs-on: ubuntu-latest
needs:
- init-github-context
- create-bee-workflow
- params-gen
- attach-billing-project-to-landing-zone-workflow
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Configure the user subjects for the test
run: |
USER_SUBJECTS='{
"service_account": "${{ needs.init-github-context.outputs.service-account }}",
"owners": ["${{ needs.init-github-context.outputs.owner-subject }}"],
"students": ${{ needs.init-github-context.outputs.student-subjects }}
}'
USER_SUBJECTS=$(echo "$USER_SUBJECTS" |
tr -d '\n' |
jq -c '.')
echo "USER_SUBJECTS=$USER_SUBJECTS" >> $GITHUB_ENV
- name: Configure e2e-infrastructure input parameter
# E2E_INFRASTRUCTURE values are used as follows:
# e2e_env: The name of a .env file that contains envvars for E2E tests
# billing_project: Billing Project
run: |
E2E_INFRASTRUCTURE='{
"e2e_env": { "val": "${{ env.E2E_ENV }}" },
"billing_project": { "val": "${{ needs.params-gen.outputs.project-name }}" }
}'
E2E_INFRASTRUCTURE=$(echo "$E2E_INFRASTRUCTURE" |
tr -d '\n' |
jq -c '.')
echo "E2E_INFRASTRUCTURE=$E2E_INFRASTRUCTURE" >> $GITHUB_ENV
- name: Configure test-reporting input parameter
# TEST_REPORTING values are used as follows:
# log_results: boolean to log test results to bigquery
# test_context: descriptive context that test is running in, e.g. PR, post-develop, staging. Will be passed to env of the bigquery table
# caller_run_id: descriptive run_id of caller
run: |
TEST_REPORTING='{
"log_results": { "val": ${{ needs.init-github-context.outputs.log-results }} },
"test_context": { "val": "${{ needs.init-github-context.outputs.test-context }}" },
"caller_run_id": { "val": "${{ github.run_id }}" }
}'
TEST_REPORTING=$(echo "$TEST_REPORTING" |
tr -d '\n' |
jq -c '.')
echo "TEST_REPORTING=$TEST_REPORTING" >> $GITHUB_ENV
- name: dispatch to terra-github-workflows
env:
leo_test_command: "testOnly -s org.broadinstitute.dsde.workbench.leonardo.LeonardoAzureSuite"
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.LEO_SWAT_TESTS_RUN_NAME }}"
workflow: .github/workflows/leonardo-swat-tests.yaml
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ env.TOKEN }}
inputs: '{
"run-name": "${{ env.LEO_SWAT_TESTS_RUN_NAME }}",
"bee-name": "${{ env.BEE_NAME }}",
"ENV": "qa",
"test-group-name": "workspaces_azure",
"sbt-test-command": "${{ env.leo_test_command }}",
"java-version": "17",
"ref": "${{ needs.init-github-context.outputs.automation-branch }}",
"e2e-infrastructure": ${{ toJson(env.E2E_INFRASTRUCTURE) }},
"test-reporting": ${{ toJson(env.TEST_REPORTING) }},
"user-subjects": ${{ toJson(env.USER_SUBJECTS) }}
}'
#
# Cleanup
#
delete-billing-project-v2-from-bee-workflow:
runs-on: ubuntu-latest
needs:
- init-github-context
- params-gen
- leo-automation-test-job
if: always()
steps:
- name: dispatch to terra-github-workflows
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.DEL_BP_V2_RUN_NAME }}"
workflow: .github/workflows/delete-billing-project-v2-from-bee.yaml
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ env.TOKEN }}
inputs: '{
"run-name": "${{ env.DEL_BP_V2_RUN_NAME }}",
"bee-name": "${{ env.BEE_NAME }}",
"billing-project": "${{ needs.params-gen.outputs.project-name }}",
"billing-project-owner": "${{ needs.init-github-context.outputs.owner-subject }}",
"service-account": "${{ needs.init-github-context.outputs.service-account }}",
"silent-on-failure": "true"
}'
destroy-bee-workflow:
runs-on: ubuntu-latest
needs:
- init-github-context
- leo-automation-test-job
- delete-billing-project-v2-from-bee-workflow
if: ${{ needs.init-github-context.outputs.delete-bee && always() }} # always run to confirm bee is destroyed unless explicitly requested not to
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: dispatch to terra-github-workflows
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.BEE_DESTROY_RUN_NAME }}"
workflow: bee-destroy
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ env.TOKEN }}
inputs: '{
"run-name": "${{ env.BEE_DESTROY_RUN_NAME }}",
"bee-name": "${{ env.BEE_NAME }}"
}'
wait-for-completion: false
notify-slack-on-failure:
runs-on: ubuntu-latest
needs:
- init-github-context
- create-bee-workflow
- leo-automation-test-job
- destroy-bee-workflow
if: ${{ github.event_name == 'schedule' && failure() }} # Want to notify regardless of which step fails
steps:
- name: Notify slack
uses: slackapi/slack-github-action@v1.23.0
with:
# C03ATF4QXEV is for #ia-notification-test
# C53JYBV9A is for #dsde-qa
channel-id: 'C03ATF4QXEV,C53JYBV9A'
slack-message: "Azure E2E Tests FAILED, automation-branch: ${{ needs.init-github-context.outputs.automation-branch }}\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACKBOT_TOKEN }}