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: