2
2
3
3
# get_e2e_test_ids_on_date gets all workflow IDs of workflows that contain "e2e" on a specific date.
4
4
function get_e2e_test_ids_on_date {
5
- ids=" $( gh run list --created " $1 " --status failure --json createdAt,workflowName,databaseId --jq ' .[] | select(.workflowName | contains("e2e") and (contains("MiniConstellation") | not)) | .databaseId' -L1000 -R edgelesssys/constellation || exit 1) "
5
+ ids=" $( gh run list --created " $1 " --status failure --json createdAt,workflowName,databaseId --jq ' .[] | select(.workflowName | ( contains("e2e") or contains("Release") ) and (contains("MiniConstellation") | not)) | .databaseId' -L1000 -R edgelesssys/constellation || exit 1) "
6
6
echo " ${ids} "
7
7
}
8
8
@@ -11,24 +11,15 @@ function download_tfstate_artifact {
11
11
gh run download " $1 " -p " terraform-state-*" -R edgelesssys/constellation > /dev/null
12
12
}
13
13
14
- # delete_resources runs terraform destroy on the constellation-terraform subfolder of a given folder.
15
- function delete_resources {
16
- if [[ -d " $1 /constellation-terraform" ]]; then
17
- cd " $1 /constellation-terraform" || exit 1
18
- terraform init > /dev/null || exit 1 # first, install plugins
19
- terraform destroy -auto-approve || exit 1
20
- cd ../../ || exit 1
21
- fi
22
- }
23
-
24
- # delete_iam_config runs terraform destroy on the constellation-iam-terraform subfolder of a given folder.
25
- function delete_iam_config {
26
- if [[ -d " $1 /constellation-iam-terraform" ]]; then
27
- cd " $1 /constellation-iam-terraform" || exit 1
28
- terraform init > /dev/null || exit 1 # first, install plugins
29
- terraform destroy -auto-approve || exit 1
30
- cd ../../ || exit 1
14
+ # delete_terraform_resources runs terraform destroy on the given folder.
15
+ function delete_terraform_resources {
16
+ delete_err=0
17
+ if pushd " ${1} /${2} " ; then
18
+ terraform init > /dev/null || delete_err=1 # first, install plugins
19
+ terraform destroy -auto-approve || delete_err=1
20
+ popd || exit 1
31
21
fi
22
+ return " ${delete_err} "
32
23
}
33
24
34
25
# check if the password for artifact decryption was given
@@ -42,7 +33,7 @@ artifact_pwd=${ENCRYPTION_SECRET}
42
33
shopt -s nullglob
43
34
44
35
start_date=$( date " +%Y-%m-%d" )
45
- end_date=$( date --date " -7 day" " +%Y-%m-%d" )
36
+ end_date=$( date --date " -4 day" " +%Y-%m-%d" )
46
37
dates_to_clean=()
47
38
48
39
# get all dates of the last week
@@ -85,13 +76,19 @@ export TF_PLUGIN_CACHE_DIR="${HOME}/tf_plugin_cache"
85
76
echo " [*] created terraform cache directory ${TF_PLUGIN_CACHE_DIR} "
86
77
87
78
echo " [*] deleting resources"
79
+ error_occurred= 0
88
80
for directory in ./terraform-state-* ; do
89
81
echo " deleting resources in ${directory} "
90
- delete_resources " ${directory} "
82
+ delete_terraform_resources " ${directory} " " constellation-terraform " || echo " [!] deleting resources failed " && error_occurred=1
91
83
echo " deleting IAM configuration in ${directory} "
92
- delete_iam_config " ${directory} "
84
+ delete_terraform_resources " ${directory} " " constellation-iam-terraform " || echo " [!] deleting IAM resources failed " && error_occurred=1
93
85
echo " deleting directory ${directory} "
94
86
rm -rf " ${directory} "
95
87
done
96
88
89
+ if [[ ${error_occurred} -ne 0 ]]; then
90
+ echo " [!] Errors occurred during resource deletion."
91
+ exit 1
92
+ fi
93
+
97
94
exit 0
0 commit comments