This uses the repository_dispatch event to enable a workflow in one repository (the “from” repo) to trigger a workflow run in another (the “to” repo).

Setup requirements

Generate a new fine-grained Personal Access Token scoped to the “to” repo with write access to the Contents.

Store this PAT as a repo secret in the “from” repo. You may also want to store the repository user/path information of the “to” repo (as $username/$repository). The below example uses secrets.REPO_PAT and secrets.REPO_NAME for this.

”from” workflow

name: Trigger remote workflow
 
on:
  push: # triggers for all pushes, adjust as needed
 
defaults:
    run:
      shell: bash
 
jobs:
  trigger:
    runs-on: ubuntu-latest
    steps:
      - name: Remote trigger
        run: |
          curl -X POST \
            -H "Authorization: token ${{ secrets.REPO_PAT }}" \
            -H "Accept: application/vnd.github.v3+json" \
            https://api.github.com/repos/${{ secrets.REPO_NAME }}/dispatches \
            -d '{"event_type": "remote-trigger"}'

”to” workflow

name: Workflow which is trigger remotely
 
on:
  repository_dispatch: # triggers from API dispatches
 
defaults:
  run:
    shell: bash
 
jobs:
  execute:
    runs-on: ubuntu-latest
    steps:
      - name: remotely triggered run
        run: |
          echo "repository_dispatch triggered"

See also: