Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 4

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.

3 Replies
GitHub Staff
Message 2 of 4

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

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.

Copilot Lvl 2
Message 3 of 4

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


@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.

Copilot Lvl 2
Message 4 of 4

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

@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.