-
Notifications
You must be signed in to change notification settings - Fork 5
/
cleanup.sh
executable file
·33 lines (27 loc) · 1.09 KB
/
cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Echo commands as they are executed, but don't allow errors to stop the script.
set -x
if [ -z "$TERMINUS_SITE" ] || [ -z "$TERMINUS_ENV" ]; then
echo "TERMINUS_SITE and TERMINUS_ENV environment variables must be set"
exit 1
fi
# Only delete old environments if there is a pattern defined to
# match environments eligible for deletion. Otherwise, delete the
# current multidev environment immediately.
#
# To use this feature, set MULTIDEV_DELETE_PATTERN to '^ci-' or similar
# in the CI server environment variables.
if [ -z "$MULTIDEV_DELETE_PATTERN" ] ; then
terminus multidev:delete $SITE_ENV --delete-branch --yes
exit 0
fi
# List all but the newest two environments.
OLDEST_ENVIRONMENTS=$(terminus env:list $SITE_ENV --format=list | sort -k2 | cut -d ' ' -f 1 | grep "$MULTIDEV_DELETE_PATTERN" | sed -e '$d' | sed -e '$d')
# Exit if there are no environments to delete
if [ -z "$OLDEST_ENVIRONMENTS" ] ; then
exit 0
fi
# Go ahead and delete the oldest environments.
for ENV_TO_DELETE in $OLDEST_ENVIRONMENTS ; do
terminus multidev:delete $ENV_TO_DELETE --delete-branch --yes
done