Files
example_self_tested_lambda/ci/cleanup.sh
Rioting Pacifist b9b3bf572f Initial commit
contains:
* Actual template
* Example function
* Tests
* Integration test (make file)
* Integration tests (deployed as lambda)
* drone CI and CI scripts
2020-03-16 16:33:40 +00:00

24 lines
618 B
Bash

#!/usr/bin/env bash
# Delete a deployed environment after a merge
# checks parent commits for environment/<env>.env
PROTECTED=master
function try_and_delete_environment () {
if [ -f "environments/${1}.env" ]; then
make delete env="${1}"
exit 0
fi
}
MERGED_ENVIRONMENT="${DRONE_SOURCE_BRANCH##*/}"
if [[ ! "$MERGED_ENVIRONMENT" =~ $PROTECTED ]]; then
try_and_delete_environment "$MERGED_ENVIRONMENT"
echo "Checking out parent commits for env file"
for PARENT in $(git log --pretty=%P -n 1 | tac -s ' '); do
git checkout "$PARENT"
try_and_delete_environment "$MERGED_ENVIRONMENT"
done
fi