Skip to content

Commit ced6293

Browse files
misc(info) Log the url of the triggered workflow even if we don't wait for completion
1 parent 26d8ae6 commit ced6293

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.20.0

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,23 @@ The solution is to manually create a PAT and store it as a secret e.g. `${{ secr
3939
**Optional.** The time to wait to mark triggered workflow has timed out. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1h`
4040

4141
### `wait-for-completion-interval`
42-
**Optional.** The time to wait between two polls for getting run status. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `30s`.
42+
**Optional.** The time to wait between two polls for getting run status. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1m`.
43+
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
44+
45+
### `display-worflow-run-url`
46+
**Optional.** If `true`, it displays in logs the URL of the triggered workflow. It is useful to follow the progress of the triggered workflow. It is enabled by default.
47+
48+
### `display-worflow-run-url-timeout`
49+
**Optional.** The time to wait for getting the workflow run URL. If the timeout is reached, it doesn't fail and continues. Displaying the workflow URL is just for information purpose. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `display-worflow-run-url` is `false`. Default is `10m`
50+
51+
### `display-worflow-run-url-interval`
52+
**Optional.** The time to wait between two polls for getting workflow run URL. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `display-worflow-run-url` is `false`. Default is `1m`.
4353
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
4454

4555
## Outputs
56+
### `workflow-url`
57+
The URL of the workflow run that has been triggered. It may be undefined if the URL couldn't be retrieved (timeout reached) or if `wait-for-completion` and `display-worflow-run-url` are both `false`
58+
4659
### `workflow-conclusion`
4760
The result of the triggered workflow. May be one of `success`, `failure`, `cancelled`, `timed_out`, `skipped`, `neutral`, `action_required`. The step in your workflow will fail if the triggered workflow completes with `failure`, `cancelled` or `timed_out`. Other workflow conlusion are considered success.
4861
Only available if `wait-for-completion` is `true`

action.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ inputs:
1717
repo:
1818
description: 'Repo owner & name, slash separated, only set if invoking a workflow in a different repo'
1919
required: false
20+
display-workflow-run-url:
21+
description: 'Get the URL of the triggered workflow and display it in logs (useful to follow the progress of the triggered workflow)'
22+
required: false
23+
default: true
24+
display-workflow-run-url-interval:
25+
description: 'The time to wait (+unit) between two polls to get the URL of the workflow run'
26+
required: false
27+
default: 1m
28+
display-workflow-run-url-timeout:
29+
description: 'Maximum amount of time (+unit) to wait for the URL of the workflow run. If the timeout is reached, it is just ignored'
30+
required: false
31+
default: 10m
2032
wait-for-completion:
2133
description: 'Block until the triggered workflow has finished'
2234
required: false
@@ -28,7 +40,7 @@ inputs:
2840
wait-for-completion-interval:
2941
description: 'Time to wait (+unit) between two polls to get run status'
3042
required: false
31-
default: 30s
43+
default: 1m
3244

3345
runs:
3446
using: 'node12'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workflow-dispatch-and-wait",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Trigger running GitHub Actions workflows and wait for result",
55
"main": "dist/index.js",
66
"scripts": {

src/main.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,32 @@ import * as github from '@actions/github'
1010
import { formatDuration, getArgs, isTimedOut, sleep } from './utils';
1111
import { WorkflowHandler, WorkflowRunConclusion, WorkflowRunResult, WorkflowRunStatus } from './workflow-handler';
1212

13+
14+
15+
async function getFollowUrl(workflowHandler: WorkflowHandler, interval: number, timeout: number) {
16+
const start = Date.now();
17+
let url;
18+
do {
19+
await sleep(interval);
20+
try {
21+
const result = await workflowHandler.getWorkflowRunStatus();
22+
url = result.url;
23+
} catch(e) {
24+
core.debug(`Failed to get workflow url: ${e.message}`);
25+
}
26+
} while (!url && !isTimedOut(start, timeout));
27+
return url;
28+
}
29+
1330
async function waitForCompletionOrTimeout(workflowHandler: WorkflowHandler, checkStatusInterval: number, waitForCompletionTimeout: number) {
1431
const start = Date.now();
15-
let first = true;
1632
let status;
1733
let result;
1834
do {
1935
await sleep(checkStatusInterval);
2036
try {
2137
result = await workflowHandler.getWorkflowRunStatus();
2238
status = result.status;
23-
if (first) {
24-
core.info(`You can follow the running workflow here: ${result.url}`);
25-
first = false;
26-
}
2739
core.debug(`Worflow is running for ${formatDuration(Date.now() - start)}. Current status=${status}`)
2840
} catch(e) {
2941
core.warning(`Failed to get workflow status: ${e.message}`);
@@ -60,13 +72,20 @@ async function run(): Promise<void> {
6072
workflowHandler.triggerWorkflow(args.inputs);
6173
core.info(`Workflow triggered 🚀`);
6274

75+
if (args.displayWorkflowUrl) {
76+
const url = await getFollowUrl(workflowHandler, args.displayWorkflowUrlInterval, args.displayWorkflowUrlTimeout)
77+
core.info(`You can follow the running workflow here: ${url}`);
78+
core.setOutput('workflow-url', url);
79+
}
80+
6381
if (!args.waitForCompletion) {
6482
return;
6583
}
6684

6785
core.info(`Waiting for workflow completion`);
6886
const { result, start } = await waitForCompletionOrTimeout(workflowHandler, args.checkStatusInterval, args.waitForCompletionTimeout);
6987

88+
core.setOutput('workflow-url', result?.url);
7089
computeConclusion(start, args.waitForCompletionTimeout, result);
7190

7291
} catch (error) {

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export function getArgs() {
3434
inputs = JSON.parse(inputsJson);
3535
}
3636

37+
const displayWorkflowUrlStr = core.getInput('display-workflow-run-url');
38+
const displayWorkflowUrl = displayWorkflowUrlStr && displayWorkflowUrlStr === 'true';
39+
const displayWorkflowUrlTimeout = toMilliseconds(core.getInput('display-workflow-run-url-timeout'));
40+
const displayWorkflowUrlInterval = toMilliseconds(core.getInput('display-workflow-run-url-interval'));
41+
3742
const waitForCompletionStr = core.getInput('wait-for-completion');
3843
const waitForCompletion = waitForCompletionStr && waitForCompletionStr === 'true';
3944
const waitForCompletionTimeout = toMilliseconds(core.getInput('wait-for-completion-timeout'));
@@ -46,6 +51,9 @@ export function getArgs() {
4651
owner,
4752
repo,
4853
inputs,
54+
displayWorkflowUrl,
55+
displayWorkflowUrlTimeout,
56+
displayWorkflowUrlInterval,
4957
checkStatusInterval,
5058
waitForCompletion,
5159
waitForCompletionTimeout

0 commit comments

Comments
 (0)