To create i simple auto deploy script,i have created a post-receive hook on my git like below :
#!/bin/sh
GIT_DIR="/srv/git/test.git"
TARGET="/srv/www/laravel"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [[ $ref = refs/heads/$BRANCH ]] ;
then
echo "Ref $ref received. Deploying ${BRANCH} branch to ${TARGET}"
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
#expecting value from git describe --tag like v0.4-45-g0a0b538
pushd $TARGET
echo {tag}
php artisan make:version {tag}
popd
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
However, I cannot find a way to get the printed value from git describe --tag
like v0.4-45-g0a0b538
to my {tag} from my bare repository.
php artisan make:version
is a command to save the {tag}
to my .env file which later on, it will display to my web page.
I wonder if there is a way to get the latest tag every time i pushed on master branch and save it in my .env file.
Edited :
I manage to get the git describe --tags
output from my bare repository but i think it is a little bit messy since i have to duplicate my get worktree command.
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
pushd $TARGET > /dev/null
php artisan iapms:version $(git --work-tree=$TARGET --git-dir=$GIT_DIR describe --tags)