Trying on SO too, after the Travis forum.
I’ve a quite big project, which takes long time to build. Because of that, I don’t want it to be rebuilt upon every Github pushed change. At the same time, I’d like to build it automatically every day, but only if there have been GitHub changes since the last build. Scheduling a daily rebuild in Travis doesn’t seem to achieve such a result, the repo is rebuilt daily anyway, even if the code on GH is exactly the same as the day before. Rebuilding a big unchanged codebase for nothing isn’t very good.
Is there a way to obtain that in Travis? Should I file a new feature request?
OK, strangely, it doesn't seem an interesting problem, so I had to find some sort of solution on my own.
As far as I can understand, Travis doesn't support such a feature (I don't know why, it's pretty basic to me), but it offers an environment variable to know what triggered the build. Which can be combined with git log
:
if [[ "$TRAVIS_EVENT_TYPE" == "cron" ]]; then
nchanges=$(git log --since '24 hours ago' --format=oneline | wc -l)
if [[ $(($nchanges)) == 0 ]]; then
cat <<EOT
This is a cron-triggered build and the code didn't change since the
latest build, so we're not rebuilding.
This is based on github logs (--since '24 hours ago'). Please,
launch a new build manually if I didn't get it right.
EOT
exit
fi
fi
This isn't perfect, cause the whole VM and its environment are bringed up anyways, and the Travis logs show the event without distinguishing it from any other build. But, until I find a better solution, at least this is better than building every day for nothing (or building many times a day, even against minimal changes).