pub / stagit-scripts

Building src.jayvii.de with stagit
git clone https://src.jayvii.de/pub/stagit-scripts.git
Home | Log | Files | Exports | Refs | README | RSS

commit b0da2fdd34e02f67ac71032c86c95ad204c7cfd7
parent 898fb5fa2a788cc10522a009a8d1ffe37d9d7e87
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sat, 15 Jun 2024 21:53:17 +0200

feat: add automatic deployment feature

Diffstat:
MMakefile | 22+++++++++-------------
Abin/git_deploy.sh | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,16 +1,12 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de> -# Create Package ready for deployment -package: - git archive main . \ - ":!LICENSES" \ - ":!LICENSE" \ - ":!examples" \ - ":!README" \ - ":!.reuse" \ - ":!.git" \ - ":!.gitignore" \ - ":!Makefile" \ - --format=tar.gz \ - -o "deployable.tar.gz" +# Deployment for git post-update hook +git-hook-deploy: + rsync -av ./ ~/ \ + --exclude=".git/*" \ + --exclude=".resue/*" \ + --exclude="examples/*" \ + --exclude="LICENSE/*" \ + --exclude="Makefile" \ + --exclude="README" diff --git a/bin/git_deploy.sh b/bin/git_deploy.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env sh +# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-FileCopyrightText: 2021-2024 JayVii <jayvii[AT]posteo[DOT]de> + +# $1 - HTML Root +# $2 - prv/pub +# $3 - repo name +# $@ - optional list of refs, as given to post-update hook + +# Error out if not all options are given +if [ -z "$3" ]; then + echo "Usage: +git_deploy.sh \\ + \"/var/www/git.example.git\" \\ + \"pub\" \\ + \"stagit-jayvii.de\" + " + exit 1; +fi + +for REF in $@; do + + # Git-Repository + cd "${1}/${2}/${3}.git" + + # skip first three parameters + if [ "$REF" = "$1" ] || [ "$REF" = "$2" ] || [ "$REF" = "$3" ]; then + continue + fi + + # fetch newest tag from given ref + TAG=`git tag --contains $REF | tail -n 1 | awk '{ print $NF }'` + + # cycle through branches and tags + if [ -z $TAG ]; then + + # create archive + git archive ${TAG} . \ + --format=tar.gz \ + -o "${TAG}.tar.gz" + + # extract archive to temporary directory + TMPDIR=`mktemp --directory` + tar xfvz "${TAG}.tar.gz" --directory "${TMPDIR}/" > /dev/null + + # run deployment in temporary directory + cd "$TMPDIR" + make git-hook-deploy > /dev/null + MAKE_STATUS=$? + rm -r "$TMPDIR" + + # error handling + if [ $MAKE_STATUS -gt 0 ]; then + exit 1 + fi + + # Output for user + echo "Version ${TAG} has been deployed" + + fi + +done +