Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github actions, schedule operation on branch

Tags:

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.

like image 235
Lupyana Mbembati Avatar asked Nov 11 '19 09:11

Lupyana Mbembati


People also ask

What branch does GitHub actions run scheduled jobs on?

Also, be aware that GitHub Actions only runs scheduled jobs on the default branch of your repository (usually master or main ). A quick favor: was anything I wrote incorrect or misspelled, or do you have any questions?

What is a schedule event in GitHub?

The schedule event lets you define a schedule for your workflow to run on. Using the cron syntax, you basically tell GitHub “run this workflow, independent of any activity on the repo - just run it on my schedule.”

How often do you run the GitHub actions workflow?

The above would run the GitHub Actions workflow on every push (to any branch), every pull request (against any branch), and on the cron schedule of every 15 minutes through the day. I typically run my schedules either daily or weekly, depending on how much I need to track the day-to-day changes in my project's underlying dependencies.

What are GitHub actions and how do I use them?

You can use GitHub Actions as a way to run a cron job script, which they’ll run for you for free (as long as you stay within the monthly limits ). Let’s say I’m creating a GitHub Action that runs a Node.js script on a schedule.


1 Answers

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.

like image 69
peterevans Avatar answered Sep 26 '22 01:09

peterevans