Skip GitHub Action workflow if it has been executed before on the same commit

Currently, I have a nightly workflow which I’ve configured to be triggered with the schedule event set to every day at 12:00AM UTC.

However, this workflow is usually associated with the latest commit, resulting in multiple builds of the same artifacts. Is there any way to prevent this?

You can view the source code of the workflow here.

Just to be clear: you basically want to avoid running your nightly build if there’s been no change to the master branch since the last time it ran?  There’s currently not any syntax to do that easily.

1 Like

@ethomson wrote:

Just to be clear: you basically want to avoid running your nightly build if there’s been no change to the master branch since the last time it ran?  There’s currently not any syntax to do that easily.

Yup, that’s exactly what I meant.

@edricchan03, could you query your artifacts with the download-artifact action to determine the commit sha they were last built with?

For example, if an artifact included the short hash of a commit in its name, like “my-artifact-03fh5v” and if the current commit hash is 03fh5v then don’t rebuild.

Similarly, if you don’t want to put the commit hash as part of the name, perhaps you could publish as an artifact a text file that contains the commit it was built with. Your build job would query that file and compare the commit hashes. If the same, don’t do anything.


Originally I was going to suggest using @actions/cache but then read one of the limitations is that the cache is only available for push and pull_request events, not scheduled.

2 Likes