diff --git a/.github/setBranchName.sh b/.github/setBranchName.sh new file mode 100755 index 0000000000..00ffd55ffe --- /dev/null +++ b/.github/setBranchName.sh @@ -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 \ No newline at end of file diff --git a/.github/waf-controller.sh b/.github/waf-controller.sh index 6f57206b0b..3bdd242e38 100755 --- a/.github/waf-controller.sh +++ b/.github/waf-controller.sh @@ -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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2cc84ab594..0262cca41c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,7 +8,7 @@ on: - "!skipci*" concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref_name }} permissions: id-token: write @@ -19,7 +19,7 @@ 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: @@ -27,17 +27,11 @@ jobs: 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/install-jq-action@v2.1.0 with: @@ -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 @@ -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 @@ -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: diff --git a/.github/workflows/destroy.yml b/.github/workflows/destroy.yml index f9f5ef5066..08ee56abd1 100644 --- a/.github/workflows/destroy.yml +++ b/.github/workflows/destroy.yml @@ -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 @@ -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 diff --git a/destroy.sh b/destroy.sh index 6ada321564..615ec57db0 100755 --- a/destroy.sh +++ b/destroy.sh @@ -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