Tasks #135
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
# Run database migration commands inside the Docker container running | |
# the Elastic Beanstalk application | |
name: Tasks | |
on: | |
workflow_dispatch: | |
inputs: | |
Task: | |
type: choice | |
description: "The task to perform" | |
required: true | |
options: | |
- 'db current revision' | |
- 'db upgrade to head' | |
- 'db upgrade to next' | |
- 'db downgrade to previous' | |
Environment: | |
type: choice | |
description: "The environment to target" | |
required: true | |
default: 'staging' | |
options: | |
- 'staging' | |
- 'prod' | |
Timeout: | |
type: string | |
description: "The timeout in seconds" | |
default: '900' | |
Region: | |
type: choice | |
description: "The AWS region to target" | |
required: true | |
default: 'all' | |
options: | |
- 'all' | |
- 'ca-central-1' | |
- 'us-west-1' | |
Destructive: | |
description: Check to confirm you are happy to proceed with a destructive operation | |
type: boolean | |
required: false | |
default: false | |
jobs: | |
preflight: | |
runs-on: ubuntu-latest | |
steps: | |
- name: catch unauthorised destructive operations | |
run: | | |
if [[ "${{ inputs.Task }}" = 'db upgrade to head' ]] && | |
[[ "${{ github.event.inputs.Destructive }}" = 'false' ]] || | |
[[ "${{ inputs.Task }}" = 'db upgrade to next' ]] && | |
[[ "${{ github.event.inputs.Destructive }}" = 'false' ]] || | |
[[ "${{ inputs.Task }}" = 'db downgrade to previous' ]] && | |
[[ "${{ github.event.inputs.Destructive }}" = 'false' ]] ; then | |
echo "::error::'${{ inputs.Task }}' needs destructive option" | |
exit 1 | |
else | |
echo "::notice::Preparing '${{ inputs.Task }}' update in ${{ inputs.Environment }}" | |
echo "::notice::Targeting regions - '${{ inputs.region }}'" | |
echo "::notice::Timeout - '${{ inputs.Timeout }}'" | |
exit 0 | |
fi | |
current: | |
if: inputs.Task == 'db current revision' | |
needs: preflight | |
uses: hypothesis/workflows/.github/workflows/eb-task.yml@main | |
with: | |
App: ${{ github.event.repository.name }} | |
Env: ${{ inputs.Environment }} | |
Timeout: ${{ inputs.Timeout }} | |
Region: ${{ inputs.Region }} | |
Command: 'alembic -c conf/alembic.ini current' | |
secrets: inherit | |
head: | |
if: inputs.Task == 'db upgrade to head' && github.event.inputs.Destructive == 'true' | |
needs: preflight | |
uses: hypothesis/workflows/.github/workflows/eb-task.yml@main | |
with: | |
App: ${{ github.event.repository.name }} | |
Env: ${{ inputs.Environment }} | |
Timeout: ${{ inputs.Timeout }} | |
Region: ${{ inputs.Region }} | |
Command: 'alembic -c conf/alembic.ini upgrade head' | |
secrets: inherit | |
next: | |
if: inputs.Task == 'db upgrade to next' && github.event.inputs.Destructive == 'true' | |
needs: preflight | |
uses: hypothesis/workflows/.github/workflows/eb-task.yml@main | |
with: | |
App: ${{ github.event.repository.name }} | |
Env: ${{ inputs.Environment }} | |
Timeout: ${{ inputs.Timeout }} | |
Region: ${{ inputs.Region }} | |
Command: 'alembic -c conf/alembic.ini upgrade +1' | |
secrets: inherit | |
downgrade: | |
if: inputs.Task == 'db downgrade to previous' && github.event.inputs.Destructive == 'true' | |
needs: preflight | |
uses: hypothesis/workflows/.github/workflows/eb-task.yml@main | |
with: | |
App: ${{ github.event.repository.name }} | |
Env: ${{ inputs.Environment }} | |
Timeout: ${{ inputs.Timeout }} | |
Region: ${{ inputs.Region }} | |
Command: 'alembic -c conf/alembic.ini downgrade -1' | |
secrets: inherit |