stephennelson
stephennelson

Reputation: 503

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);
}

Upvotes: 47

Views: 18318

Answers (3)

cortes257
cortes257

Reputation: 97

(Editor's note: For the future readers, do read the comment of this answer for an update of the frequency.)

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.

Upvotes: 8

Jithil P Ponnan
Jithil P Ponnan

Reputation: 1247

I recommends to use some trigger apps like IFTTT, Zappier or even AWS Lamda functions etc to handle this case.

Github actions docs says that the cron job scheduled may not work as expected and its a known issue.

If you want to do some critical tasks on time like release the code everyday 8:30 AM , merge the master to other branches on midnight etc can be handled using the apps mentioned above.

Upvotes: 1

Abbas Hosseini
Abbas Hosseini

Reputation: 1643

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?

Upvotes: 6

Related Questions