Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}
like image 740
stephennelson Avatar asked Jan 02 '20 08:01

stephennelson


People also ask

Can GitHub Actions be scheduled?

You can configure your workflows to run when specific activity on GitHub happens, at a scheduled time, or when an event outside of GitHub occurs.

Do GitHub Actions jobs run sequentially?

To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .

How do I schedule a GitHub job?

Go to your GitHub repository (create one if required). Go to the Actions tab and create a new action workflow. Add your Cron schedule and task to it. Commit the change.

How do I trigger a GitHub Action with an HTTP request?

These three steps are given below. Create github action. Generate a personal access token. Create a http request.


2 Answers

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?

like image 66
Abbas Hosseini Avatar answered Oct 20 '22 11:10

Abbas Hosseini


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.

like image 37
cortes257 Avatar answered Oct 20 '22 11:10

cortes257