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.
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?
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.”
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With