Skip to content

Commit a448163

Browse files
committed
Merge branch 'master' into update-2022
2 parents 8fc6a4f + b946c8e commit a448163

File tree

7 files changed

+58
-42
lines changed

7 files changed

+58
-42
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Workflow Tester
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
testAction:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Invoke echo 1 workflow using this action
12+
uses: ./
13+
with:
14+
workflow: echo-1.yaml
15+
inputs: '{"message": "blah blah this is a test"}'

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
1313

1414
## Inputs
1515
### `workflow`
16-
**Required.** The name or ID of the workflow to trigger and run. This is the name declared in the YAML, not the filename
16+
**Required.** The name, filename or ID of the workflow to be triggered and run. All three possibilities are checked when looking for the workflow
1717

1818
### `token`
1919

20-
**Required.** A GitHub access token (PAT) with write access to the repo in question. **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).
21-
22-
The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`
20+
**Optional.** By default the standard `github.token` will be used and you no longer need to provide a token here. It is left for backwards compatibility only, or in the rare case you want to provide your own token.
2321

2422
### `inputs`
2523
**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`
@@ -41,15 +39,13 @@ None
4139
uses: benc-uk/workflow-dispatch@v1
4240
with:
4341
workflow: My Workflow
44-
token: ${{ secrets.PERSONAL_TOKEN }}
4542
```
4643
4744
```yaml
4845
- name: Invoke workflow with inputs
4946
uses: benc-uk/workflow-dispatch@v1
5047
with:
5148
workflow: Another Workflow
52-
token: ${{ secrets.PERSONAL_TOKEN }}
5349
inputs: '{ "message": "blah blah", "debug": true }'
5450
```
5551
@@ -59,6 +55,5 @@ None
5955
with:
6056
workflow: Some Workflow
6157
repo: benc-uk/example
62-
token: ${{ secrets.PERSONAL_TOKEN }}
6358
inputs: '{ "message": "blah blah", "debug": true }'
6459
```

action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ inputs:
77
required: true
88
token:
99
description: 'GitHub token with repo write access, can NOT use secrets.GITHUB_TOKEN, see readme'
10-
required: true
10+
required: false
11+
default: ${{ github.token }}
1112
inputs:
1213
description: 'Inputs to pass to the workflow, must be a JSON string'
1314
required: false

