How to skip a nightly build if nothing changed during the day?

I am setting up nightly build for my hobby project. I want to have a nightly release, but only when the code was changed during the day. Is there a best practice for this?

Now I set it up like following:

  1. A “primary” workflow, triggered by push on master, runs all tests, codecov, etc.
  2. A “release” workflow, triggered by tag push.
  3. A “prepare-release” workflow, scheduled nightly:
# Load versionCode of last release

# Skip release if nothing changed since last release
git fetch --tags
[ "release-${versionCode}" = "$(git tag --list --points-at HEAD)" ] && echo "Nothing changed since release-${versionCode}. Skipping release." && exit 0

# Step versionCode and create tag
sed --regexp-extended --in-place 's/^(versionCode=)([0-9]+)$/echo "\1$((\2+1))"/ge'
git commit --message="Prepare for release-${versionCode}"
git tag release-${versionCode}

# By pushing this tag, "release" workflow is triggered
git push origin --tags :

The problem is, every time a new tag is pushed, the “primary” workflow is also triggered, unnecessarily. And if push with [skip ci], “release” won’t be triggered either.

1 Like

Hi @sah,

Not sure if there’s a simple solution for this, as you actually do a code change on the master branch, even if it’s as trivial as changing a version code; a CI is meant to test every code change.

If possible, although this requires some changes in how you work, I’d suggest you to either do release on master branch changes, or not to commit back the version bump, instead rely on the tag, e.g. use the tag in the release build as the version.

Of course there’s no problem with your setup either, but that will trigger both the “test” (primary) build (due to the code change), as well as the release due to the tag, as you perform both actions.

Great question btw! :wink:

I guess it’s possible to write a script which would run as the first step of the primary workflow and abort/cancel it if the only change was the release bump… But that seems quite hacky :thinking:

Thanks for replying. Cancelling in the first step of primary will make that build shown as failed and I want to avoid that. But your advice on reading versionCode from git tag is indeed something worth trying.

1 Like