diff --git a/.github/actions/happy-cleanup/action.yml b/.github/actions/happy-cleanup/action.yml index 1e0c6a5f..21bc0cad 100644 --- a/.github/actions/happy-cleanup/action.yml +++ b/.github/actions/happy-cleanup/action.yml @@ -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 @@ -46,6 +50,7 @@ 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: | @@ -53,16 +58,20 @@ runs: set -o pipefail date=`date +%Y-%m-%d'T'%H:%M'Z' -d "$TIME ago"` + list="happy list --output json --env $ENV" + force="" + if [[ ${ALL} ]]; then + list="happy list --all --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 $($(echo $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 "$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 $($(echo $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 "$force" + done \ No newline at end of file