dist/index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
558558
Object.defineProperty(exports, "__esModule", { value: true });
559559
const core = __importStar(__webpack_require__(470));
560560
const github = __importStar(__webpack_require__(469));
561+
const PackageJSON = __importStar(__webpack_require__(731));
561562
//
562563
// Main task function (async wrapper)
563564
//
564565
function run() {
565566
return __awaiter(this, void 0, void 0, function* () {
567+
core.info(`!!!!Workflow Dispatch Action v${PackageJSON.version}`);
566568
try {
567569
// Required inputs
568570
const token = core.getInput('token');
@@ -587,18 +589,21 @@ function run() {
587589
core.debug('### START List Workflows response data');
588590
core.debug(JSON.stringify(workflows, null, 3));
589591
core.debug('### END: List Workflows response data');
590-
// Locate workflow either by name or id
591-
const workflowFind = workflows.find((workflow) => workflow.name === workflowRef || workflow.id.toString() === workflowRef);
592-
if (!workflowFind)
592+
// Locate workflow either by name, id or filename
593+
const foundWorkflow = workflows.find((workflow) => {
594+
return workflow.name === workflowRef ||
595+
workflow.id.toString() === workflowRef ||
596+
workflow.path.endsWith(workflowRef);
597+
});
598+
if (!foundWorkflow)
593599
throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`);
594-
console.log(`!!!Workflow id is: ${workflowFind.id}`);
600+
console.log(`Workflow id is: ${foundWorkflow.id}`);
595601
// Call workflow_dispatch API
596-
const dispatchResp = yield octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${workflowFind.id}/dispatches`, {
602+
const dispatchResp = yield octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${foundWorkflow.id}/dispatches`, {
597603
ref: ref,
598604
inputs: inputs
599605
});
600-
core.info(`!!!Workflow Dispatch response: ${JSON.stringify(dispatchResp.data)}`);
601-
core.info(`!!!API response status: ${dispatchResp.status} 🚀`);
606+
core.info(`API response status: ${dispatchResp.status} 🚀`);
602607
}
603608
catch (error) {
604609
const e = error;
@@ -6192,6 +6197,13 @@ exports.default = _default;
61926197

61936198
/***/ }),
61946199

6200+
/***/ 731:
6201+
/***/ (function(module) {
6202+
6203+
module.exports = {"name":"workflow-dispatch","version":"1.2.0","description":"Trigger running GitHub Actions workflows","main":"dist/index.js","scripts":{"build":"ncc build src/main.ts -o dist","lint":"eslint src/"},"keywords":["github","actions"],"author":"Ben Coleman","license":"MIT","devDependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@zeit/ncc":"^0.22.3","@typescript-eslint/eslint-plugin":"^5.41.0","@typescript-eslint/parser":"^5.41.0","eslint":"^8.26.0","typescript":"^4.8.4"}};
6204+
6205+
/***/ }),
6206+
61956207
/***/ 733:
61966208
/***/ (function(__unusedmodule, exports, __webpack_require__) {
61976209

src/main.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77

88
import * as core from '@actions/core'
99
import * as github from '@actions/github'
10+
import * as PackageJSON from '../package.json'
1011

1112
type Workflow = {
1213
id: number
1314
name: string
15+
path: string
1416
}
1517

1618
//
1719
// Main task function (async wrapper)
1820
//
1921
async function run(): Promise<void> {
22+
core.info(`!!!!Workflow Dispatch Action v${PackageJSON.version}`)
2023
try {
2124
// Required inputs
2225
const token = core.getInput('token')
@@ -39,26 +42,32 @@ async function run(): Promise<void> {
3942
octokit.graphql
4043

4144
// List workflows via API, and handle paginated results
42-
const workflows: Workflow[] =
43-
await octokit.paginate(octokit.rest.actions.listRepoWorkflows.endpoint.merge({ owner, repo, ref, inputs }))
45+
const workflows: Workflow[] = await octokit.paginate(
46+
octokit.rest.actions.listRepoWorkflows.endpoint.merge({ owner, repo, ref, inputs })
47+
)
4448

4549
// Debug response if ACTIONS_STEP_DEBUG is enabled
4650
core.debug('### START List Workflows response data')
4751
core.debug(JSON.stringify(workflows, null, 3))
4852
core.debug('### END: List Workflows response data')
4953

50-
// Locate workflow either by name or id
51-
const workflowFind = workflows.find((workflow) => workflow.name === workflowRef || workflow.id.toString() === workflowRef)
52-
if(!workflowFind) throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`)
53-
console.log(`Workflow id is: ${workflowFind.id}`)
54+
// Locate workflow either by name, id or filename
55+
const foundWorkflow = workflows.find((workflow) => {
56+
return workflow.name === workflowRef ||
57+
workflow.id.toString() === workflowRef ||
58+
workflow.path.endsWith(workflowRef)
59+
})
60+
61+
if(!foundWorkflow) throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`)
62+
63+
console.log(`Workflow id is: ${foundWorkflow.id}`)
5464

5565
// Call workflow_dispatch API
56-
const dispatchResp = await octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${workflowFind.id}/dispatches`, {
66+
const dispatchResp = await octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${foundWorkflow.id}/dispatches`, {
5767
ref: ref,
5868
inputs: inputs
5969
})
6070

61-
6271
core.info(`API response status: ${dispatchResp.status} 🚀`)
6372
} catch (error) {
6473
const e = error as Error

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"compilerOptions": {
33
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
44
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
5-
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
5+
"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
66
"strict": true, /* Enable all strict type-checking options. */
77
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
8-
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
8+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
9+
"resolveJsonModule": true
910
},
1011
"exclude": ["node_modules", "**/*.test.ts"]
1112
}

0 commit comments

Comments
 (0)