Skip to content

Commit

Permalink
Fix infrastructure destroy actions (#2046)
Browse files Browse the repository at this point in the history
  • Loading branch information
berryd authored Feb 15, 2024
1 parent eb3562e commit 4052f9d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
19 changes: 19 additions & 0 deletions .github/setBranchName.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

GITHUB_REFNAME="${1}"

[ -z "${GITHUB_REFNAME}" ] && echo "Error setting branch name. No input given." && exit 1

case ${GITHUB_REFNAME} in
$([[ "$GITHUB_REFNAME" =~ ^dependabot/.* ]] && echo ${GITHUB_REFNAME}))
echo ${GITHUB_REFNAME} | md5sum | head -c 10 | sed 's/^/x/'
;;
$([[ "$GITHUB_REFNAME" =~ ^snyk-* ]] && echo ${GITHUB_REFNAME}))
echo ${GITHUB_REFNAME##*-} | head -c 10 | sed 's/^/s/'
;;
*)
echo ${GITHUB_REFNAME}
;;
esac
2 changes: 1 addition & 1 deletion .github/waf-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ for ((i=1; i <= $CIRCUIT_BREAKER; i++)); do
[[ $CMD_CD -eq $AWS_RETRY_ERROR ]] || break

SLEEP_FOR=$(jitter ${j})
echo "CLI retries exceed. Waiting for ${SLEEP_FOR} seconds to execute read again...$({j})"
echo "CLI retries exceed. Waiting for ${SLEEP_FOR} seconds to execute read again...(${j})"
sleep ${SLEEP_FOR}
done

Expand Down
32 changes: 10 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "!skipci*"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref_name }}

permissions:
id-token: write
Expand All @@ -19,25 +19,19 @@ jobs:
unit-tests:
name: Unit Tests
uses: ./.github/workflows/unittest-workflow.yml
if: github.ref == 'refs/heads/master'
if: github.ref_name == 'master'
secrets:
CODE_CLIMATE_ID: ${{ secrets.CODE_CLIMATE_ID }}
deploy:
runs-on: ubuntu-latest
env:
SLS_DEPRECATION_DISABLE: "*" # Turn off deprecation warnings in the pipeline
steps:
- uses: actions/checkout@v4
- name: set branch_name # Some integrations (Dependabot & Snyk) build very long branch names. This is a switch to make long branch names shorter.
run: |
echo "GITHUB_REF=${GITHUB_REF}"
if [[ "$GITHUB_REF" =~ ^refs/heads/dependabot/.* ]]; then
echo "branch_name=`echo ${GITHUB_REF##*/*-} | md5sum | head -c 10 | sed 's/^/x/'`" >> $GITHUB_ENV
elif [[ "$GITHUB_REF" =~ ^refs/.*/snyk-* ]]; then
echo "branch_name=`echo ${GITHUB_REF##*/*-} | head -c 10 | sed 's/^/s/'`" >> $GITHUB_ENV
else
echo "branch_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
- uses: actions/checkout@v3
BRANCH_NAME=$(./.github/setBranchName.sh ${{ github.ref_name }})
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_ENV
- name: 'Setup jq'
uses: dcarbone/[email protected]
with:
Expand Down Expand Up @@ -95,7 +89,7 @@ jobs:
# run e2e tests after deploy completes
e2e-tests-init:
name: Initialize End To End Tests
if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/val' && github.ref != 'refs/heads/prod' }}
if: ${{ github.ref_name != 'master' && github.ref_name != 'val' && github.ref_name != 'prod' }}
needs:
- deploy
runs-on: ubuntu-latest
Expand All @@ -105,17 +99,11 @@ jobs:
run: |
echo "No endpoint set, Check if the deploy workflow was successful."
exit 1
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: set branch_name
run: |
echo "GITHUB_REF=${GITHUB_REF}"
if [[ "$GITHUB_REF" =~ ^refs/heads/dependabot/.* ]]; then
echo "branch_name=`echo ${GITHUB_REF##*/*-} | md5sum | head -c 10 | sed 's/^/x/'`" >> $GITHUB_ENV
elif [[ "$GITHUB_REF" =~ ^refs/.*/snyk-* ]]; then
echo "branch_name=`echo ${GITHUB_REF##*/*-} | head -c 10 | sed 's/^/s/'`" >> $GITHUB_ENV
else
echo "branch_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
BRANCH_NAME=$(./.github/setBranchName.sh ${{ github.ref_name }})
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_ENV
- name: set branch specific variable names
id: set_names
run: ./.github/build_vars.sh set_names
Expand Down Expand Up @@ -327,7 +315,7 @@ jobs:
env:
SLS_DEPRECATION_DISABLE: "*" # Turn off deprecation warnings in the pipeline
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
28 changes: 20 additions & 8 deletions .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Destroy

on: delete
on:
delete:
workflow_dispatch:
inputs:
environment:
description: "Name of the environment to destroy:"
required: true

permissions:
id-token: write
Expand All @@ -14,17 +20,23 @@ jobs:
# 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.
if: github.event.ref_type == 'branch' && !contains(fromJson('["master", "val", "prod"]'), github.event.ref)
if: |
(
github.event.ref_type == 'branch' &&
(!startsWith(github.event.ref, 'skipci')) &&
(!contains(fromJson('["master", "val", "prod"]'), github.event.ref))
) ||
(
inputs.environment != '' &&
(!contains(fromJson('["master", "val", "prod"]'), inputs.environment))
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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
BRANCH_NAME=$(./.github/setBranchName.sh ${{ inputs.environment || github.event.ref }})
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_ENV
- name: set branch specific variable names
run: ./.github/build_vars.sh set_names
- name: set variable values
Expand Down
10 changes: 10 additions & 0 deletions destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ set -e
# Find cloudformation stacks associated with stage
stackList=(`aws cloudformation describe-stacks | jq -r ".Stacks[] | select(.Tags[] | select(.Key==\"STAGE\") | select(.Value==\"$stage\")) | .StackName"`)

if [ ${#stackList[@]} -eq 0 ]; then
echo """
---------------------------------------------------------------------------------------------
ERROR: No stacks were identified for destruction
---------------------------------------------------------------------------------------------
Please verify the stage name: $stage
"""
exit 1
fi

# Find buckets attached to any of the stages, so we can empty them before removal.
bucketList=()
set +e
Expand Down

0 comments on commit 4052f9d

Please sign in to comment.