cleaner shell script

This commit is contained in:
miampf 2024-02-13 15:40:23 +01:00
parent c944533982
commit 989db042c1
No known key found for this signature in database
GPG Key ID: EF039364B5B6886C

View File

@ -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