Last active
August 25, 2023 21:11
-
-
Save Daniel-ltw/552b90800b07c22e4a83dfa68ada6318 to your computer and use it in GitHub Desktop.
Github Actions repository_dispatch example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Artifacts | |
on: [push] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
with: | |
fetch-depth: 1 | |
- name: call the other repo | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
EVENT: YOUR_EVENT_TYPE | |
ORG: YOUR_ORG_NAME | |
REPO: YOUR_REPO_NAME | |
run: | | |
curl -d "{\"event_type\": \"${EVENT}\"}" -H "Content-Type: application/json" -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.everest-preview+json" "https://api.github.com/repos/${ORG}/${REPO}/dispatches" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: dispatch receiver | |
on: [repository_dispatch] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
- name: dispatch trigger | |
if: github.event.action == "YOUR_EVENT_TYPE" | |
run: | | |
echo "repository_dispatch triggered" |
@big-andy-coates Exceptions have been made for using GITHUB_TOKEN for workflow_dispatch and repository_dispatch - https://github.blog/changelog/2022-09-08-github-actions-use-github_token-with-workflow_dispatch-and-repository_dispatch/
Oh that's now a lot easier - thanks for the update @whsalazar !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this to work with the latest Github workflows you can't use
secrets.GITHUB_TOKEN
when triggering another workflow. If you do, Github will ignore the request. This is to avoid infinite loops. Instead, you will need to set up an access token, store it in your repo or orgs secrets and reference that instead.Docs: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow