Skip to content

Commit 3133c5d

Browse files
authored
Merge pull request #21 from the-actions-org/feat/improve-and-doc
Feat/improve and doc
2 parents 7ef5140 + 6bf7225 commit 3133c5d

File tree

10 files changed

+220
-216
lines changed

10 files changed

+220
-216
lines changed

.github/workflows/timeout.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Sleep
11-
run: sleep 1200s
11+
run: sleep 120s

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
.env
2+
.env
3+
.idea

README.md

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

1212
*Note 2.* If you want to reference the target workflow by ID, you will need to list them with the following REST API call `curl https://api.github.com/repos/{{owner}}/{{repo}}/actions/workflows -H "Authorization: token {{pat-token}}"`
1313

14-
*This action is a fork of `benc-uk/workflow-dispatch` to add support for waiting for workflow completion.*
14+
*This action is a fork of `aurelien-baudet/workflow-dispatch` with a better management of run-name option and node20 support.*
1515

1616
## Inputs
1717

@@ -105,16 +105,16 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
105105
> Based on the value, result will be:
106106
>
107107
> * `output`: Multiline string
108-
>
109-
> ```log
108+
>
109+
> ```log
110110
> <job-name> | <datetime> <message>
111111
> <job-name> | <datetime> <message>
112112
> ...
113113
> ```
114114
>
115115
> * `json-output`: JSON string
116-
>
117-
> ```json
116+
>
117+
> ```json
118118
> {
119119
> "<job-name>": [
120120
> {
@@ -135,7 +135,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
135135
136136
```yaml
137137
- name: Invoke workflow without inputs. Wait for result
138-
uses: aurelien-baudet/workflow-dispatch@v2
138+
uses: the-actions-org/workflow-dispatch@v4
139139
with:
140140
workflow: My Workflow
141141
token: ${{ secrets.PERSONAL_TOKEN }}
@@ -145,7 +145,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
145145

146146
```yaml
147147
- name: Invoke workflow without inputs. Don't wait for result
148-
uses: aurelien-baudet/workflow-dispatch@v2
148+
uses: the-actions-org/workflow-dispatch@v4
149149
with:
150150
workflow: My Workflow
151151
token: ${{ secrets.PERSONAL_TOKEN }}
@@ -156,7 +156,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
156156
157157
```yaml
158158
- name: Invoke workflow with inputs
159-
uses: aurelien-baudet/workflow-dispatch@v2
159+
uses: the-actions-org/workflow-dispatch@v4
160160
with:
161161
workflow: Another Workflow
162162
token: ${{ secrets.PERSONAL_TOKEN }}
@@ -167,7 +167,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
167167
168168
```yaml
169169
- name: Invoke workflow in another repo with inputs
170-
uses: aurelien-baudet/workflow-dispatch@v2
170+
uses: the-actions-org/workflow-dispatch@v4
171171
with:
172172
workflow: Some Workflow
173173
repo: benc-uk/example
@@ -180,7 +180,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
180180
```yaml
181181
- name: Invoke workflow and handle result
182182
id: trigger-step
183-
uses: aurelien-baudet/workflow-dispatch@v2
183+
uses: the-actions-org/workflow-dispatch@v4
184184
with:
185185
workflow: Another Workflow
186186
token: ${{ secrets.PERSONAL_TOKEN }}
@@ -194,7 +194,7 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
194194
```yaml
195195
- name: Invoke workflow and scrap output
196196
id: trigger-step
197-
uses: aurelien-baudet/workflow-dispatch@v2
197+
uses: the-actions-org/workflow-dispatch@v4
198198
with:
199199
workflow: Another Workflow
200200
token: ${{ secrets.PERSONAL_TOKEN }}
@@ -220,7 +220,7 @@ jobs:
220220
```yaml
221221
- name: Invoke workflow and handle result
222222
id: trigger-step
223-
uses: aurelien-baudet/workflow-dispatch@v3
223+
uses: the-actions-org/workflow-dispatch@v4
224224
env:
225225
RUN_NAME: ${{ github.repository }}/actions/runs/${{ github.run_id }}
226226
with:
@@ -252,6 +252,9 @@ on:
252252

253253
Thanks to:
254254

