From 989db042c17a20b46445f95c000a3335e0d7e031 Mon Sep 17 00:00:00 2001 From: miampf Date: Tue, 13 Feb 2024 15:40:23 +0100 Subject: [PATCH] cleaner shell script --- .../e2e_cleanup_timeframe/e2e-cleanup.sh | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh b/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh index cbc36d9e0..058637ae5 100755 --- a/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh +++ b/.github/actions/e2e_cleanup_timeframe/e2e-cleanup.sh @@ -3,7 +3,7 @@ # get_e2e_test_ids_on_date gets all workflow IDs of workflows that contain "e2e" on a specific date. function get_e2e_test_ids_on_date { ids="$(gh run list --created "$1" --json createdAt,workflowName,databaseId --jq '.[] | select(.workflowName | contains("e2e")) | .databaseId' -L1000 -R edgelesssys/constellation)" - echo $ids + echo "$ids" } # download_tfstate_artifact downloads all artifacts matching the pattern terraform-state-* from a given workflow ID. @@ -13,18 +13,18 @@ function download_tfstate_artifact { # delete_resources runs terraform destroy on the constellation-terraform subfolder of a given folder. function delete_resources { - cd $1/constellation-terraform + cd "$1/constellation-terraform" || exit 1 terraform init > /dev/null # first, install plugins terraform destroy -auto-approve > /dev/null - cd ../../ + cd ../../ || exit 1 } # delete_iam_config runs terraform destroy on the constellation-iam-terraform subfolder of a given folder. function delete_iam_config { - cd $1/constellation-iam-terraform + cd "$1/constellation-iam-terraform" || exit 1 terraform init > /dev/null # first, install plugins terraform destroy -auto-approve > /dev/null - cd ../../ + cd ../../ || exit 1 } # check if the password for artifact decryption was given @@ -42,21 +42,21 @@ dates_to_clean=() # get all dates of the last week while [[ $end_date != "$start_date" ]]; do - dates_to_clean+=($end_date) + dates_to_clean+=("$end_date") end_date=$(date --date "$end_date +1 day" "+%Y-%m-%d") done echo "[*] retrieving run IDs for cleanup" database_ids=() -for d in ${dates_to_clean[*]}; do +for d in "${dates_to_clean[@]}"; do echo " retrieving run IDs from $d" - database_ids+=($(get_e2e_test_ids_on_date $d)) + database_ids+=($(get_e2e_test_ids_on_date "$d")) done echo "[*] downloading terraform state artifacts" -for id in ${database_ids[*]}; do +for id in "${database_ids[@]}"; do echo " downloading from workflow $id" - download_tfstate_artifact $id + download_tfstate_artifact "$id" done echo "[*] extracting artifacts" @@ -64,15 +64,15 @@ for directory in ./terraform-state-*; do echo " extracting $directory" # extract and decrypt the artifact - unzip -d ${directory} -P "$artifact_pwd" $directory/archive.zip > /dev/null + unzip -d "${directory}" -P "$artifact_pwd" "$directory/archive.zip" > /dev/null done echo "[*] deleting resources" for directory in ./terraform-state-*; do echo " deleting resources in $directory" - delete_resources $directory + delete_resources "$directory" echo " deleting IAM configuration in $directory" - delete_iam_config $directory + delete_iam_config "$directory" done exit 0