1

We have a requirement to trigger GitHub Actions pipeline using API and Cron Schedule. We have those changes in default branch and those are working fine but the same changes are not working when comes to feature branch.

Am i missing any config in Github ?

on: 
  schedule:
    - cron: '1 * * * *'
curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer token"\
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/org/repo_name/dispatches \
  -d '{"event_type":"develop-package"}'
karthik
  • 193
  • 1
  • 1
  • 13
  • Does this answer your question? [Github actions, schedule operation on branch](https://stackoverflow.com/questions/58798886/github-actions-schedule-operation-on-branch) – Haridarshan Apr 06 '23 at 13:43

1 Answers1

0

It's not possible to trigger workflows by cron schedule event on branch different than default one (like fature branches). This is expected behaviour according to the documentation:

Scheduled workflows run on the latest commit on the default or base branch.

This should answer the first part of your question. It's not possible to have an on.schedule event triggered on a branch different than your repo default branch. This is why it does not work for your feature branches.

Speaking about the second part of the question. You are trying to manually trigger the workflow by using repository_dispatch webhook event but it seems your workflow is not configured to be triggered this way.

According to the documentation:

When you make a request to create a repository_dispatch event, you must specify an event_type to describe the activity type. By default, all repository_dispatch activity types trigger a workflow to run. You can use the types keyword to limit your workflow to run when a specific event_type value is sent in the repository_dispatch webhook payload.

According to this, the missing part of your workflow configuration configuration is the repository_dispatch event declaration:

on: 
  repository_dispatch:
    types:
      - develop-package

So, to be able to trigger the workflow run using both cron (schedule event) and manually using Github API (repository_dispatch event) you should have both events mentioned in the workflow triggers configuration:

on:
 schedule:
    - cron: '1 * * * *'
  repository_dispatch:
    types:
      - develop-package
Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51