bash - 接收后挂钩内的 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 --tag
likev0.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)
解决方案
推荐阅读
- dart - 如何修复“在 Flutter 中未获取 SignInWithgoogle 属性”
- msbuild - 如何根据主要版本安装 NuGet 包
- laravel-5.2 - 用户首次使用 Laravel PWA 成功登录时如何处理身份验证?
- java - 带值的 JavaFX 折线图
- python - TypeError: 'list' 和 'int' Python 的实例之间不支持'>'
- ruby-on-rails - Rails:update_attributes 不尊重依赖::destroy
- java - 新更新后如何安装 oracle-java8-installer
- asp.net-mvc - 如何在视图中仅显示用户名角色?
- javascript - 括号之间的关键字后的正则表达式匹配字符串
- angular - toString() 在打字稿文件中做了什么?