2021-09-02 22:03:28 +02:00
|
|
|
---
|
2021-05-04 22:41:49 +02:00
|
|
|
name: QA Deploy
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
2021-09-02 22:03:28 +02:00
|
|
|
inputs:
|
2021-05-04 22:41:49 +02:00
|
|
|
migrateDb:
|
|
|
|
required: true
|
|
|
|
default: "true"
|
|
|
|
resetDb:
|
|
|
|
required: true
|
|
|
|
default: "false"
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
reset-db:
|
2021-06-22 18:51:28 +02:00
|
|
|
name: Reset Database
|
|
|
|
if: ${{ github.event.inputs.resetDb == 'true' }}
|
2021-09-25 00:04:14 +02:00
|
|
|
runs-on: ubuntu-20.04
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
|
|
|
- name: Reset Test Data - Stub
|
|
|
|
run: |
|
|
|
|
echo "placeholder for cleaning DB"
|
|
|
|
echo "placeholder for loading test dataset"
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
|
2021-05-04 22:41:49 +02:00
|
|
|
update-db:
|
2021-06-22 18:51:28 +02:00
|
|
|
name: Update Database
|
|
|
|
if: ${{ github.event.inputs.migrateDb == 'true' }}
|
2021-09-25 00:04:14 +02:00
|
|
|
runs-on: ubuntu-20.04
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
2021-06-22 18:51:28 +02:00
|
|
|
- name: Checkout repo
|
|
|
|
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
|
|
|
|
|
|
|
|
- name: Login to Azure
|
|
|
|
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
|
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2022-10-04 20:23:08 +02:00
|
|
|
uses: Azure/get-keyvault-secrets@80ccd3fafe5662407cc2e55f202ee34bfff8c403
|
|
|
|
with:
|
|
|
|
keyvault: "bitwarden-qa-kv"
|
|
|
|
secrets: "mssql-server-host,
|
|
|
|
mssql-admin-login,
|
|
|
|
mssql-admin-login-password"
|
2021-06-22 18:51:28 +02:00
|
|
|
|
|
|
|
- name: Migrate database
|
|
|
|
env:
|
|
|
|
MSSQL_HOST: ${{ steps.retrieve-secrets.outputs.mssql-server-host }}
|
|
|
|
MSSQL_USER: ${{ steps.retrieve-secrets.outputs.mssql-admin-login }}
|
|
|
|
MSSQL_PASS: ${{ steps.retrieve-secrets.outputs.mssql-admin-login-password }}
|
2022-05-18 14:43:36 +02:00
|
|
|
MSSQL_DATABASE: vault
|
|
|
|
MSSQL_MIGRATIONS_DIRECTORY: util/Migrator/DbScripts
|
2021-05-04 22:41:49 +02:00
|
|
|
run: |
|
2021-06-22 18:51:28 +02:00
|
|
|
echo "Running database migrations..."
|
2022-05-18 14:43:36 +02:00
|
|
|
$GITHUB_WORKSPACE/dev/helpers/mssql/run_migrations.sh -p
|
2021-05-04 22:41:49 +02:00
|
|
|
|
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
deploy:
|
2021-09-02 22:03:28 +02:00
|
|
|
name: Deploy
|
2021-09-25 00:04:14 +02:00
|
|
|
runs-on: ubuntu-20.04
|
2021-06-22 18:51:28 +02:00
|
|
|
if: always()
|
2021-09-02 22:03:28 +02:00
|
|
|
needs:
|
2021-05-04 22:41:49 +02:00
|
|
|
- reset-db
|
|
|
|
- update-db
|
2021-06-10 22:14:15 +02:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- name: Api
|
|
|
|
- name: Admin
|
|
|
|
- name: Billing
|
|
|
|
- name: Events
|
|
|
|
- name: Sso
|
|
|
|
- name: Identity
|
2021-05-04 22:41:49 +02:00
|
|
|
steps:
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Setup
|
|
|
|
id: setup
|
|
|
|
run: |
|
|
|
|
NAME_LOWER=$(echo "${{ matrix.name }}" | awk '{print tolower($0)}')
|
|
|
|
echo "Matrix name: ${{ matrix.name }}"
|
|
|
|
echo "NAME_LOWER: $NAME_LOWER"
|
|
|
|
echo "::set-output name=name_lower::$NAME_LOWER"
|
|
|
|
|
2021-10-27 21:44:54 +02:00
|
|
|
BRANCH_NAME=$(echo "$GITHUB_REF" | sed "s#refs/heads/##g")
|
2021-09-30 18:12:42 +02:00
|
|
|
echo "GITHUB_REF: $GITHUB_REF"
|
|
|
|
echo "BRANCH_NAME: $BRANCH_NAME"
|
2021-09-25 00:04:14 +02:00
|
|
|
echo "::set-output name=branch_name::$BRANCH_NAME"
|
|
|
|
|
2021-09-30 18:12:42 +02:00
|
|
|
mkdir publish
|
|
|
|
|
2022-07-25 23:19:56 +02:00
|
|
|
- name: Create GitHub deployment for ${{ matrix.name }}
|
|
|
|
uses: chrnorm/deployment-action@1b599fe41a0ef1f95191e7f2eec4743f2d7dfc48
|
|
|
|
id: deployment
|
|
|
|
with:
|
|
|
|
token: '${{ secrets.GITHUB_TOKEN }}'
|
2022-08-03 17:39:35 +02:00
|
|
|
initial-status: 'in_progress'
|
2022-07-25 23:19:56 +02:00
|
|
|
environment: 'Server ${{ matrix.name }} - QA'
|
|
|
|
task: 'deploy'
|
|
|
|
description: 'Deploy from ${{ env.branch_name }} branch'
|
|
|
|
|
2021-09-25 00:04:14 +02:00
|
|
|
- name: Download latest ${{ matrix.name }} asset from ${{ env.branch_name }}
|
2022-09-28 14:50:43 +02:00
|
|
|
uses: bitwarden/gh-actions/download-artifacts@850faad0cf6c02a8c0dc46eddde2363fbd6c373a
|
2021-09-30 17:24:50 +02:00
|
|
|
env:
|
|
|
|
branch_name: ${{ steps.setup.outputs.branch_name }}
|
2021-05-04 22:41:49 +02:00
|
|
|
with:
|
2021-09-25 00:04:14 +02:00
|
|
|
workflow: build.yml
|
|
|
|
workflow_conclusion: success
|
|
|
|
branch: ${{ env.branch_name }}
|
2021-09-30 17:24:50 +02:00
|
|
|
artifacts: ${{ matrix.name }}.zip
|
2021-09-30 18:12:42 +02:00
|
|
|
|
2021-05-04 22:41:49 +02:00
|
|
|
- name: Login to Azure
|
|
|
|
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
|
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2021-06-10 22:14:15 +02:00
|
|
|
env:
|
2021-09-02 22:03:28 +02:00
|
|
|
VAULT_NAME: "bitwarden-qa-kv"
|
2021-06-10 22:14:15 +02:00
|
|
|
run: |
|
2021-09-25 00:04:14 +02:00
|
|
|
webapp_name=$(
|
|
|
|
az keyvault secret show --vault-name $VAULT_NAME \
|
|
|
|
--name appservices-${{ steps.setup.outputs.name_lower }}-webapp-name \
|
|
|
|
--query value --output tsv
|
|
|
|
)
|
2021-06-10 22:14:15 +02:00
|
|
|
echo "::add-mask::$webapp_name"
|
|
|
|
echo "::set-output name=webapp-name::$webapp_name"
|
2021-05-04 22:41:49 +02:00
|
|
|
|
2021-09-13 16:08:32 +02:00
|
|
|
- name: Stop App Service
|
|
|
|
env:
|
|
|
|
AZURE_RESOURCE_GROUP: "bw-qa-env"
|
2021-12-08 05:28:13 +01:00
|
|
|
run: |
|
|
|
|
az webapp stop --name ${{ steps.retrieve-secrets.outputs.webapp-name }} \
|
|
|
|
--resource-group $AZURE_RESOURCE_GROUP
|
2021-09-13 16:08:32 +02:00
|
|
|
|
2021-06-10 22:14:15 +02:00
|
|
|
- name: Deploy App
|
2021-05-17 21:15:01 +02:00
|
|
|
uses: azure/webapps-deploy@798e43877120eda6a2a690a4f212c545e586ae31
|
2021-05-04 22:41:49 +02:00
|
|
|
with:
|
2021-09-02 22:03:28 +02:00
|
|
|
app-name: ${{ steps.retrieve-secrets.outputs.webapp-name }}
|
2021-06-10 22:14:15 +02:00
|
|
|
package: ./${{ matrix.name }}.zip
|
2021-09-13 16:08:32 +02:00
|
|
|
|
|
|
|
- name: Start App Service
|
|
|
|
env:
|
|
|
|
AZURE_RESOURCE_GROUP: "bw-qa-env"
|
2021-12-08 05:28:13 +01:00
|
|
|
run: |
|
|
|
|
az webapp start --name ${{ steps.retrieve-secrets.outputs.webapp-name }} \
|
|
|
|
--resource-group $AZURE_RESOURCE_GROUP
|
2022-07-25 23:19:56 +02:00
|
|
|
|
|
|
|
- name: Update ${{ matrix.name }} deployment status to Success
|
2022-08-03 17:39:35 +02:00
|
|
|
if: ${{ success() }}
|
2022-07-25 23:19:56 +02:00
|
|
|
uses: chrnorm/deployment-status@07b3930847f65e71c9c6802ff5a402f6dfb46b86
|
|
|
|
with:
|
|
|
|
token: '${{ secrets.GITHUB_TOKEN }}'
|
|
|
|
state: 'success'
|
|
|
|
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
|
|
|
|
|
|
|
|
- name: Update ${{ matrix.name }} deployment status to Failure
|
2022-08-03 17:39:35 +02:00
|
|
|
if: ${{ failure() }}
|
2022-07-25 23:19:56 +02:00
|
|
|
uses: chrnorm/deployment-status@07b3930847f65e71c9c6802ff5a402f6dfb46b86
|
|
|
|
with:
|
|
|
|
token: '${{ secrets.GITHUB_TOKEN }}'
|
|
|
|
state: 'failure'
|
|
|
|
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
|