Add devcpone sync hook

This commit is contained in:
sas.fajri
2026-04-27 10:39:06 +07:00
parent 8ba3d33c6d
commit c11b8935a0
2 changed files with 50 additions and 0 deletions

8
.githooks/post-commit Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -eu
repo_root=$(git rev-parse --show-toplevel)
if ! "$repo_root/scripts/devcpone_sync.sh"; then
printf '%s\n' "devcpone sync skipped/failed; commit kept intact" >&2
fi

42
scripts/devcpone_sync.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/sh
set -eu
repo_root=$(git rev-parse --show-toplevel)
branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null || true)
case "$branch" in
master|main)
;;
*)
exit 0
;;
esac
remote_host=${DEVCPONE_REMOTE_HOST:-one@devcpone.aplikasi.web.id}
remote_root=${DEVCPONE_REMOTE_ROOT:-/home/one/project/one/one-api}
ssh_key=${DEVCPONE_SSH_KEY:-/Users/fajrihardhitamurti/id_rsa}
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/devcpone-sync.XXXXXX")
trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM
manifest="$tmpdir/files.list"
if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
git diff -M --name-only -z --diff-filter=ACMR HEAD^ HEAD > "$manifest"
else
git ls-files -z > "$manifest"
fi
if [ ! -s "$manifest" ]; then
exit 0
fi
ssh_cmd="ssh"
if [ -f "$ssh_key" ]; then
ssh_cmd="$ssh_cmd -i $ssh_key"
fi
ssh_cmd="$ssh_cmd -o BatchMode=yes"
ssh "$remote_host" "mkdir -p '$remote_root'" >/dev/null
rsync -a --relative --from0 --files-from="$manifest" -e "$ssh_cmd" "$repo_root"/ "$remote_host:$remote_root"/