Skip to content

Destroy

Destroy #194

Workflow file for this run

name: Destroy
on: delete
concurrency:
# Ensuring group key matches the destroy workflow currently in master
group: dev-${{ github.event.ref }}
cancel-in-progress: false
permissions:
id-token: write
contents: read
actions: read
jobs:
destroy:
# Protected branches should be designated as such in the GitHub UI.
# So, a protected branch should never have this workflow run, since the branch should never be deleted.
# This conditional is a backup mechanism to help prevent mistakes from becoming disasters.
# This is a list of branch names that are commonly used for protected branches/environments.
# Add/remove names from this list as appropriate.
# Names include current v3 branches (main/val/production) and v2 branches in an effort to protect any preserved resources like saved databases
if: github.event.ref_type == 'branch' && !contains(fromJson('["master", "main", "staging", "val", "production", "prod"]'), github.event.ref)
runs-on: ubuntu-latest
steps:
- name: set branch_name
run: |
if [[ "${{ github.event.ref }}" =~ ^dependabot/.* ]]; then # Dependabot builds very long branch names. This is a switch to make it shorter.
echo "branch_name=`echo ${{ github.event.ref }} | md5sum | head -c 10 | sed 's/^/x/'`" >> $GITHUB_ENV
else
echo "branch_name=${{ github.event.ref }}" >> $GITHUB_ENV
fi
- uses: actions/checkout@v3
- name: set branch specific variable names
run: ./.github/build_vars.sh set_names
- name: set variable values
run: ./.github/build_vars.sh set_values
env:
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_OIDC_ROLE_TO_ASSUME: ${{ secrets[env.BRANCH_SPECIFIC_VARNAME_AWS_OIDC_ROLE_TO_ASSUME] || secrets.AWS_OIDC_ROLE_TO_ASSUME }}
STAGE_PREFIX: ${{ secrets.STAGE_PREFIX }}
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ env.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Delete topics from bigmac
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Delete Topics
repo: Enterprise-CMCS/bigmac
token: ${{ secrets.AUTOMATION_ACCESS_TOKEN }}
inputs: '{ "topics": "mgmt.connect.cms-carts-seds.carts-bigmac-streams-${{env.BRANCH_NAME}}.config,mgmt.connect.cms-carts-seds.carts-bigmac-streams-${{env.BRANCH_NAME}}.offsets,mgmt.connect.cms-carts-seds.carts-bigmac-streams-${{env.BRANCH_NAME}}.status"}'
ref: refs/heads/master # Otherwise workflow-dispatch tries to operate off of our default name
- run: ./destroy.sh $STAGE_PREFIX$branch_name