41

I am trying to configure a github workflow, I have managed to configure it on push event. However what if I need it to run on after a time period has passed?

What I have understood from the documentation is that it can be achieved using a schedule.

name: Release Management

on: 
  schedule:
   - cron: "*/5 * * * *"

How do I specify the branch that the action will run on ?

My end goal is to automate releases.

Lupyana Mbembati
  • 1,516
  • 2
  • 14
  • 19

1 Answers1

84

If you take a look at the documentation here you will see that the GITHUB_SHA associated with the on: schedule event is "Last commit on default branch." This is what will be checked out by default when you use the actions/checkout action.

If your repository's default branch is master (which in general is the case) this workflow will checkout the last commit on master when it triggers.

name: Release Management
on: 
  schedule:
   - cron: "*/5 * * * *"
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

If you want to checkout a different branch you can specify with parameters on the checkout action. This workflow will checkout the last commit on the some-branch branch.

name: Release Management
on: 
  schedule:
   - cron: "*/5 * * * *"
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: some-branch

See documentation for the actions/checkout action for other options.

peterevans
  • 34,297
  • 7
  • 84
  • 83
  • Maybe there is still a subtle problem, if you don't allow the `master` branch to deploy the essential CI enviornment in repository setting, actions will fail. – Starry-OvO Jan 14 '23 at 14:53
  • specially annoying if you use the workflow both to trigger manually (that allows choosing branch) and schedule. You cannot hardcode a branch in the checkout step otherwise branch option when triggering manually makes no sense – Filipe Pina Mar 23 '23 at 13:51