Skip to content

Commit ba74cdb

Browse files
utam0kroboquat
authored andcommitted
test: Add a gc for integration branches
1 parent af45552 commit ba74cdb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

.werft/workspace-run-integration-tests.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ DO_CLEANUP=0
1515
declare -A FAILURE_TESTS
1616
declare SIGNAL # used to record signal caught by trap
1717

18+
BRANCH_TIMEOUT_SEC=10800
19+
1820
context_name=$1
1921
context_repo=$2
2022

@@ -69,6 +71,26 @@ function cleanup ()
6971
werft log slice "clean up" --done
7072
}
7173

74+
function gc_integration_branches ()
75+
{
76+
werft log phase "GC too old integration branches" "GC too old integration branches"
77+
now=$(date --utc +%s)
78+
for br in $(git branch --format="%(refname:short)" -a | grep -v HEAD); do
79+
if echo $br | grep -q "origin/wk-inte-test/*"; then
80+
last_commite_date=$(date --utc --date "$(git show --format="%ci" $br | head -n 1)" +%s)
81+
diff=$(( $now-$last_commite_date ))
82+
if [[ $diff > $BRANCH_TIMEOUT_SEC ]]; then
83+
local_branch_name=$(echo $br | cut -d '/' -f2-)
84+
werft log slice "delete $local_branch_name"
85+
set +e
86+
git push origin :"$local_branch_name"
87+
set -e
88+
werft log slice "delete $local_branch_name" --done
89+
fi
90+
fi
91+
done
92+
}
93+
7294
sudo chown -R gitpod:gitpod /workspace
7395
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
7496
export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/legacy_credentials/[email protected]/adc.json"
@@ -77,6 +99,8 @@ git config --global user.name roboquat
7799
git config --global user.email [email protected]
78100
git remote set-url origin https://oauth2:"${ROBOQUAT_TOKEN}"@github.com/gitpod-io/gitpod.git
79101

102+
gc_integration_branches
103+
80104
werft log phase "build preview environment" "build preview environment"
81105

82106
# Create a new branch and asks Werft to create a preview environment for it
@@ -185,3 +209,4 @@ do
185209
done
186210

187211
exit $FAILURE_COUNT
212+

0 commit comments

Comments
 (0)