From 863ce8e612142ef2c13bf17e12c3ccab147be59e Mon Sep 17 00:00:00 2001 From: Steve Persch Date: Tue, 9 Jun 2020 10:18:24 -0500 Subject: [PATCH] Only call terminus -n build:env:delete:ci and terminus -n build:env:delete:pr when the current build will make a new multidev (#43) * working on cleanup logic * deletion checker * updating multidev deletion logic * fixing indenting * fixing error * removing testing files * Delete contains-check.sh --- src/@orb.yml | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/@orb.yml b/src/@orb.yml index 36dfe43..2023717 100644 --- a/src/@orb.yml +++ b/src/@orb.yml @@ -127,9 +127,35 @@ jobs: paths: - $PANTHEON_REPO_DIR + # terminus build:env:delete can take around a minute. + # So only run it when the current build needs to + # make a new Multidev environment. - run: - name: Delete old Multidevs to make space for a potential new one - command: terminus -n build:env:delete:ci "$TERMINUS_SITE" --keep=2 --yes + name: Delete old Multidevs if this build needs to create a new one + command: | + if [[ $TERMINUS_ENV = ci-* || $TERMINUS_ENV = pr-* ]] + then + echo "May need to delete old ci- or pr- environments to make room for this one" + echo "Getting list of all environments" + export ENV_LIST=$(terminus env:list $TERMINUS_SITE --field=id) + echo "Checking if current environment is in list of existing environments" + if [[ $(echo "${ENV_LIST}" | grep -x ${TERMINUS_ENV}) ]] + then + echo "${TERMINUS_ENV} found in the list of environments" + exit 0 + else + echo "${TERMINUS_ENV} not found in the list of environments." + echo "Running clean-up script to delete old pr- environments" + terminus -n build:env:delete:pr "$TERMINUS_SITE" --yes + if [[ $TERMINUS_ENV = ci-* ]] + then + echo "Running clean-up script to delete old ci- environments" + terminus -n build:env:delete:ci "$TERMINUS_SITE" --keep=2 --yes + else + echo "Skipping deletion of ci- envs" + fi + fi + fi - run: name: Copy code to the local clone of the Pantheon repository @@ -162,7 +188,6 @@ jobs: # Delete old multidev environments associated with a PR that has been # merged or closed. terminus -n build:env:delete:pr "$TERMINUS_SITE" --yes - # @todo, Check back with CircleCI DevRel team. They mentioned possibly # adding a CircleCI-maintained Orb step to do this concept. - run: