Github action works on push but not scheduled
I am running the example of javascript github actions and it works just fine when I have
on: [push]
but not when I have
on:
schedule:
- cron: '*/5 * * * *'
I expect the github action to run every 5 minutes but it doesn't seem to run at all.
Here is the rest of my code for reference
.github/worflows/main.yml
on:
schedule:
- cron: '*/5 * * * *'
jobs:
hello_world_job:
runs-on: ubuntu-latest
name: A job to say hello
steps:
- name: Hello world action step
id: hello
uses: StephenVNelson/website/@3-experiment-with-actions
with:
who-to-greet: 'Mona the Octocat'
# Use the output from the `hello` step
- name: Get the output time
run: echo "The time was ${{ steps.hello.outputs.time }}"
./action.yml
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
who-to-greet: # id of input
description: 'Who to greet'
required: true
default: 'World'
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'node12'
main: './github-actions/main.js'
./github-actions/main.js
const core = require('@actions/core');
const github = require('@actions/github');
try {
// `who-to-greet` input defined in action metadata file
const nameToGreet = core.getInput('who-to-greet');
console.log(`Hello ${nameToGreet}!`);
const time = (new Date()).toTimeString();
core.setOutput("time", time);
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
As mentioned in the GitHub documentation about Scheduled events
The schedule event can be delayed during periods of high loads of GitHub Actions workflow runs. High load times include the start of every hour. To decrease the chance of delay, schedule your workflow to run at a different time of the hour.
Read further : No assurance on scheduled jobs?
You won't be able to schedule it for every 5 minutes as the "shortest interval you can run scheduled workflows is once every 15 minutes":
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
Change it to '*/15 * * * *' and you'll be fine.