linux - 检查 git 提交是否是一天的第一天的脚本

标签 linux git shell travis-ci

任务如下:

  • 在构建服务器 (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/

相关文章:

linux - 接受用户输入并添加到 bash 脚本中的文件中

c++ - LabVIEW Linux C++开发——初学者问题

git - 如何返回:Gblame after selecting a particular commit?的结果

git - 我如何让 git 显示 vim 中的更改,就像 hg 对 hgeditor 脚本所做的那样?

bash - bash/zsh 脚本中 "case"语句的奇怪语法的原因是什么?

linux - 如何禁止在 bash 中编辑我的历史记录

linux - Linux 端口中每秒的请求数

linux - shell 脚本 1 : [: [: unexpected operator

git - 如何抑制 "Changes not staged for commit"?

linux - 我应该使用 user_data 还是 Ansible 配置我的 EC2