From 1b6861cdbb819cf4206f48d65c676334cb2917de Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 3 Apr 2022 13:20:50 -0400 Subject: [PATCH] feat: add plugin trigger for checking if an app has code This will allow us to short-circuit build processes that would otherwise be triggered due to various commands in Dokku. --- docs/development/plugin-triggers.md | 14 ++++++++++++++ plugins/git/git-has-code | 18 ++++++++++++++++++ plugins/git/internal-functions | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100755 plugins/git/git-has-code diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 9014822f7..4326d8adb 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -774,6 +774,20 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `git-has-code` + +- Description: Checks to see if there is code at the specified branch +- Arguments: `$APP $BRANCH_NAME` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `git-post-pull` - Description: diff --git a/plugins/git/git-has-code b/plugins/git/git-has-code new file mode 100755 index 000000000..083120278 --- /dev/null +++ b/plugins/git/git-has-code @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-git-git-has-code() { + declare desc="checks if there is code at a specific branch" + declare trigger="git-has-code" + declare APP="$1" BRANCH_NAME="$2" + + if fn-git-has-code "$APP" "$BRANCH_NAME"; then + return 0 + fi + + return 1 +} + +trigger-git-git-has-code "$@" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 845a64370..43f545d23 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -405,6 +405,22 @@ fn-git-fetch() { fn-git-cmd "$APP_ROOT" config --add core.bare true } +fn-git-has-code() { + declare desc="checks if there is code at a specific branch" + declare APP="$1" DOKKU_DEPLOY_BRANCH="$2" + + if [[ -z "$DOKKU_DEPLOY_BRANCH" ]]; then + DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" + fi + + local HEAD_FILE="$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH" + if [[ -f "$HEAD_FILE" ]]; then + return 0 + fi + + return 1 +} + fn-git-last-updated-at() { declare desc="retrieve the deploy branch for a given application" declare APP="$1"