Trigger action on.schedule only if there are changes to the branch

I would like to run an Action once every 24 hours, only if commits have been made to the target branch in the last 24 hours (or since the last run). This is for calculating code coverage on a large repo, which takes about 20-30 mins.

I can find documentation for on.schedule ( but not for checking the date/time of the latest commit.

1 Like

Hey @nheath99, this is not a functionary that is supported out of the box. I suggest adding in an additional piece to the action that uses Python or another language to check the git contents to see if there’s a commit in the last 24 hours. 

1 Like

Hi @nheath99 ,

You can use ‘schedule’ event, and in the job check the last commit time via script in the link:

If the last commit is in 24hours, execute your steps, otherwise skip it(use if expression to skip the job ).



you can do something like this:

  1. first add this job:
    runs-on: ubuntu-latest
    name: Check latest commit
      should_run: ${{ steps.should_run.outputs.should_run }}
      - uses: actions/checkout@v2
      - name: print latest_commit
        run: echo ${{ github.sha }}

      - id: should_run
        continue-on-error: true
        name: check latest commit is less than a day
        if: ${{ github.event_name == 'schedule' }}
        run: test -z $(git rev-list  --after="24 hours"  ${{ github.sha }}) && echo "::set-output name=should_run::false"
  1. add this to all other jobs in your workflow:
    needs: check_date
    if: ${{ needs.check_date.outputs.should_run != 'false' }}

for example:

    needs: check_date
    if: ${{ needs.check_date.outputs.should_run != 'false' }}
    runs-on: windows-latest
    name: do something.
      - uses: actions/checkout@v2