Skip to content

Commit 3ae16d6

Browse files
committed
Add support for using GitHub app with automatic token refresh
1 parent 3133c5d commit 3ae16d6

File tree

9 files changed

+16399
-9834
lines changed

9 files changed

+16399
-9834
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GitHub Action for Dispatching Workflows
22

3-
This action triggers another GitHub Actions workflow, using the `workflow_dispatch` event.
3+
This action triggers another GitHub Actions workflow, using the `workflow_dispatch` event.
44
The workflow must be configured for this event type e.g. `on: [workflow_dispatch]`
55

66
This allows you to chain workflows, the classic use case is have a CI build workflow, trigger a CD release/deploy workflow when it completes. Allowing you to maintain separate workflows for CI and CD, and pass data between them as required.
@@ -23,9 +23,17 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
2323

2424
> **Required.** A GitHub access token (PAT) with write access to the repo in question.
2525
>
26-
> **NOTE.** The automatically provided token e.g. `${{ secrets.GITHUB_TOKEN }}` can not be used, GitHub prevents this token from being able to fire the `workflow_dispatch` and `repository_dispatch` event. [The reasons are explained in the docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
26+
> **NOTE.** The automatically provided token e.g. `${{ secrets.GITHUB_TOKEN }}` can not be used, GitHub prevents this token from being able to fire the `workflow_dispatch` and `repository_dispatch` event. [The reasons are explained in the docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
2727
> The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`
2828
29+
### `app-id`
30+
31+
> **Optional.** The GitHub App ID with access to Actions API.
32+
33+
### `app-private-key`
34+
35+
> **Optional.** The GitHub App Private Key of the app with access to Actions API.
36+
2937
### `inputs`
3038

3139
> **Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`.
@@ -101,7 +109,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
101109
102110
### `workflow-logs`
103111

104-
> The logs of the triggered workflow based if `inputs.workflow-logs` is set to either `output`, or `json-output`.
112+
> The logs of the triggered workflow based if `inputs.workflow-logs` is set to either `output`, or `json-output`.
105113
> Based on the value, result will be:
106114
>
107115
> * `output`: Multiline string
@@ -248,6 +256,23 @@ on:
248256
required: false
249257
```
250258

259+
### Invoke workflow with app-id and app-private-key
260+
261+
```yaml
262+
- name: Invoke workflow with app-id and app-private-key
263+
uses: the-actions-org/workflow-dispatch@v4
264+
env:
265+
RUN_NAME: ${{ github.repository }}/actions/runs/${{ github.run_id }}
266+
with:
267+
app-id: ${{ secrets.APP_ID }}
268+
app-private-key: ${{ secrets.APP_PRIVATE_KEY }}
269+
run-name: ${{ env.RUN_NAME }}
270+
workflow: Another Workflow
271+
inputs: >-
272+
{
273+
"run-name": "${{ env.RUN_NAME }}"
274+
}
275+
251276
## Contributions
252277
253278
Thanks to:

action.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ inputs:
66
description: 'Name or ID of workflow to run'
77
required: true
88
token:
9-
description: 'GitHub token with repo write access, can NOT use secrets.GITHUB_TOKEN, see readme'
10-
required: true
9+
description: 'GitHub token with repo write access, can NOT use secrets.GITHUB_TOKEN, see README.md. If not provided, app-id and app-private-key must be provided. If token is set it takes precedence over app-id and app-private-key.'
10+
required: false
11+
app-id:
12+
description: 'GitHub App ID with access to Actions API.'
13+
required: false
14+
app-private-key:
15+
description: 'GitHub App Private Key of the app with access to Actions API.'
16+
required: false
1117
inputs:
1218
description: 'Inputs to pass to the workflow, must be a JSON string. All values must be strings (even if used as boolean or number)'
1319
required: false

0 commit comments

Comments
 (0)