Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to delete all stacks in happy environment #275

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions .github/actions/happy-cleanup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: The environment in which to delete stacks
required: true
default: rdev
all:
description: include every stack in the environment
required: false
default: false
time:
description: The longest period before a stack should be considered stale. Should be something like '2 weeks' or '1 day'
required: true
Expand Down Expand Up @@ -46,23 +50,28 @@ runs:
TFE_TOKEN: ${{ inputs.tfe_token }}
TIME: ${{inputs.time}}
EXCLUDE: ${{ inputs.exclude }}
ALL: ${{ inputs.all}}
HAPPY_OIDC_ID_TOKEN: ${{steps.idtoken.outputs.id_token}}
shell: bash
run: |
set -ue
set -o pipefail

date=`date +%Y-%m-%d'T'%H:%M'Z' -d "$TIME ago"`
list="happy list --aws-profile '' --output json --env $ENV"
force=""
if [[ ${ALL} ]]; then
list="happy list --all --aws-profile '' --output json --env $ENV"
force="--force"
fi
if [[ ! -z ${EXCLUDE} ]]; then
for i in $(happy list --aws-profile "" --output json --env $ENV | jq -r --arg date "$date" --arg exclude "$EXCLUDE" '.[] | select(.last_updated < $date) | select(any(.stack; contains($exclude))|not) | .stack'); do
for i in $("$list" | jq -r --arg date "$date" --arg exclude "$EXCLUDE" '.[] | select(.last_updated < $date) | select(any(.stack; contains($exclude))|not) | .stack'); do
echo "Deleting stack: $i"
happy delete $i --env $ENV --aws-profile ""
happy delete $i --env $ENV --aws-profile "" "$force"
done
exit
fi
for i in $(happy list --aws-profile "" --output json --env $ENV | jq -r --arg date "$date" '.[] | select(.last_updated < $date) | .stack'); do
for i in $("$list" | jq -r --arg date "$date" '.[] | select(.last_updated < $date) | .stack'); do
echo "Deleting stack: $i"
happy delete $i --env $ENV --aws-profile ""
done


happy delete $i --env $ENV --aws-profile "" "$force"
done
Loading