Skip to content

Commit 5242e0b

Browse files
committed
Adjust defaults
Use GITHUB_TOKEN for token
1 parent 57bdacd commit 5242e0b

File tree

6 files changed

+96
-57
lines changed

6 files changed

+96
-57
lines changed

README.md

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,31 @@
22

33
Trigger other workflows, display a link, and optionally wait for the result.
44

5-
## Usage
5+
## Examples
66

7-
### Inputs
7+
See [Usage](#usage) for full documentation.
88

9-
| Name | Description | Required | Default |
10-
| ------------ | -------------------------------------------------- | -------- | ------------------ |
11-
| inputs | JSON object of inputs | No | {} |
12-
| marker-input | Name of the downstream's input for upstream URL. | No | |
13-
| owner | Repsitory owner name | No | Current owner |
14-
| ref | Git reference | No | Current ref |
15-
| repo | Repository name | No | Current repository |
16-
| token | Personal access token | Yes | |
17-
| wait | Whether to wait for conclusion | No | false |
18-
| workflow | Workflow path in .github/workflows (e.g. main.yml) | Yes |
9+
### Same repository
1910

20-
### Outputs
21-
22-
| Name | Description |
23-
| ---------- | ------------------------------------ |
24-
| conclusion | Workflow conclusion, if wait is true |
25-
| run_id | Workflow run ID |
26-
27-
### Marker step
28-
29-
The Github API does not provide a direct association between a workflow dispatch
30-
and the subsequent workflow run. For greater robustness in determining the
31-
relationship, the upstream URL can be used as an input. _The downstream workflow
32-
must use that value as the name of a step._ (See [example](#marker-step-1).)
11+
**upstream.yml**
3312

34-
### Personal access token
13+
```yml
14+
job:
15+
example:
16+
steps:
17+
- use: pauldraper/[email protected]
18+
with:
19+
inputs: '{"color": "blue"}'
20+
workflow: downstream.yml
21+
```
3522
36-
A personal access token is required with read/write permissions for actions on
37-
the downstream repo. (Note: The default `GITHUB_TOKEN` does not have sufficient
38-
permissions.) See
39-
[Creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
23+
**downstream.yml**
4024
41-
## Examples
25+
```yml
26+
on: [workflow_dispatch]
27+
```
4228
43-
### Basic
29+
### Different repository, and wait for finish
4430
4531
**upstream.yml**
4632
@@ -51,10 +37,10 @@ job:
5137
- use: pauldraper/[email protected]
5238
with:
5339
inputs: '{"color": "blue"}'
54-
owner: example
5540
ref: refs/head/main
56-
repo: example
57-
token: "${{ secrets.GH_TOKEN }}"
41+
repo: example/example
42+
token: ${{ secrets.GH_TOKEN }}
43+
wait: "true"
5844
workflow: downstream.yml
5945
```
6046
@@ -75,7 +61,7 @@ job:
7561
- use: pauldraper/[email protected]
7662
with:
7763
marker-input: upstream-url
78-
token: "${{ secrets.GH_TOKEN }}"
64+
workflow: downstream.yml
7965
```
8066
8167
**downstream.yml**
@@ -84,8 +70,8 @@ job:
8470
jobs:
8571
example:
8672
steps:
87-
- if: "${{ inputs.upstream-url }}"
88-
name: "${{ inputs.upstream-url }}"
73+
- if: ${{ inputs.upstream-url }}
74+
name: ${{ inputs.upstream-url }}
8975
run:
9076
echo 'Started by [${{ inputs.upstream-url }}](${{ inputs.upstream-url
9177
}})' >> "$GITHUB_STEP_SUMMARY"
@@ -95,3 +81,44 @@ on:
9581
upstream-url:
9682
description: URL of upstream run
9783
```
84+
85+
## Usage
86+
87+
### Inputs
88+
89+
| Name | Description | Required | Default |
90+
| ------------ | -------------------------------------------------- | -------- | -------------------------------- |
91+
| inputs | JSON object of inputs | No | `{}` |
92+
| marker-input | Name of the downstream's input for upstream URL. | No | `` |
93+
| owner | Repsitory owner name | No | `${{ github.repository_owner }}` |
94+
| ref | Git reference | No | `${{ github.ref }}` |
95+
| repo | Repository name | No | `${{ github.repository }}` |
96+
| token | Personal access token | No | `${{ github.token }}` |
97+
| wait | Whether to wait for conclusion | No | `false` |
98+
| workflow | Workflow path in .github/workflows (e.g. main.yml) | Yes | `` |
99+
100+
### Outputs
101+
102+
| Name | Description |
103+
| ---------- | ------------------------------------ |
104+
| conclusion | Workflow conclusion, if wait is true |
105+
| run_id | Workflow run ID |
106+
107+
### Marker step
108+
109+
The Github API does not provide a direct association between a workflow dispatch
110+
and the subsequent workflow run. For greater robustness in determining the
111+
relationship, the upstream URL can be used as an input. The downstream workflow
112+
must use that value as the name of a step, so that the action can find it. (See
113+
[example](#marker-step-1).)
114+
115+
### Token
116+
117+
`GITHUB_TOKEN` must have read/write actions permissions. See
118+
[Permissions for the `GITHUB_TOKEN`](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token).
119+
120+
When starting workflows in other repos, you must create a personal access token
121+
and provide it as the `token` input. See
122+
[Creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
123+
and
124+
[Encrypted Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets).

action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ inputs:
1111
marker-input:
1212
description: Name of input for this workflow's URL
1313
repo:
14-
description: Repository name
15-
owner:
16-
description: Owner name
14+
default: ${{ github.repository }}
15+
description: Repository owner and name
1716
ref:
17+
default: ${{ github.ref }}
1818
description: Ref
1919
token:
20+
default: ${{ github.token }}
2021
description:
2122
Personal access token, see
2223
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
23-
required: true
2424
wait:
2525
default: "false"
2626
description: Whether to wait for
2727
workflow:
2828
description: Workflow file path
29+
required: true
2930
outputs:
3031
conclusion:
3132
description: Conclusion of workflow run

tools/file/files.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ filegroup(
55
srcs = glob(["files/**/*.bazel", "files/**/*.bzl"]),
66
)
77

8-
filegroup(
9-
name = "eslint_files",
10-
srcs = glob(["files/**/*.js"]),
11-
)
12-
138
filegroup(
149
name = "prettier_files",
1510
srcs = glob(

workflow-dispatch/dist/main.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16235,6 +16235,14 @@ function getJsonInput(name) {
1623516235
}
1623616236
}
1623716237
}
16238+
function getRepoInput(name) {
16239+
const text = coreExports.getInput(name);
16240+
const match = text.match(/^([^/]+)\/([^/]+)$/);
16241+
if (!match) {
16242+
throw new ActionError(`Invalid GitHub repository`);
16243+
}
16244+
return { owner: match[1], repo: match[2] };
16245+
}
1623816246
function workflowRunAttemptUrl(server, owner, repo, runId, runAttempt) {
1623916247
return `${workflowRunUrl(server, owner, repo, runId)}/attempts/${runAttempt}`;
1624016248
}
@@ -29896,12 +29904,11 @@ if (typeof crypto === "undefined") {
2989629904
async function main() {
2989729905
const inputs = getJsonInput("inputs");
2989829906
const markerInput = coreExports.getInput("marker-input");
29899-
const owner = coreExports.getInput("owner") || context.repo.owner;
29900-
const ref = coreExports.getInput("ref") || context.ref;
29901-
const repo = coreExports.getInput("repo") || context.repo.repo;
29902-
const token = coreExports.getInput("token", { required: true });
29907+
const ref = coreExports.getInput("ref");
29908+
const { owner, repo } = getRepoInput("repo");
29909+
const token = coreExports.getInput("token");
2990329910
const wait = getBooleanInput("wait");
29904-
const workflow = coreExports.getInput("workflow", { required: true });
29911+
const workflow = coreExports.getInput("workflow");
2990529912
const octokit = new Octokit({ auth: token });
2990629913
let dispatcher;
2990729914
if (markerInput) {

workflow-dispatch/src/action.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ export function getJsonInput(name: string) {
3030
}
3131
}
3232

33+
export function getRepoInput(name: string): { owner: string; repo: string } {
34+
const text = getInput(name);
35+
const match = text.match(/^([^/]+)\/([^/]+)$/);
36+
if (!match) {
37+
throw new ActionError(`Invalid GitHub repository`);
38+
}
39+
return { owner: match[1], repo: match[2] };
40+
}
41+
3342
export function workflowRunAttemptUrl(
3443
server: string,
3544
owner: string,

workflow-dispatch/src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
currentUrl,
1313
getBooleanInput,
1414
getJsonInput,
15+
getRepoInput,
1516
workflowRunAttemptUrl,
1617
} from "./action";
1718
import { ActionError } from "./core";
@@ -30,12 +31,11 @@ if (typeof crypto === "undefined") {
3031
async function main() {
3132
const inputs = getJsonInput("inputs");
3233
const markerInput = getInput("marker-input");
33-
const owner = getInput("owner") || context.repo.owner;
34-
const ref = getInput("ref") || context.ref;
35-
const repo = getInput("repo") || context.repo.repo;
36-
const token = getInput("token", { required: true });
34+
const ref = getInput("ref");
35+
const { owner, repo } = getRepoInput("repo");
36+
const token = getInput("token");
3737
const wait = getBooleanInput("wait");
38-
const workflow = getInput("workflow", { required: true });
38+
const workflow = getInput("workflow");
3939

4040
const octokit = new Octokit({ auth: token });
4141

0 commit comments

Comments
 (0)