255+
* [LudovicTOURMAN](https://github.com/LudovicTOURMAN )
256+
* [Djontleman](https://github.com/Djontleman)
257+
* [aurelien-baudet](https://github.com/aurelien-baudet)
255258
* [samirergaibi](https://github.com/samirergaibi)
256259
* [rui-ferreira](https://github.com/rui-ferreira)
257260
* [robbertvdg](https://github.com/robbertvdg)

dist/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29323,7 +29323,7 @@ function waitForCompletionOrTimeout(workflowHandler, checkStatusInterval, waitFo
2932329323
}
2932429324
function computeConclusion(start, waitForCompletionTimeout, result) {
2932529325
if ((0, utils_1.isTimedOut)(start, waitForCompletionTimeout)) {
29326-
core.info(`Workflow wait timed out`);
29326+
core.info('Workflow wait timed out');
2932729327
core.setOutput('workflow-conclusion', workflow_handler_1.WorkflowRunConclusion.TIMED_OUT);
2932829328
throw new Error('Workflow run has failed due to timeout');
2932929329
}
@@ -29358,7 +29358,7 @@ function run() {
2935829358
const workflowHandler = new workflow_handler_1.WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref, args.runName);
2935929359
// Trigger workflow run
2936029360
yield workflowHandler.triggerWorkflow(args.inputs);
29361-
core.info(`Workflow triggered 🚀`);
29361+
core.info('Workflow triggered 🚀');
2936229362
if (args.displayWorkflowUrl) {
2936329363
const url = yield getFollowUrl(workflowHandler, args.displayWorkflowUrlInterval, args.displayWorkflowUrlTimeout);
2936429364
core.info(`You can follow the running workflow here: ${url}`);
@@ -29367,7 +29367,7 @@ function run() {
2936729367
if (!args.waitForCompletion) {
2936829368
return;
2936929369
}
29370-
core.info(`Waiting for workflow completion`);
29370+
core.info('Waiting for workflow completion');
2937129371
const { result, start } = yield waitForCompletionOrTimeout(workflowHandler, args.checkStatusInterval, args.waitForCompletionTimeout);
2937229372
yield handleLogs(args, workflowHandler);
2937329373
core.setOutput('workflow-id', result === null || result === void 0 ? void 0 : result.id);
@@ -29455,7 +29455,7 @@ function getArgs() {
2945529455
? core.getInput('repo').split('/')
2945629456
: [github.context.repo.owner, github.context.repo.repo];
2945729457
// Decode inputs, this MUST be a valid JSON string
29458-
let inputs = parse(core.getInput('inputs'));
29458+
const inputs = parse(core.getInput('inputs'));
2945929459
const displayWorkflowUrlStr = core.getInput('display-workflow-run-url');
2946029460
const displayWorkflowUrl = displayWorkflowUrlStr && displayWorkflowUrlStr === 'true';
2946129461
const displayWorkflowUrlTimeout = toMilliseconds(core.getInput('display-workflow-run-url-timeout'));
@@ -29501,13 +29501,13 @@ function formatDuration(duration) {
2950129501
let minutesStr = minutes + '';
2950229502
let secondsStr = seconds + '';
2950329503
if (hours < 10) {
29504-
hoursStr = "0" + hoursStr;
29504+
hoursStr = '0' + hoursStr;
2950529505
}
2950629506
if (minutes < 10) {
29507-
minutesStr = "0" + minutesStr;
29507+
minutesStr = '0' + minutesStr;
2950829508
}
2950929509
if (seconds < 10) {
29510-
secondsStr = "0" + secondsStr;
29510+
secondsStr = '0' + secondsStr;
2951129511
}
2951229512
return hoursStr + 'h ' + minutesStr + 'm ' + secondsStr + 's';
2951329513
}
@@ -29727,7 +29727,7 @@ class WorkflowHandler {
2972729727
repo: this.repo
2972829728
});
2972929729
const workflows = workflowsResp.data.workflows;
29730-
(0, debug_1.debug)(`List Workflows`, workflows);
29730+
(0, debug_1.debug)('List Workflows', workflows);
2973129731
// Locate workflow either by name or id
2973229732
const workflowFind = workflows.find((workflow) => workflow.name === this.workflowRef || workflow.id.toString() === this.workflowRef);
2973329733
if (!workflowFind)
@@ -29926,8 +29926,8 @@ function logHandlerFactory(mode) {
2992629926
}
2992729927
}
2992829928
function escapeImportedLogs(str) {
29929-
return str.replace(/^/mg, "| ")
29930-
.replace(/##\[([^\]]+)\]/gm, "##<$1>");
29929+
return str.replace(/^/mg, '| ')
29930+
.replace(/##\[([^\]]+)\]/gm, '##<$1>');
2993129931
}
2993229932

2993329933

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "ncc build src/main.ts -o dist",
8-
"lint": "eslint src/"
8+
"lint": "eslint src/",
9+
"lint-fix": "eslint src/ --fix"
910
},
1011
"keywords": [
1112
"github",

src/debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export function debug(title: string, content: any) {
44
if (core.isDebug()) {
55
core.info(`::group::${title}`)
66
try {
7-
core.debug(JSON.stringify(content, null, 3));
7+
core.debug(JSON.stringify(content, null, 3))
88
} catch(e) {
99
core.debug(`Failed to serialize object, trying toString. Cause: ${e}`)
10-
core.debug(content?.toString());
10+
core.debug(content?.toString())
1111
}
1212
core.info('::endgroup::')
1313
}

src/main.ts

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,66 @@
66
// ----------------------------------------------------------------------------
77

88
import * as core from '@actions/core'
9-
import * as github from '@actions/github'
10-
import { formatDuration, getArgs, isTimedOut, sleep } from './utils';
11-
import { WorkflowHandler, WorkflowRunConclusion, WorkflowRunResult, WorkflowRunStatus } from './workflow-handler';
12-
import { handleWorkflowLogsPerJob } from './workflow-logs-handler';
9+
import { formatDuration, getArgs, isTimedOut, sleep } from './utils'
10+
import { WorkflowHandler, WorkflowRunConclusion, WorkflowRunResult, WorkflowRunStatus } from './workflow-handler'
11+
import { handleWorkflowLogsPerJob } from './workflow-logs-handler'
1312

1413

1514

1615
async function getFollowUrl(workflowHandler: WorkflowHandler, interval: number, timeout: number) {
17-
const start = Date.now();
18-
let url;
16+
const start = Date.now()
17+
let url
1918
do {
20-
await sleep(interval);
19+
await sleep(interval)
2120
try {
22-
const result = await workflowHandler.getWorkflowRunStatus();
23-
url = result.url;
21+
const result = await workflowHandler.getWorkflowRunStatus()
22+
url = result.url
2423
} catch(e: any) {
25-
core.debug(`Failed to get workflow url: ${e.message}`);
24+
core.debug(`Failed to get workflow url: ${e.message}`)
2625
}
27-
} while (!url && !isTimedOut(start, timeout));
28-
return url;
26+
} while (!url && !isTimedOut(start, timeout))
27+
return url
2928
}
3029

3130
async function waitForCompletionOrTimeout(workflowHandler: WorkflowHandler, checkStatusInterval: number, waitForCompletionTimeout: number) {
32-
const start = Date.now();
33-
let status;
34-
let result;
31+
const start = Date.now()
32+
let status
33+
let result
3534
do {
36-
await sleep(checkStatusInterval);
35+
await sleep(checkStatusInterval)
3736
try {
38-
result = await workflowHandler.getWorkflowRunStatus();
39-
status = result.status;
37+
result = await workflowHandler.getWorkflowRunStatus()
38+
status = result.status
4039
core.debug(`Worflow is running for ${formatDuration(Date.now() - start)}. Current status=${status}`)
4140
} catch(e: any) {
42-
core.warning(`Failed to get workflow status: ${e.message}`);
41+
core.warning(`Failed to get workflow status: ${e.message}`)
4342
}
44-
} while (status !== WorkflowRunStatus.COMPLETED && !isTimedOut(start, waitForCompletionTimeout));
43+
} while (status !== WorkflowRunStatus.COMPLETED && !isTimedOut(start, waitForCompletionTimeout))
4544
return { result, start }
4645
}
4746

4847
function computeConclusion(start: number, waitForCompletionTimeout: number, result?: WorkflowRunResult) {
4948
if (isTimedOut(start, waitForCompletionTimeout)) {
50-
core.info(`Workflow wait timed out`);
51-
core.setOutput('workflow-conclusion', WorkflowRunConclusion.TIMED_OUT);
52-
throw new Error('Workflow run has failed due to timeout');
49+
core.info('Workflow wait timed out')
50+
core.setOutput('workflow-conclusion', WorkflowRunConclusion.TIMED_OUT)
51+
throw new Error('Workflow run has failed due to timeout')
5352
}
5453

55-
core.info(`Workflow completed with conclusion=${result?.conclusion}`);
56-
const conclusion = result?.conclusion;
57-
core.setOutput('workflow-conclusion', conclusion);
54+
core.info(`Workflow completed with conclusion=${result?.conclusion}`)
55+
const conclusion = result?.conclusion
56+
core.setOutput('workflow-conclusion', conclusion)
5857

59-
if (conclusion === WorkflowRunConclusion.FAILURE) throw new Error('Workflow run has failed');
60-
if (conclusion === WorkflowRunConclusion.CANCELLED) throw new Error('Workflow run was cancelled');
61-
if (conclusion === WorkflowRunConclusion.TIMED_OUT) throw new Error('Workflow run has failed due to timeout');
58+
if (conclusion === WorkflowRunConclusion.FAILURE) throw new Error('Workflow run has failed')
59+
if (conclusion === WorkflowRunConclusion.CANCELLED) throw new Error('Workflow run was cancelled')
60+
if (conclusion === WorkflowRunConclusion.TIMED_OUT) throw new Error('Workflow run has failed due to timeout')
6261
}
6362

6463
async function handleLogs(args: any, workflowHandler: WorkflowHandler) {
6564
try {
6665
const workflowRunId = await workflowHandler.getWorkflowRunId()
67-
await handleWorkflowLogsPerJob(args, workflowRunId);
66+
await handleWorkflowLogsPerJob(args, workflowRunId)
6867
} catch(e: any) {
69-
core.error(`Failed to handle logs of triggered workflow. Cause: ${e}`);
68+
core.error(`Failed to handle logs of triggered workflow. Cause: ${e}`)
7069
}
7170
}
7271

@@ -75,34 +74,34 @@ async function handleLogs(args: any, workflowHandler: WorkflowHandler) {
7574
//
7675
async function run(): Promise<void> {
7776
try {
78-
const args = getArgs();
79-
const workflowHandler = new WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref, args.runName);
77+
const args = getArgs()
78+
const workflowHandler = new WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref, args.runName)
8079

8180
// Trigger workflow run
82-
await workflowHandler.triggerWorkflow(args.inputs);
83-
core.info(`Workflow triggered 🚀`);
81+
await workflowHandler.triggerWorkflow(args.inputs)
82+
core.info('Workflow triggered 🚀')
8483

8584
if (args.displayWorkflowUrl) {
8685
const url = await getFollowUrl(workflowHandler, args.displayWorkflowUrlInterval, args.displayWorkflowUrlTimeout)
87-
core.info(`You can follow the running workflow here: ${url}`);
88-
core.setOutput('workflow-url', url);
86+
core.info(`You can follow the running workflow here: ${url}`)
87+
core.setOutput('workflow-url', url)
8988
}
9089

9190
if (!args.waitForCompletion) {
92-
return;
91+
return
9392
}
9493

95-
core.info(`Waiting for workflow completion`);
96-
const { result, start } = await waitForCompletionOrTimeout(workflowHandler, args.checkStatusInterval, args.waitForCompletionTimeout);
94+
core.info('Waiting for workflow completion')
95+
const { result, start } = await waitForCompletionOrTimeout(workflowHandler, args.checkStatusInterval, args.waitForCompletionTimeout)
9796

98-
await handleLogs(args, workflowHandler);
97+
await handleLogs(args, workflowHandler)
9998

100-
core.setOutput('workflow-id', result?.id);
101-
core.setOutput('workflow-url', result?.url);
102-
computeConclusion(start, args.waitForCompletionTimeout, result);
99+
core.setOutput('workflow-id', result?.id)
100+
core.setOutput('workflow-url', result?.url)
101+
computeConclusion(start, args.waitForCompletionTimeout, result)
103102

104103
} catch (error: any) {
105-
core.setFailed(error.message);
104+
core.setFailed(error.message)
106105
}
107106
}
108107

0 commit comments

Comments
 (0)