Delete Preview Env Database #4
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
name: Delete Preview Env Database | |
on: | |
# TODO Delete this after testing | |
workflow_dispatch: | |
inputs: | |
db-name: | |
required: true | |
type: string | |
description: Database name to delete | |
workflow_call: | |
inputs: | |
db-name: | |
required: true | |
type: string | |
description: Database name to drop | |
jobs: | |
drop_database: | |
runs-on: [self-hosted] | |
steps: | |
- name: Set Owner | |
run: >- | |
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}" | |
-c "alter database ${{ inputs.db-name }} owner to ${{ secrets.DB_ROOT_USERNAME }};" postgres | |
- name: Drop Database | |
run: | | |
PGPASSWORD="${{ secrets.DB_PASSWORD }}" dropdb -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}" ${{ inputs.db-name }} | |
# run: | | |
# PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}" -c "DROP DATABASE ${{ inputs.db-name }}" postgres | |
# on-failure: | |
# runs-on: ubuntu-latest | |
# if: ${{ always() && (needs.drop_database.result == 'failure' || needs.drop_database.result == 'timed_out') }} | |
# needs: | |
# - drop_database | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: "Send Slack message on failure" | |
# uses: rtCamp/action-slack-notify@v2 | |
# env: | |
# SLACK_COLOR: failure | |
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }} | |
# SLACK_TITLE: Drop Database | |
# SLACK_MESSAGE: 'Error during database deletion!' | |
# | |
# on-success: | |
# runs-on: ubuntu-latest | |
# if: ${{ always() && (needs.drop_database.result == 'success') }} | |
# needs: | |
# - drop_database | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: "Send Slack message on success" | |
# uses: rtCamp/action-slack-notify@v2 | |
# env: | |
# SLACK_COLOR: success | |
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }} | |
# SLACK_TITLE: Drop Database | |
# SLACK_MESSAGE: 'Database deleted successfully!' |