feat: add ability to only build synced repo if there are changes

Closes #6242
This commit is contained in:
Jose Diaz-Gonzalez
2024-03-14 03:49:46 -04:00
parent e470a880f9
commit 4de97a1094
3 changed files with 88 additions and 2 deletions

View File

@@ -179,6 +179,7 @@ cmd-git-sync() {
local cmd="git:sync"
[[ "$1" == "$cmd" ]] && shift 1
declare APP GIT_REMOTE GIT_REF FLAG
local CURRENT_REF DOKKU_DEPLOY_BRANCH SHOULD_BUILD UPDATED_REF
ARGS=()
for arg in "$@"; do
@@ -187,6 +188,11 @@ cmd-git-sync() {
continue
fi
if [[ "$arg" == "--build-if-changes" ]]; then
FLAG="--build-if-changes"
continue
fi
ARGS+=("$arg")
done
@@ -202,6 +208,11 @@ cmd-git-sync() {
fi
local APP_ROOT="$DOKKU_ROOT/$APP"
DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
CURRENT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)"
dokku_log_verbose "Current ref for $APP is $CURRENT_REF"
if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then
dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF"
fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF"
@@ -209,7 +220,22 @@ cmd-git-sync() {
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
fi
UPDATED_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)"
dokku_log_verbose "Updated ref for $APP is $UPDATED_REF"
local SHOULD_BUILD=false
if [[ "$FLAG" == "--build" ]]; then
SHOULD_BUILD=true
elif [[ "$FLAG" == "--build-if-changes" ]]; then
if [[ "$CURRENT_REF" == "$UPDATED_REF" ]]; then
dokku_log_verbose "Skipping build as no changes were detected"
return
fi
SHOULD_BUILD=true
fi
if [[ "$SHOULD_BUILD" == "true" ]]; then
if [[ -n "$GIT_REF" ]]; then
GIT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$GIT_REF")"
plugn trigger receive-app "$APP" "$GIT_REF"