Erdss4
Erdss4

Reputation: 1125

Is it possible to trigger a GitHub action to a different repository?

If I have a public repo which has a workflow setup to be triggered when something is pushed to master, can I then trigger another workflow from a different repo to trigger?

The reason I want to do this is because my public repo is used to allow anyone to contribute but I want to make another repo which is private that handles the build process/deployment that can't be seen. Is there a better way to handle this kind of use case with GitHub actions? - I basically don't want my build process on my server to be public.

Upvotes: 5

Views: 6114

Answers (2)

Erdss4
Erdss4

Reputation: 1125

From doing more research I found this marketplace plug-in which solves what I want and calls another repository which triggers another build which is a private repository, you can enter a name of your choice and have a front facing repo which is public and keep all your CI/CD stuff in a private repo:

https://github.com/marketplace/actions/dispatch-action (Deprecated, use https://github.com/marketplace/actions/repository-dispatch instead)

Upvotes: 7

Eyal Sooliman
Eyal Sooliman

Reputation: 2268

name: Trigger automation tests
steps:
- uses: actions/github-script@v6
  with:
    github-token: ${{ secrets.PERSONAL_TOKEN }}
    script: |
      await github.rest.actions.createWorkflowDispatch({
       owner: '*****',
       repo: '*****',
       workflow_id: '*****.yml',
       ref: 'main'
      })
  1. Create personal access token in target repository.
  2. Add this personal access token as secret in both repositories.
  3. Create a new workflow or edit one which is already exists (yml file).
  4. Add the above step to yml file.

owner = organization / personal gitHub.

repo = target repository to run.

workflow_id = yml file name of the target workflow.

ref = which brench to run in target repository

Upvotes: 5

Related Questions