任务如下:
- 在构建服务器 (travis-ci) 上,我想检查推送是否是白天的第一次
- 如果是,将主分支复制到另一个分支(每日快照)
最好的问候
最佳答案
在构建脚本的末尾,您可以将日期转储到文件中。一开始,你可以比较一下。它可能看起来像:
currentDate=$(date +%D)
isFirstBuildOfTheDay=true
if [ -e last_date_build.txt ]; then
if [ $currentDate = $(cat last_date_build.txt) ]; then
isFirstBuildOfTheDay=false
fi
fi
if $isFirstBuildOfTheDay; then
#Take a daily snapshot
fi
#Perform the actual build
echo $currentDate > last_date_build.txt
编辑以考虑评论:
如果你不能保留文件,将这个日期记录在标签上怎么样?
例如:
currentDate=$(date +%F)
dailyTag=daily_$currentDate
if ! git rev-parse $tag >/dev/null 2>&1; then
#Take a daily snapshot
git tag $dailyTag
git push --tags
fi
关于linux - 检查 git 提交是否是一天的第一天的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23322014/