Skip to content

Commit f269624

Browse files
authored
Merge pull request #124 from peter-evans/token-update
Token update
2 parents b860159 + 2f6d32c commit f269624

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
permissions:
1515
pull-requests: write
1616
contents: write
17+
actions: write
1718

1819
jobs:
1920
build:
@@ -60,14 +61,12 @@ jobs:
6061
- name: Test repository dispatch
6162
uses: ./
6263
with:
63-
token: ${{ secrets.REPO_ACCESS_TOKEN }}
6464
event-type: tests
6565
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
6666

6767
- name: Test repository dispatch (default payload)
6868
uses: ./
6969
with:
70-
token: ${{ secrets.REPO_ACCESS_TOKEN }}
7170
event-type: tests
7271

7372
package:

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ A GitHub action to create a repository dispatch event.
66

77
## Usage
88

9+
Dispatch an event to the current repository by elivating the permissions of the default `GITHUB_TOKEN`.
10+
```yml
11+
permissions:
12+
actions: write
13+
14+
jobs:
15+
repositorydispatch:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Repository Dispatch
19+
uses: peter-evans/repository-dispatch@v2
20+
with:
21+
event-type: my-event
22+
```
23+
24+
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).
925
```yml
1026
- name: Repository Dispatch
1127
uses: peter-evans/repository-dispatch@v2
@@ -18,15 +34,23 @@ A GitHub action to create a repository dispatch event.
1834

1935
| Name | Description | Default |
2036
| --- | --- | --- |
21-
| `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. | |
37+
| `token` | (**required**) `GITHUB_TOKEN` (permissions `actions: 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` |
2238
| `repository` | The full name of the repository to send the dispatch. | `github.repository` (current repository) |
2339
| `event-type` | (**required**) A custom webhook event name. | |
2440
| `client-payload` | JSON payload with extra information about the webhook event that your action or workflow may use. | `{}` |
2541

26-
#### `token`
42+
#### Token
43+
44+
This action creates [`repository_dispatch`](https://docs.github.com/en/rest/repos/repos#create-a-repository-dispatch-event) events.
45+
The default `GITHUB_TOKEN` token can only be used if you are dispatching the same repository that the workflow is executing in.
46+
In this case you must [elevate the token permissions](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs) to allow the dispatch.
47+
48+
```yaml
49+
permissions:
50+
actions: write
51+
```
2752

28-
This action creates [`repository_dispatch`](https://developer.github.com/v3/repos/#create-a-repository-dispatch-event) events.
29-
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.
53+
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.
3054
If you will be dispatching to a public repository then you can use the more limited `public_repo` scope.
3155

3256
## Example

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: 'Repository Dispatch'
22
description: 'Create a repository dispatch event'
33
inputs:
44
token:
5-
description: 'A repo scoped GitHub Personal Access Token'
6-
required: true
5+
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
6+
default: ${{ github.token }}
77
repository:
88
description: 'The full name of the repository to send the dispatch.'
99
default: ${{ github.repository }}

0 commit comments

Comments
 (0)