peter-evans / repository-dispatch Goto Github PK
View Code? Open in Web Editor NEWA GitHub action to create a repository dispatch event
License: MIT License
A GitHub action to create a repository dispatch event
License: MIT License
note that you no longer need to leak a PAT in order to do dispatch, as you can add the actions: write
permission to the workflow to elevate the scope.
I have a main workflow which triggers multiple repos having repository dispatch. Is it possible to put a condition to check if repository dispatch is not present in any of the downstream repos then that repository execution can be skipped by main workflow? If not, then how to handle conditional scenarios with repository dispatch?
I have this job below on workflow one which will supposedly trigger another workflow which resides on the master branch on another repo.
This workflow is being triggered everytime a push event is captured on 'develop' branch
name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: same-user/another-repo
event-type: trigger-deployment
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
It's triggering just fine but it's failing to run because workflow2 is looking for develop branch on my other repo which is not existent.
Is there a way to tell what branch is going to be triggered?
Not work for me
According to the documentation the repository_dispatch
event doesn't use the types
property.
This event does not have additional activity types so it does not support the
types
keyword.
Should the example be:
name: Repository Dispatch
on: repository_dispatch
jobs:
myEvent:
if: github.event.action == 'my-event'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.client_payload.ref }}
- run: echo ${{ github.event.client_payload.sha }}
or does it work with the types
property?
Is there an event to listen for when something is pushed to an outside repository within my organization?
I am trying to build a workflow that pushes a tag to a repository anytime a new repository is created and pushed to. I don't know when the repository will be created or who will create it. And I need to execute the workflow I have from outside of the repository I want to add the tag to. Is this possible?
name: Check Github Tags
on: push
jobs:
check-git-tags:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Print Repository info
run: |
echo 'Commit:' $GITHUB_SHA
echo 'Repository:' $GITHUB_REPOSITORY
echo 'Workspace:' $GITHUB_WORKSPACE
echo 'Ref:' $GITHUB_REF
git tag
- name: Push new tag
id: push_new_tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: test2
- name: Print New Tag Added
run: echo 'New tag' ${{steps.push_new_tag.outputs.new_tag}} 'added to commit' $GITHUB_SHA 'in' $GITHUB_REPOSITORY.
Hi, I have a request like below:
below is my yaml
Benchmarks_Test:
name: Build Modified
runs-on: [ self-hosted, Linux, X64, package-for-linux ]
strategy:
matrix:
repeat: [1, 2]
continue-on-error: true
concurrency:
group: Benchmarks_Test_${{matrix.repeat}}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
event-type: do-something
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
- name: check each do-something status by run id
What I've got:
The workflow step:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REDACTED_SECRET_NAME }}
repository: redacted-org/redacted-repo
event-type: redacted-event-name
client-payload: '{"repo": "${{ github.repository }}", "release_id": "${{ steps.create_release.outputs.id }}", "chart_name": "${{ env.HELM_CHART_NAME }}"}'
The repository is defined as org-name/repo-name, and is spelled correctly.
The error:
Error: Repository not found, OR token has insufficient permissions.
At this point, there is no higher permissions to give on either the user (which is part of the private org), or the PAC used in the workflow. Not sure what else to check. Thoughts?
@peter-evans I was wondering if it would be possible to leverage repository-dispatcher
to enable public repositories to call pipelines from another repository whose visibility setting is set to internal or private? If not with dispatcher, have you seen any solutions or have any recommendations on how to accomplish this?
in the example, client-payload
is kebab-case
with:
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
but in the receiving repository's workflow, this property is referenced in snake_case:
with:
ref: ${{ github.event.client_payload.ref }}
- run: echo ${{ github.event.client_payload.sha }}
I can see in the source what's happening - you've decided expect an input of client-payload
but GitHub's API requires it be client_payload
when sending this data through its API.
If this were to change it would be a breaking change and users would need to upgrade to a next major version of the action.
The usage specify:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
But the version v1
doesn't exists. It should be v1.0.0
or v1.1.1
to use the current latest version.
First I apologized if this isn't the right place to ask since I don't know where to find official Github API's channel or repo to ask.
I went through the developer and newer API docs as well as your source code, I'd think there'd be a response either 204
or 4xx
code that can be returned to the action's to determine if the POST
request actually delivered & acknowledged, but I didn't find it when I read the job run log. It seems like a missed opportunity to be able to flag the step as successful with better confidence.
Can it be implemented?
Hi,
I love using your action script. However, I was wondering whether it is possible to repository-dispatch a whole of repos as targets?
Thanks again for developing this awesome tool!
Hi, thank you for this repo! I'm trying to apply repository_dispatch
in the same repo and pass metadata from one workflow to another. My code is shown below and it's throwing an error Error: Resource not accessible by integration
. Why is it throwing that error? I thought for local dispatch it doesn't need secrets.GITHUB_TOKEN
or PAT?
save-to-dispatch:
runs-on: ubuntu-latest
needs: [set-tag, build-image-and-push]
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
event-type: version-tag
client-payload: '{"dispatch_origin": "production", "tag": "${{ needs.set-tag.outputs.tag }}"}'
So I am trying to implement a multiline client_payload, my configuration:
call-gke-cd:
if: >
${{
(startsWith(github.event.head_commit.message, '[PROD]:')) ||
(github.ref != 'refs/heads/master')
}}
name: CD / Deploy to Kubernetes
runs-on: ubuntu-22.04
needs: [affected-services, build-and-push-docker]
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GIT_ACCESS_TOKEN }}
repository: myorg/myrepo
event-type: deploy
client-payload: >
'{"ref": "${{ github.ref }}",
"image_tag": "${{ needs.affected-services.outputs.project_version }}",
"services": "${{ needs.affected-services.outputs.matrix }}"}'
I get fails of Unexpected token ' in JSON at position 0
occasionally can't hit the github dispatches API, here's the error logs :
Run 689b4c9
with:
token: ***
repository: tokopedia/ansible-v2
event-type: apply
client-payload: { "pr_number": "20897", "extra_vars": "", "tags": "", "limit": "", "comment_body": "ghtoped apply", "pr_url": "https://api.github.com/repos/tokopedia/ansible-v2/pulls/20897"}
env:
GCS_FILE: true
COMMENT_BODY: ghtoped apply
Error: request to https://api.github.com/repos/tokopedia/ansible-v2/dispatches failed, reason: getaddrinfo ENOTFOUND api.github.com
This is a question
Thanks for the GitHub Action, I want to ask if I can use ${{ secrets.GITHUB_TOKEN }}
with this action?
Thanks.
The workflow does not run. I am admin of the public repository.
PRUpdates.yml - Workflow that sends the dispatch.
name: PR Updates
on:
pull_request:
types: [opened, reopened]
jobs:
dispatch:
runs-on: ubuntu-latest
name: Trigger Telegram notifier workflow
steps:
- name: Repository Dispatch
uses: peter-evans/[email protected]
with:
token: ${{ secrets.PAT }}
event-type: pr-opened
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "title": "${{ github.event.pull_request.title }}", "creator": "${{ github.actor }}"}'
notifier.yml - Workflow triggered on dispatch
name: GitHub Notifier
on:
repository_dispatch:
types: [pr-opened]
jobs:
build:
name: Telegram Notify
runs-on: ubuntu-latest
steps:
- name: Notify telegram group on pull request changes
uses: appleboy/[email protected]
with:
to: ${{ secrets.TELEGRAM_TO }} # don't change
token: ${{ secrets.TELEGRAM_TOKEN }} # don't change
ref: ${{ github.event.client_payload.ref }}
message: |
**${{ github.event.client_payload.title }}**
@${{ github.event.client_payload.creator }} opened a pull request.
It would be awesome if after dispatching a workflow, this action could log the URL to the active workflow of the receiver. Maybe this just required querying Github for the run number once the run has been scheduled?
How to check in my next step to "Repository Dispatch" workflow status ?
name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: *****
repository: username/anotherrepo
event-type: my-event
client-payload: '{"sample": "${{ env.sample}}"}'
name: ....
Hi Peter,
I want to use this github action in my work, but the security team says [email protected] has a high vulnerability. Is it possible to bump this package's version? Thanks!
PATs seem to be more complicated now, I couldn't just choose "public_repo" permissions, I had to choose whether to not allow, allow read-only or allow read/write for like 30 different things.
https://github.com/settings/personal-access-tokens/new
I chose 6 that looked good, and it seems to have worked but I forget which ones I chose and I don't think I can see. It would be great if the documentation listed the permissions that need to be set.
Both of my workflows are on master
of my repository. I'm not getting any error messages, however the workflow is not being triggered
verification:
name: Workflow - Lint, Test & Build
runs-on: 'ubuntu-latest'
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
event-type: run-lint-test-build
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
name: Lint, Test & Build
on:
repository_dispatch:
types: [run-lint-test-build]
jobs:
verification:
name: Lint, Test & Build
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
ref: ${{ github.event.client_payload.ref }}
- run: echo ${{ github.event.client_payload.sha }}
Is this possible without duplicating the step several times? Something like
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: [slug1/repo1, slug2/repo2, ...]
event-type: my-event
Error I get. What am I missing? Really want this to work.
with:
token: ***
event-type: my-event
client-payload: {"ref": "refs/heads/master", "sha": "f71d129c3362c56acf734863f873aa8bb3281459"}
repository: ******
##[error]Not Found
name: Alert parent repository on push
on:
push:
branches:
- **********
jobs:
dispatch:
name: Dispatch to other-repo
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@master
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
#repository: test-dispatch
event-type: my-event
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
Another job waitingto this event does exist and everything.
Hi @peter-evans, currently i have a workflow that triggers repository dispatch from issue comments. This has been an issue since the the repository dispatch workflow doesn't displayed the current PR when triggering from issue comments job. Is there any chance to hardcode the PR to be displayed for repository dispatch? Thank You!
If a workflow that needs to be dispatched requires some input parameters there is option to set these input parameters from this action.
Hi, I was wondering if this action can be used from an organization repository. According to documentation, the repository attribute should be something like: username/my-repo
. I tried with an organization (organization/repo-b
, using a personal token) and the event is never caught by the repo-b
. I have used branches for testing purposes.
Any suggestion?
I have a test repo-dispatch action in my first repo:
name: Test
on:
push:
paths:
- '.github/workflows/test-repo-dispatch.yml'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{secrets.SECRET}}
repository: polyverse/polyscripted-wordpress
event-type: x
In my downstream repo it is supposed to run on a specific type of dispatch, yet is triggered regardless of what event type is added.
repository_dispatch:
type: [build_7.2_apache]
The above workflow runs even with event type "x" sent.
I found your workflow to trigger another (or same in my case) repository. The essential part about this idea, which is way easier implemented in GitLab) is to trigger upstream pipelines. This needs a way to trigger another workflow.
By looking at https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event, a workflow_id
is supported in REST API. Can you please add a workflow
parameter to your action?
Let's say I have a YAML file that I want to send as Client Payload. Is this possible?
I love this action, it made starting workflows from other repositories super easy. We are using this action in a submodule repository to trigger workflows on all repositories which use the submodule whenever master is updated.
The problem we are finding is that workflow runs triggered by repository-dispatch are reporting "Repository dispatch triggered by TJKrawczynski2" in the actions tab always, even when the original repository-dispatch action was triggered by someone else in the submodule. Essentially this means TJKrawczynski2 (me) is the only one who gets notified of failed CI runs instead of the developers who originally made changes on the submodule.
I suspect the "actor" field is not getting forwarded to the repository_dispatch-triggered workflow properly, I tried looking over your code but got a little lost since I've never worked with typescript or any java-related languages really... Any help will be appreciated!
- name: Repository Dispatch
uses: peter-evans/[email protected]
with:
# A repo scoped GitHub Personal Access Token
token: ${{ secrets.GITHUB_TOKEN }}
# The full name of the repository to send the dispatch.
repository: MrThanlon/meclass
# A custom webhook event name.
event-type: updated
need something like 'wait on check' but a more dynamic one... i think i saw some solution for it in one of your repos but cant find it now
i am using this code from a.yml (sender)
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
if: always()
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
repository: abc/cde
event-type: cd_development_event
client-payload: >-
{
"sha": "${{ github.sha }}",
"ref": "${{ github.ref }}",
"configuration": "${{ github.event.inputs.configuration }}",
"deployment": "${{ github.event.inputs.deployment }}",
"note": "${{ github.event.inputs.note }}",
"webhook": "${{ secrets.WEBHOOK_TEAMS_DEVELOPMENT }}",
"needs": ${{ toJson(needs) }},
"job": ${{ toJson(job) }},
"steps": ${{ toJson(steps) }}
}
and for receiver in b.yml, iam using like this
- name: Send a Report
uses: skitionek/notify-microsoft-teams@master
with:
needs: ${{ github.event.client_payload.needs }}
job: ${{ github.event.client_payload.job }}
steps: ${{ github.event.client_payload.steps }}
and when send a report is run, i got an error. this is my error :
Error: .github/workflows/cn_teams.yml (Line: 47, Col: 18): A mapping was not expected
Error: .github/workflows/cn_teams.yml (Line: 48, Col: 16): A mapping was not expected
Error: .github/workflows/cn_teams.yml (Line: 49, Col: 18): A mapping was not expected
Error: The template is not valid. .github/workflows/cn_teams.yml (Line: 47, Col: 18): A mapping was not expected,.github/workflows/cn_teams.yml (Line: 48, Col: 16): A mapping was not expected,.github/workflows/cn_teams.yml (Line: 49, Col: 18): A mapping was not expected
and when i am display value from reciver, this my error
# - name: needs
# run: echo ${{ github.event.client_payload.needs }}
output : {}
# - name: job
# run: echo ${{ github.event.client_payload.job }}
output : {}
expected output :
{
"needs": {},
"job": {
"status": "success"
},
"steps": {}
}
please, how to get that json from sender to receiver. thank you
I ran into the same problem reported in #34, where the error with the workflow just reported "not found", without providing any information wrt what is not found. Reading the issue discussion helped, however I suggest to make the error message more informative.
Specifying the client-payload
value can be problematic. As this is created within a workflow file, I can't benefit from any syntax validation or syntax highlighting that might otherwise help in spotting a mistake.
If I were instead able to store the required payload in a file, I could:
Ideally a workflow step may then end up looking like:
- name: Dispatch event
uses: peter-evans/repository-dispatch@v1
with:
repository: example/repo
event-type: event-type-name
client-payload-file: ./path/to/payload.json
Would it be possible, rather than specifying the client-payload as a json string, to juist build a yaml object and have that be converted into json?
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.PAT }}
repository: username/my-repo
event-type: my-event
client-payload:
ref: ${{ github.ref }}
sha: ${{ github.sha }}
Both workflows are in default branch on each repos still not dispatching an event.
Dispatcher
name: Codegen
on:
push:
branches:
- develop
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: org-name/repo-name
event-type: my-event
Reciever
name: Graphql Codegen
on:
repository_dispatch:
types: [my-event]
jobs:
codegen:
runs-on: ubuntu-latest
steps:
But when I tried to dispatch via curl, it triggers the workflow on the receiver repo.
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ghp_token_with_repo_workflow_scope" \
https://api.github.com/repos/org-name/repo-name/dispatches \
-d '{"event_type":"my-event","client_payload":{"command":"ping"}'
My personal access token has repo + worfklow scope
While Github Actions will try to redact secrets printed to logs, I think it would be best if the debug logging in this action didn't include the GH token configured.
https://github.com/peter-evans/repository-dispatch/blob/master/src/main.ts#L13
https://docs.github.com/en/actions/reference/encrypted-secrets
Warning: GitHub automatically redacts secrets printed to the log, but you should avoid printing secrets to the log intentionally.
Hi Peter,
With GitHub's recent release of fine-grained personal access tokens, I'm curious: do you have any recommendations on the minimum set of permissions needed to use a fine-grained PAT with repository-dispatch?
Classic PATs with a repo scope per your recommendation continue to work fine, of course. ๐
Thanks!
Hello,
I have bunch of workflows that i'd like to manage with this action.
Problem is workflows that are supposed to get triggered are not triggerin.
I have followed instructions at https://stevenmortimer.com/running-github-actions-sequentially/ .
At the moment my workflows are defined only in one branch. Is that a problem for this action?
I'm doing something like this as per instructions as a last part of my first workflow:
- name: Trigger next workflow
if: success()
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REPO_GHA_PAT }}
repository: ${{ github.repository }}
event-type: trigger-test-workflow
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
And this is the next workflow start:
name: Next test workflow
on:
repository_dispatch:
types: [trigger-test-worflow]
Edit. Just read that it only triggers if it's in main branch. I guess this just turned into feature request if it's possible to implement.
The documentation says
you can use the more limited public_repo scope.
which doesn't seem to be true (from both reading GH docs and trying it out)
Did you get it to work that way? Maybe it depends on a setting.
Hi,
I'm trying to trigger a github actions workflow in a non-default branch. Is there any way I can do that using your Action?
I want to run workflow on custom branch.
I tried dispatch using just appending "/custom_branch_name",
like "sunn-e/myRepo/dev" , it showed green tick but did not actually trigger, s in it was not received.
Hello. I have the error in my project "##[error]Bad credentials"
https://github.com/linuxoid69/go-backuper/runs/533775840?check_suite_focus=true
I created a token with maximum permissions.
REPO_ACCESS_TOKEN
screenshot -> https://imgur.com/a/3tGZeIw
What am I doing wrong?
Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: peter-evans/repository-dispatch
Hi, I'm trying to use an repository which receives the same event from different repositories. What I don't understand it's why it works with a repository (A) and it doesn't work if I've the same configuration in a repository (B).
This is my subtree repository on listen-dispatch.yml
# listen-dispatch.yml file
name: listen trigger events from another repository
on:
repository_dispatch:
types: [update-subtree-repository]
jobs:
build:
name: run-workflow
runs-on: self-hosted
steps:
- name: Checkout project
uses: actions/checkout@v3
with:
ref: master
fetch-depth: 0
- name: Create environment variables
run: |
echo "REPOSITORY_NAME=`basename ${{ github.event.client_payload.repository }}`" >> $GITHUB_ENV
echo "[email protected]:${{ github.event.client_payload.repository }}.git" >> $GITHUB_ENV
- name: Get changes
run: make git-subtree-pull REPOSITORY_NAME=${{ env.REPOSITORY_NAME}} REPOSITORY_URL=${{ env.REPOSITORY_URL }}
- name: update changes
run: make upload-changes-to-remote
This is what I've on my repositories which send the event to the previous one, there's one of them which works though there is another one which has the same configuration and share the access token from the same organization, both are private repositories.
# repository-dispatch.yml file on multiple repositories from the same organization which share the same PAT
name: trigger events in another repository
on:
push:
branches: [ master ]
jobs:
testing-trigger:
runs-on: self-hosted
steps:
- name: Repository Dispatch
uses: peter-evans/[email protected]
with:
token: ${{ secrets.ACCESS_TOKEN }}
repository: myorg/mysubtree-repo
event-type: update-subtree-repository
client-payload: '{ "repository": "${{ github.repository }}" }' # optional, default is {}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.