diff --git a/README.md b/README.md index 848957a..0547333 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ If you have an existing `fly.toml` in your repo, this action will copy it with a | `org` | Which Fly organization to launch the app under. Alternatively, set the env `FLY_ORG`. Defaults to `personal`. | | `path` | Path to run the `flyctl` commands from. Useful if you have an existing `fly.toml` in a subdirectory. | | `postgres` | Optional name of an existing Postgres cluster to `flyctl postgres attach` to. | +| `postgres_clean_on_close` | Drop database and role on Pull Request close event (default false) | | `update` | Whether or not to update this Fly app when the PR is updated. Default `true`. | | `secrets` | Secrets to be set on the app. Separate multiple secrets with a space | | `vmsize` | Set app VM to a named size, eg. shared-cpu-1x, dedicated-cpu-1x, dedicated-cpu-2x etc. Takes precedence over cpu, cpu kind, and memory inputs. | diff --git a/action.yml b/action.yml index e5cd725..4c30d5c 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,9 @@ inputs: description: path to a directory containing a fly.toml to clone postgres: description: Optionally attach the app to a pre-existing Postgres cluster on Fly + postgres_clean_on_close: + description: Drop database and role on Pull Request close event (default false) + default: false secrets: description: Secrets to be set on the app. Separate multiple secrets with a space vmsize: diff --git a/entrypoint.sh b/entrypoint.sh index 3ac92ee..77ca6a3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,6 +27,8 @@ config="${INPUT_CONFIG:-fly.toml}" build_args="" build_secrets="" runtime_environment="" +database_name="${app/-/_}_pg" +database_role="${app/-/_}_pg" if ! echo "$app" | grep "$PR_NUMBER"; then if [ "$INPUT_ALLOW_UNSAFE_NAME" != "true" ]; then @@ -39,6 +41,15 @@ fi # PR was closed - remove the Fly app if one exists and exit. if [ "$EVENT_TYPE" = "closed" ]; then flyctl apps destroy "$app" -y || true + + if [ "$INPUT_POSTGRES_CLEAN_ON_CLOSE" == "true" && -n "$INPUT_POSTGRES" ]; then + flyctl postgres connect --app "$INPUT_POSTGRES" <