Trigger a workflow from another workflow with GitHub Actions
Learn how to trigger a workflow from another workflow, even from another repository, using a GitHub App token and not personal access tokens.
Note: if you want to trigger a workflow from a workflow present in the same repository, you do not need to create a GitHub App and can skip to Step 3 (and remove the token input from step 4, so that the default ${{ secrets.GITHUB_TOKEN }} is used).
Step 1: Create the GitHub App
- Go to your GitHub account settings and create a new GitHub App.
- Generate a private key for the app and note down the
App ID. - Install the GitHub App on the repository where you want to trigger the workflow.
Step 2: Store the credentials
- Add the
app_idandapp_private_keyas secrets in your repository settings. Name themAPP_IDandAPP_PRIVATE_KEY.
Step 3: Create the triggered workflow
Create a workflow file (e.g., .github/workflows/triggered-workflow.yml) that will be triggered by another workflow.
# my-org/triggered-repo/.github/workflows/triggered-workflow.yml
name: Triggered Workflow
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Run a script
run: echo "This is the triggered workflow"
Step 4: Create the triggering workflow
Create another workflow file (e.g., .github/workflows/triggering-workflow.yml) that will trigger the above workflow.
# my-org/triggering-repo/.github/workflows/triggering-workflow.yml
name: Triggering Workflow
on:
push:
branches:
- main
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Trigger another workflow
uses: benc-uk/workflow-dispatch@v1
with:
workflow: triggered-workflow.yml
token: ${{ steps.generate_token.outputs.token }}
repo: my-org/triggered-repo
ref: main
Explanation
-
Triggered Workflow:
- This workflow (
triggered-workflow.yml) is set to run on theworkflow_dispatchevent, which allows it to be triggered manually or by another workflow.
- This workflow (
-
Triggering Workflow:
- This workflow (
triggering-workflow.yml) runs on a push to themainbranch. - It uses the
actions/create-github-app-token↗ action to generate a GitHub App token using theapp_idandapp_private_keystored in the repository secrets. - It uses the
benc-uk/workflow-dispatch↗ action to trigger thetriggered-workflow.ymlby dispatching a workflow dispatch event. - The
workflowinput specifies the workflow file to be triggered. - The
tokeninput uses the generated GitHub App token. - The
repoinput specify the repository where the event should be dispatched. - The
refinput specifies the branch or tag to use for the triggered workflow run.
- This workflow (
Note
- Ensure the GitHub App has the necessary permissions to dispatch events and is installed on the repository.