Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GitHub Action for Dispatching Workflows

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

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.
Expand Down Expand Up @@ -64,6 +64,10 @@ This option is also left for backwards compatibility with older versions where t

**Optional.** The maximum time in seconds to wait for the triggered workflow run to complete before timing out. This only applies if `wait-for-completion` is set to `true`. Default is `900` seconds (15 minutes).

### `wait-interval-seconds`

**Optional.** Interval in seconds between polls. This only applies if `wait-for-completion` is set to `true`. Default is `5` seconds.

Comment on lines +67 to +70
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

### `sync-status`

**Optional.** Set to `'true'` to sync the status of this action with the triggered workflow run. If the triggered workflow run fails or is cancelled, this action will also be set to failed. This only applies if `wait-for-completion` is set to `true`. Default is `false`.
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: 'Maximum time in seconds to wait for the workflow run to complete before timing out (only applies if wait-for-completion is true)'
required: false
default: 900
wait-interval-seconds:
description: 'Interval in seconds between polls (only applies if wait-for-completion is true)'
required: false
default: 5
sync-status:
description: 'Whether to set the status of this action to failed if the triggered workflow run fails, or is cancelled. Only applies if wait-for-completion is true.'
required: false
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23633,6 +23633,7 @@ async function run() {
const waitForCompletion = getInput("wait-for-completion") === "true";
const syncStatus = getInput("sync-status") === "true";
const timeoutSeconds = parseInt(getInput("wait-timeout-seconds") || "900", 10);
const waitIntervalSeconds = parseInt(getInput("wait-interval-seconds") || "5", 10);
let runStatus = "in_progress";
if (waitForCompletion) {
info(`\u23F3 Waiting for workflow run to complete with a timeout of ${timeoutSeconds} seconds...`);
Expand All @@ -23646,7 +23647,7 @@ Note: The workflow is still running but we have stopped waiting. You can check t
runStatus = "timed_out";
break;
}
await new Promise((resolve) => setTimeout(resolve, 5e3));
await new Promise((resolve) => setTimeout(resolve, waitIntervalSeconds * 1e3));
const { data: runData } = await octokit.request(
`GET /repos/${owner}/${repo}/actions/runs/${dispatchResp.data.workflow_run_id}`
);
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async function run(): Promise<void> {
const waitForCompletion = core.getInput('wait-for-completion') === 'true'
const syncStatus = core.getInput('sync-status') === 'true'
const timeoutSeconds = parseInt(core.getInput('wait-timeout-seconds') || '900', 10) // Default to 15 minutes
const waitIntervalSeconds = parseInt(core.getInput('wait-interval-seconds') || '5', 10) // Default to 5 seconds
Comment thread
benc-uk marked this conversation as resolved.
let runStatus = 'in_progress'

// Polling loop to check workflow run status until it completes or times out
Expand All @@ -105,7 +106,7 @@ async function run(): Promise<void> {
break
}

await new Promise((resolve) => setTimeout(resolve, 5000)) // Wait for 5 seconds before polling again
await new Promise((resolve) => setTimeout(resolve, waitIntervalSeconds * 1000)) // Wait for waitIntervalSeconds before polling again

const { data: runData } = await octokit.request(
`GET /repos/${owner}/${repo}/actions/runs/${dispatchResp.data.workflow_run_id}`,
Expand Down
Loading