首页 > 解决方案 > 接收后挂钩内的 Git 标记

问题描述

为了创建我简单的自动部署脚本,我在我的 git 上创建了一个接收后挂钩,如下所示:

#!/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

但是,我找不到从我的裸存储库中获取从git describe --taglikev0.4-45-g0a0b538到我的 {tag} 的打印值的方法。

php artisan make:version是将文件保存{tag}到我的 .env 文件的命令,稍后它将显示在我的网页上。

我想知道每次我推送主分支时是否有办法获取最新标签并将其保存在我的 .env 文件中。

编辑:

我设法git describe --tags从我的裸存储库中获取输出,但我认为它有点乱,因为我必须复制我的 get worktree 命令。

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)      

标签: bashgitlaravelshell

解决方案


推荐阅读