How do I trigger a scheduled action on a specific branch?

Viewed 2464

I've made an action. I'd like for this to run on branch foo at a schedule(in my case, twice a day).

Here's what I've got so far:

repo/.github/workflows/daily-foo-tests.yml

name: Run integration tests on foo branch twice a day
on:
  schedule:
    # Execute at 00:01 and 13:01 UTC daily
    - cron:  '00 01,13 * * *'

jobs:
  build:
    name: Run UI Automation
    runs-on: [self-hosted, macOS, X64]
    steps:
      - uses: actions/checkout@v2
      - name: dotnet build
        with: { ref: foo }
        // continues to do stuff, not important

Now, this action has been pushed to said foo branch. However, going to github.com/org/repo/actions, it does not trigger(I've waited 24 hours now; it should've done something at this point).

What is the correct way to trigger a scheduled github action workflow on a specified branch?

1 Answers

The workflow must be committed to the default branch to be triggered. It won't work if you only commit it to a non-default branch.

Scheduled workflows run on the latest commit on the default or base branch.

ref: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule

For example, this should be committed to the default branch. When it runs, it checks out branch foo and then you can build, test, etc.

on:
  schedule:
    - cron:  '0 1 * * 4'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: foo
      
      # Build steps go here
Related