commit a5bf9b3e233df3f782b43364462930d4d3c704e9
parent b7f6084cd641f11e1b6cd517bf330751b423f5cc
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Mon, 17 Jun 2024 19:44:38 +0200
feat: always run deployment on new tags if "git-hook-deploy" rule is present
Diffstat:
2 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/bin/git_deploy.sh b/bin/git_deploy.sh
@@ -13,7 +13,8 @@ if [ -z "$3" ]; then
git_deploy.sh \\
\"/var/www/git.example.git\" \\
\"pub\" \\
- \"stagit-jayvii.de\"
+ \"stagit-jayvii.de\" \\
+ \$@ # optional parameters given by post-update hook
"
exit 1;
fi
@@ -31,22 +32,40 @@ for REF in $@; do
# fetch newest tag from given ref
TAG=`git tag --contains $REF | tail -n 1 | awk '{ print $NF }'`
- # cycle through branches and tags
+ # check whether a tag was given
if [ ! -z $TAG ]; then
- # create archive
- git archive ${TAG} . \
- --format=tar.gz \
- -o "${TAG}.tar.gz"
-
+ # fetch the archive from previous export via git_export_tarball.sh
+ if [ -f "${1}/${2}${3}/exports/${TAG}.tar.gz" ]; then
+
# extract archive to temporary directory
TMPDIR=`mktemp --directory`
- tar xfvz "${TAG}.tar.gz" --directory "${TMPDIR}/" > /dev/null
+ tar xfvz "${1}/${2}${3}/exports/${TAG}.tar.gz" \
+ --directory "${TMPDIR}/" > /dev/null
+
+ MAKE_STATUS=0
+
+ # check whether Makefile exists
+ if [ -f "${TMPDIR}/Makefile" ]; then
+
+ # check whether Makefile contains the git-hook-deploy rule
+ if [ ! -z $(grep "git-hook-deploy" "${TMPDIR}/Makefile") ]; then
+
+ # run deployment
+ cd "$TMPDIR"
+ make git-hook-deploy > /dev/null
+ MAKE_STATUS=$?
- # run deployment in temporary directory
- cd "$TMPDIR"
- make git-hook-deploy > /dev/null
- MAKE_STATUS=$?
+ # User output
+ if [ $MAKE_STATUS -gt 0 ]; then
+ echo "Version ${TAG} has been deployed"
+ fi
+
+ fi
+
+ fi
+
+ # clean up
rm -r "$TMPDIR"
# error handling
@@ -54,9 +73,6 @@ for REF in $@; do
exit 1
fi
- # Output for user
- echo "Version ${TAG} has been deployed"
-
fi
done
diff --git a/bin/git_post_push.sh b/bin/git_post_push.sh
@@ -21,6 +21,7 @@ fi
~/bin/git_update_repo.sh "${1}" "${2}" "${3}"
~/bin/git_export_tarball.sh "${1}" "${2}" "${3}" $@
+~/bin/git_deploy.sh "${1}" "${2}" "${3}" $@
~/bin/git_update_repo_html.sh "${1}" "${2}" "${3}"
~/bin/git_update_index_html.sh "${1}" "${2}"