the task is as follows:

  • on a build server (travis-ci) I'd like to check if a push was a first during the day
  • if yes, copy the master branch to a another one (daily snapshot)

Best regards

有帮助吗?

解决方案

At the end of your build script you could dump the date in a file. And at the beginning, you could compare it. It could looks like:

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

Edit to take the comment into account:

If you can't keep files, what about recording this date on a tag?

For example:

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top