Azure automation tests #581
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 }} |