Triggering by other repository

Is it possible to run a github action on a push to a 2nd repository?

For example, I have 2 repos:

  • Application
  • Library

As soon as I push to Library, I would like the Library CI to run, but also run the CI for the Application, to see if the application still works with the changes in the Library.

Triggers are per-repository, _however _you could send a “repository dispatch” event to your Application repository.  This is a custom event type that has no explicit meaning within GitHub, that you can use for your own purposes.

So in the application’s workflow, you could listen for a repository dispatch event:

on: repository_dispatch

And then in the library’s workflow, you could send a repository dispatch event.  You’ll need to set up a personal access token as a secret in the library’s repository:

run: |
curl -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/YOURNAME/APPLICATION_NAME/dispatches --data '{"event_type": "build_application"}'

Replace YOURNAME/APPLICATION_NAME with the name of your github repository for your Application.

Set up a secret named PAT_USERNAME with your username, and PAT_TOKEN with the personal access token that you created (it needs repo level access).

23 Likes

Thanks. I’ve accepted it as a sollution.

Even if it doesn’t really work for my specific usecase, it does seem like a valid way to solve my question.

I have 1 library that is used by about 10 different repositories. And I don’t want to add knowledge about those external repositories to my main library repository. My home grown CI solution currently allows this “watch link”, but I understand that it’s a bit of an odd usecase.

I don’t agree that this is a “odd” usecase.

Actually it is very common that builds in upstream projects (e.g. libraries) should also trigger a build. Especially true in the CD world.

14 Likes

Is it possible to go the other way.

If my repository depends on 4 other repos can an action be triggered if one of them has a commit action (to the master for example.)?

1 Like