mirror of
https://github.com/peter-evans/repository-dispatch.git
synced 2026-06-12 11:51:25 +00:00
Compare commits
109 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11ba7d3f32 | ||
|
|
646aa8008a | ||
|
|
8d9724ed37 | ||
|
|
88ec35d633 | ||
|
|
7fbda9c715 | ||
|
|
689b4c9c3d | ||
|
|
ecb27d1931 | ||
|
|
c9a37ac63b | ||
|
|
e006cbaf4a | ||
|
|
12751c0f0e | ||
|
|
3a8608a86b | ||
|
|
f3e2ad4d6d | ||
|
|
28a41e5d3f | ||
|
|
59fb538f54 | ||
|
|
6b9355a6b3 | ||
|
|
0e8ca8c8a5 | ||
|
|
1d7df303a4 | ||
|
|
48ba398488 | ||
|
|
a3b37769d2 | ||
|
|
6c67f6dc34 | ||
|
|
c66206b38f | ||
|
|
5e4869cf56 | ||
|
|
a691d185a6 | ||
|
|
2694ce6b01 | ||
|
|
d7bf02a0d4 | ||
|
|
f43d2e4f9b | ||
|
|
0e60b0b03e | ||
|
|
27c539bc8e | ||
|
|
80935a6f6a | ||
|
|
d410a440ba | ||
|
|
2a643d2b1d | ||
|
|
f7b4de6b26 | ||
|
|
01c34330a7 | ||
|
|
756edddbea | ||
|
|
0ca2845ddc | ||
|
|
a912a66602 | ||
|
|
d57191493a | ||
|
|
47ba5baae1 | ||
|
|
5c418feb53 | ||
|
|
0a654f7a64 | ||
|
|
9570c22b4b | ||
|
|
d8636578df | ||
|
|
6f7481a067 | ||
|
|
83b60ccd45 | ||
|
|
f5abc260cb | ||
|
|
cd5067bcd9 | ||
|
|
c083ba276e | ||
|
|
12a30d3dee | ||
|
|
2960c86134 | ||
|
|
2c97fc16cc | ||
|
|
da8e21ecc8 | ||
|
|
e404a881db | ||
|
|
259edc5079 | ||
|
|
ce5485de42 | ||
|
|
eed51ed4c3 | ||
|
|
938c2224dd | ||
|
|
d1b7bfe3a6 | ||
|
|
8031fbaca8 | ||
|
|
f1680f525a | ||
|
|
5fda2f7d98 | ||
|
|
031f27b115 | ||
|
|
c49e1666ac | ||
|
|
111788c696 | ||
|
|
f131b1d1f9 | ||
|
|
95531d6358 | ||
|
|
b4caad9acd | ||
|
|
543acfac4e | ||
|
|
1b0d3fa47b | ||
|
|
6de120f0ca | ||
|
|
1f8e017ab8 | ||
|
|
4e1995c760 | ||
|
|
7d5ca7bf80 | ||
|
|
618fe4e18f | ||
|
|
8f8aeefe6e | ||
|
|
c5318edea4 | ||
|
|
438514a476 | ||
|
|
216dea92e3 | ||
|
|
c0fe68ba01 | ||
|
|
21c5610af0 | ||
|
|
754562405e | ||
|
|
a12578c2e0 | ||
|
|
0e075ee1a0 | ||
|
|
3b28b4b04f | ||
|
|
9e58632f8a | ||
|
|
163f36102f | ||
|
|
4532a8fb51 | ||
|
|
f540f114fd | ||
|
|
1c51dc3383 | ||
|
|
8e9f439e9f | ||
|
|
1708dda570 | ||
|
|
eb329a2e6a | ||
|
|
7aa158e97c | ||
|
|
35f05e8e06 | ||
|
|
f0c6ad7fa3 | ||
|
|
fe5946ba71 | ||
|
|
7ecf080487 | ||
|
|
c830a9705e | ||
|
|
ed97383570 | ||
|
|
b410ea76d1 | ||
|
|
7fe6653bc4 | ||
|
|
d874befdda | ||
|
|
9f64758ff8 | ||
|
|
e42b4b7b55 | ||
|
|
cb588ee63a | ||
|
|
41bdbb0627 | ||
|
|
d47934dfd8 | ||
|
|
34d557382e | ||
|
|
a4bb1fc8bc | ||
|
|
f9ec82f96b |
@@ -9,8 +9,7 @@
|
||||
"plugin:import/errors",
|
||||
"plugin:import/warnings",
|
||||
"plugin:import/typescript",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier/@typescript-eslint"
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"rules": {
|
||||
|
||||
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
labels:
|
||||
- "dependencies"
|
||||
44
.github/workflows/ci.yml
vendored
44
.github/workflows/ci.yml
vendored
@@ -1,40 +1,56 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
pull_request:
|
||||
branches: [master]
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 16.x
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npm run format-check
|
||||
- run: npm run lint
|
||||
- run: npm run test
|
||||
- uses: actions/upload-artifact@v2
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: action.yml
|
||||
path: action.yml
|
||||
|
||||
test:
|
||||
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
|
||||
needs: [build]
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
target: [built, committed]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
uses: actions/download-artifact@v2
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: action.yml
|
||||
path: .
|
||||
|
||||
- name: Test repository dispatch
|
||||
uses: ./
|
||||
@@ -50,24 +66,22 @@ jobs:
|
||||
event-type: tests
|
||||
|
||||
package:
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
needs: [test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/download-artifact@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v2
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
with:
|
||||
commit-message: Update distribution
|
||||
committer: GitHub <noreply@github.com>
|
||||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
||||
title: Update distribution
|
||||
body: |
|
||||
- Updates the distribution for changes on `master`
|
||||
- Updates the distribution for changes on `main`
|
||||
|
||||
Auto-generated by [create-pull-request][1]
|
||||
|
||||
|
||||
2
.github/workflows/on-repository-dispatch.yml
vendored
2
.github/workflows/on-repository-dispatch.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
PAYLOAD_CONTEXT: ${{ toJson(github.event.client_payload) }}
|
||||
run: echo "$PAYLOAD_CONTEXT"
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
if: github.event.client_payload.ref != ''
|
||||
with:
|
||||
ref: ${{ github.event.client_payload.ref }}
|
||||
|
||||
21
.github/workflows/slash-command-dispatch.yml
vendored
Normal file
21
.github/workflows/slash-command-dispatch.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Slash Command Dispatch
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
jobs:
|
||||
slashCommandDispatch:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Slash Command Dispatch
|
||||
uses: peter-evans/slash-command-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
config: >
|
||||
[
|
||||
{
|
||||
"command": "rebase",
|
||||
"permission": "admin",
|
||||
"repository": "peter-evans/slash-command-dispatch-processor",
|
||||
"issue_type": "pull-request"
|
||||
}
|
||||
]
|
||||
41
README.md
41
README.md
@@ -1,4 +1,5 @@
|
||||
# Repository Dispatch
|
||||
[](https://github.com/peter-evans/repository-dispatch/actions?query=workflow%3ACI)
|
||||
[](https://github.com/marketplace/actions/repository-dispatch)
|
||||
|
||||
A GitHub action to create a repository dispatch event.
|
||||
@@ -7,7 +8,7 @@ A GitHub action to create a repository dispatch event.
|
||||
|
||||
```yml
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: my-event
|
||||
@@ -17,11 +18,17 @@ A GitHub action to create a repository dispatch event.
|
||||
|
||||
| Name | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `token` | (**required**) A `repo` scoped GitHub [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | |
|
||||
| `token` | (**required**) A `repo` scoped GitHub [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). See [token](#token) for further details. | |
|
||||
| `repository` | The full name of the repository to send the dispatch. | `github.repository` (current repository) |
|
||||
| `event-type` | (**required**) A custom webhook event name. | |
|
||||
| `client-payload` | JSON payload with extra information about the webhook event that your action or workflow may use. | `{}` |
|
||||
|
||||
#### `token`
|
||||
|
||||
This action creates [`repository_dispatch`](https://developer.github.com/v3/repos/#create-a-repository-dispatch-event) events.
|
||||
The default `GITHUB_TOKEN` does not have scopes to do this so a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on a user with `write` access to the target repository is required.
|
||||
If you will be dispatching to a public repository then you can use the more limited `public_repo` scope.
|
||||
|
||||
## Example
|
||||
|
||||
Here is an example setting all of the input parameters.
|
||||
@@ -37,7 +44,7 @@ Here is an example setting all of the input parameters.
|
||||
```
|
||||
|
||||
Here is an example `on: repository_dispatch` workflow to receive the event.
|
||||
Note that repository dispatch events will only trigger a workflow run if the workflow is committed to the default branch (usually `master`).
|
||||
Note that repository dispatch events will only trigger a workflow run if the workflow is committed to the default branch.
|
||||
|
||||
```yml
|
||||
name: Repository Dispatch
|
||||
@@ -48,12 +55,36 @@ jobs:
|
||||
myEvent:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.client_payload.ref }}
|
||||
- run: echo ${{ github.event.client_payload.sha }}
|
||||
```
|
||||
|
||||
### Dispatch to multiple repositories
|
||||
|
||||
You can dispatch to multiple repositories by using a [matrix strategy](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix). In the following example, after the `build` job succeeds, an event is dispatched to three different repositories.
|
||||
|
||||
```yml
|
||||
jobs:
|
||||
build:
|
||||
# Main workflow job that builds, tests, etc.
|
||||
|
||||
dispatch:
|
||||
needs: build
|
||||
strategy:
|
||||
matrix:
|
||||
repo: ['my-org/repo1', 'my-org/repo2', 'my-org/repo3']
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
repository: ${{ matrix.repo }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
## Client payload
|
||||
|
||||
The GitHub API allows a maximum of 10 top-level properties in the `client-payload` JSON.
|
||||
@@ -76,6 +107,8 @@ The following payload will succeed.
|
||||
client-payload: '{"github": ${{ toJson(github) }}}'
|
||||
```
|
||||
|
||||
Additionally, there is a limitation on the total data size of the `client-payload`. A very large payload may result in a `client_payload is too large` error.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
@@ -5,7 +5,7 @@ inputs:
|
||||
description: 'A repo scoped GitHub Personal Access Token'
|
||||
required: true
|
||||
repository:
|
||||
description: 'The full name of the repository to send the dispatch. Defaults to the current repository.'
|
||||
description: 'The full name of the repository to send the dispatch.'
|
||||
default: ${{ github.repository }}
|
||||
event-type:
|
||||
description: 'A custom webhook event name.'
|
||||
@@ -14,7 +14,7 @@ inputs:
|
||||
description: 'JSON payload with extra information about the webhook event that your action or worklow may use.'
|
||||
default: '{}'
|
||||
runs:
|
||||
using: 'node12'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
icon: 'target'
|
||||
|
||||
29254
dist/index.js
vendored
29254
dist/index.js
vendored
File diff suppressed because one or more lines are too long
15127
package-lock.json
generated
15127
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
36
package.json
36
package.json
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "repository-dispatch",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"private": true,
|
||||
"description": "Create a repository dispatch event",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"format": "prettier --write '**/*.ts'",
|
||||
"format-check": "prettier --check '**/*.ts'",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"test": "jest --passWithNoTests"
|
||||
},
|
||||
@@ -27,22 +27,22 @@
|
||||
},
|
||||
"homepage": "https://github.com/peter-evans/repository-dispatch#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "1.2.4",
|
||||
"@actions/github": "2.1.1"
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/github": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "25.2.1",
|
||||
"@types/node": "13.13.4",
|
||||
"@typescript-eslint/parser": "2.31.0",
|
||||
"@zeit/ncc": "0.20.5",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-plugin-github": "3.4.1",
|
||||
"eslint-plugin-jest": "23.9.0",
|
||||
"jest": "26.0.0",
|
||||
"jest-circus": "26.0.0",
|
||||
"js-yaml": "3.13.1",
|
||||
"prettier": "2.0.5",
|
||||
"ts-jest": "25.4.0",
|
||||
"typescript": "3.8.3"
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.11",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"@vercel/ncc": "^0.32.0",
|
||||
"eslint": "^8.3.0",
|
||||
"eslint-plugin-github": "^4.3.5",
|
||||
"eslint-plugin-jest": "^25.3.0",
|
||||
"jest": "^27.4.3",
|
||||
"jest-circus": "^27.4.2",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.5.0",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.5.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"packageRules": [
|
||||
{
|
||||
"depTypeList": ["devDependencies"],
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
||||
14
src/main.ts
14
src/main.ts
@@ -14,17 +14,23 @@ async function run(): Promise<void> {
|
||||
|
||||
const [owner, repo] = inputs.repository.split('/')
|
||||
|
||||
const octokit = new github.GitHub(inputs.token)
|
||||
const octokit = github.getOctokit(inputs.token)
|
||||
|
||||
await octokit.repos.createDispatchEvent({
|
||||
await octokit.rest.repos.createDispatchEvent({
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
event_type: inputs.eventType,
|
||||
client_payload: JSON.parse(inputs.clientPayload)
|
||||
})
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
core.debug(inspect(error))
|
||||
core.setFailed(error.message)
|
||||
if (error.status == 404) {
|
||||
core.setFailed(
|
||||
'Repository not found, OR token has insufficient permissions.'
|
||||
)
|
||||
} else {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user