mirror of
https://github.com/peter-evans/repository-dispatch.git
synced 2026-06-12 11:51:25 +00:00
Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26b39ed245 | ||
|
|
b155cf1427 | ||
|
|
faa2bf022d | ||
|
|
0bc97bd4b8 | ||
|
|
8ab3ab850d | ||
|
|
defb7de2f3 | ||
|
|
fb1da2a91f | ||
|
|
ec896de369 | ||
|
|
9255d358ad | ||
|
|
f8e700e208 | ||
|
|
3c7e484edb | ||
|
|
cb18cc8cd6 | ||
|
|
1f873ff42d | ||
|
|
73f2fe9d70 | ||
|
|
9b60aa8a4d | ||
|
|
f2696244ec | ||
|
|
2f6d32ce83 | ||
|
|
66463e47e7 | ||
|
|
aebc169929 | ||
|
|
b700ade2f3 | ||
|
|
8e295bb3b1 | ||
|
|
b8601598d8 | ||
|
|
18c0a0eef4 | ||
|
|
870eb7a531 | ||
|
|
d591bcc413 | ||
|
|
42eb81b6bc | ||
|
|
26cb96aa5e | ||
|
|
6045f64a24 | ||
|
|
f8bc8c5c02 | ||
|
|
5e038d8e52 | ||
|
|
3c4e552d10 | ||
|
|
77fb463884 | ||
|
|
c8e633a77e | ||
|
|
e2dfd3c880 | ||
|
|
cac67678cf | ||
|
|
fe4ce16ccb | ||
|
|
6676414e8f | ||
|
|
eaded0e2ee | ||
|
|
23f37653ea | ||
|
|
c73dcc4242 | ||
|
|
3de81530cc | ||
|
|
d85250f54b | ||
|
|
4b2881efb9 | ||
|
|
c078548696 | ||
|
|
0459c47edf | ||
|
|
a275156cbd | ||
|
|
64c665535e | ||
|
|
077903f4f4 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
github: peter-evans
|
||||
9
.github/dependabot.yml
vendored
9
.github/dependabot.yml
vendored
@@ -3,6 +3,13 @@ updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
interval: "monthly"
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
13
.github/workflows/automerge-dependabot.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Auto-merge Dependabot
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- uses: peter-evans/enable-pull-request-automerge@v2
|
||||
with:
|
||||
token: ${{ secrets.DEPENDABOT_AUTOMERGE }}
|
||||
pull-request-number: ${{ github.event.pull_request.number }}
|
||||
merge-method: squash
|
||||
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@@ -10,12 +10,17 @@ on:
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v2
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
- run: npm ci
|
||||
@@ -55,14 +60,12 @@ jobs:
|
||||
- name: Test repository dispatch
|
||||
uses: ./
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: tests
|
||||
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
||||
|
||||
- name: Test repository dispatch (default payload)
|
||||
uses: ./
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: tests
|
||||
|
||||
package:
|
||||
@@ -76,7 +79,7 @@ jobs:
|
||||
name: dist
|
||||
path: dist
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
commit-message: Update distribution
|
||||
title: Update distribution
|
||||
|
||||
2
.github/workflows/slash-command-dispatch.yml
vendored
2
.github/workflows/slash-command-dispatch.yml
vendored
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Slash Command Dispatch
|
||||
uses: peter-evans/slash-command-dispatch@v2
|
||||
uses: peter-evans/slash-command-dispatch@v3
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
config: >
|
||||
|
||||
27
README.md
27
README.md
@@ -6,11 +6,20 @@ A GitHub action to create a repository dispatch event.
|
||||
|
||||
## Usage
|
||||
|
||||
Dispatch an event to the current repository.
|
||||
```yml
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
Dispatch an event to a remote repository using a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
|
||||
```yml
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
@@ -18,15 +27,17 @@ A GitHub action to create a repository dispatch event.
|
||||
|
||||
| Name | Description | Default |
|
||||
| --- | --- | --- |
|
||||
| `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. | |
|
||||
| `token` | `GITHUB_TOKEN` (permissions `contents: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). See [token](#token) for further details. | `GITHUB_TOKEN` |
|
||||
| `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`
|
||||
#### 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.
|
||||
This action creates [`repository_dispatch`](https://docs.github.com/en/rest/repos/repos#create-a-repository-dispatch-event) events.
|
||||
The default `GITHUB_TOKEN` token can only be used if you are dispatching the same repository that the workflow is executing in.
|
||||
|
||||
To dispatch to a remote repository you must create a [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) with the `repo` scope and store it as a secret.
|
||||
If you will be dispatching to a public repository then you can use the more limited `public_repo` scope.
|
||||
|
||||
## Example
|
||||
@@ -35,9 +46,9 @@ Here is an example setting all of the input parameters.
|
||||
|
||||
```yml
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: username/my-repo
|
||||
event-type: my-event
|
||||
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
||||
@@ -80,7 +91,7 @@ jobs:
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: ${{ matrix.repo }}
|
||||
event-type: my-event
|
||||
```
|
||||
|
||||
@@ -2,8 +2,8 @@ name: 'Repository Dispatch'
|
||||
description: 'Create a repository dispatch event'
|
||||
inputs:
|
||||
token:
|
||||
description: 'A repo scoped GitHub Personal Access Token'
|
||||
required: true
|
||||
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
|
||||
default: ${{ github.token }}
|
||||
repository:
|
||||
description: 'The full name of the repository to send the dispatch.'
|
||||
default: ${{ github.repository }}
|
||||
|
||||
2781
dist/index.js
vendored
2781
dist/index.js
vendored
File diff suppressed because one or more lines are too long
3881
package-lock.json
generated
3881
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -27,21 +27,21 @@
|
||||
},
|
||||
"homepage": "https://github.com/peter-evans/repository-dispatch#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/github": "^5.0.0"
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/github": "^5.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.11",
|
||||
"@types/node": "^18.11.11",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"@vercel/ncc": "^0.32.0",
|
||||
"@vercel/ncc": "^0.36.0",
|
||||
"eslint": "^8.3.0",
|
||||
"eslint-plugin-github": "^4.3.5",
|
||||
"eslint-plugin-github": "^4.6.0",
|
||||
"eslint-plugin-jest": "^25.3.0",
|
||||
"jest": "^27.4.3",
|
||||
"jest-circus": "^27.4.2",
|
||||
"jest-circus": "^29.3.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.5.0",
|
||||
"prettier": "^2.8.1",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.5.2"
|
||||
}
|
||||
|
||||
16
src/main.ts
16
src/main.ts
@@ -2,6 +2,16 @@ import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {inspect} from 'util'
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
function hasErrorStatus(error: any): error is {status: number} {
|
||||
return typeof error.code === 'number'
|
||||
}
|
||||
|
||||
function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const inputs = {
|
||||
@@ -22,14 +32,14 @@ async function run(): Promise<void> {
|
||||
event_type: inputs.eventType,
|
||||
client_payload: JSON.parse(inputs.clientPayload)
|
||||
})
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
core.debug(inspect(error))
|
||||
if (error.status == 404) {
|
||||
if (hasErrorStatus(error) && error.status == 404) {
|
||||
core.setFailed(
|
||||
'Repository not found, OR token has insufficient permissions.'
|
||||
)
|
||||
} else {
|
||||
core.setFailed(error.message)
|
||||
core.setFailed(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user