forked from kamilchodola/wait-for-workflow-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
155 additions
and
106 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* @kamilchodola | ||
* @lucasssvaz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,95 @@ | ||
# Wait for Workflow Action | ||
|
||
[![Test WaitForWorkflow](https://github.com/kamilchodola/wait-for-workflow-action/actions/workflows/test.yml/badge.svg)](https://github.com/kamilchodola/wait-for-workflow-action/actions/workflows/test.yml) | ||
[![Test WaitForWorkflow](https://github.com/lucasssvaz/wait-for-workflow-action/actions/workflows/test.yml/badge.svg)](https://github.com/lucasssvaz/wait-for-workflow-action/actions/workflows/test.yml) | ||
|
||
This GitHub Action waits for a specified workflow to complete before proceeding with the next steps in your workflow. It is useful when you have dependent workflows and want to ensure that one completes successfully before continuing with the next. For example, you might want to ensure that a build or test workflow finishes successfully before starting a deployment workflow. | ||
|
||
## Inputs | ||
|
||
| Input | Description | Required | Default | | ||
|------------------|-----------------------------------------------------|----------|---------| | ||
| `GITHUB_TOKEN` | GitHub token to access the repository and its APIs | Yes | | | ||
| `workflow_id` | ID of the workflow to wait for | No | | | ||
| `run_id` | If provided will wait for workflow run with specified id | No | | | ||
| `max_wait_minutes`| Maximum time script will wait to workflow run to be found in minutes | No | 5 | | ||
| `interval`| Interval in seconds which will be used for GitHub API calls | No | 10 | | ||
| `timeout`| Maximum time script will wait to workflow run to be finished | No | 30 | | ||
| `org_name` | Organization name where the repository is located | Yes | | | ||
| `repo_name` | Repository name to monitor for the workflow run | Yes | | | ||
| `ref` | Branch reference to watch for the workflow run | No | | | ||
| Input | Description | Required | Default | | ||
|-----------------|---------------------------------------------------------------------------------|----------------------------------|----------------------------| | ||
| `github-token` | GitHub token to access the repository and its APIs | No | `${{ github.token }}` | | ||
| `workflow_name` | File name of the workflow to wait for | Yes (No if `run_id` is provided) | | | ||
| `run_id` | Wait for a specific run ID | No | | | ||
| `max_wait` | Maximum time the script will wait for the workflow run to be found (minutes) | No | `5` | | ||
| `interval` | Interval between checking workflow status (seconds) | No | `10` | | ||
| `timeout` | Maximum time the script will wait for the workflow run to be finished (minutes) | No | `30` | | ||
| `repository` | Repository name with owner | No | `${{ github.repository }}` | | ||
| `ref` | Branch reference to watch for the workflow run | No | `${{ github.ref }}` | | ||
| `verbose` | Enable verbose output | No | `false` | | ||
|
||
## Outputs | ||
|
||
| Output | Description | | ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `run_id` | ID of the workflow run that was waited for | | ||
| `conclusion` | Conclusion of the workflow run. Can be one of the `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, or `action_required` | | ||
|
||
## How It Works | ||
|
||
This action performs the following steps: | ||
|
||
1. Retrieves the current time in ISO 8601 format. | ||
2. Loops until the specified workflow is triggered: | ||
- Sends a request to the GitHub API to get the list of workflow runs for the specified workflow ID. | ||
- Sends a request to the GitHub API to get the list of workflow runs for the specified `workflow_name`. | ||
- Filters the list of workflow runs based on the provided `ref` (branch) and the run creation time. | ||
- Checks if the maximum waiting time has been reached. If so, exits with an error message. | ||
- Sleeps for 30 seconds before checking again if the workflow has been triggered. | ||
3. Once the workflow is triggered, loops until the workflow run is completed: | ||
- Sleeps for `interval` seconds before checking again if the workflow has been triggered. | ||
3. Once the workflow is triggered, sets the `run_id` output and loops until the workflow run is completed: | ||
- Sends a request to the GitHub API to get the status of the specified workflow run. | ||
- Checks if the status is "completed". If so, proceeds to the next step. | ||
- Sleeps for 30 seconds before checking again if the workflow has been completed. | ||
4. When the workflow run is completed, checks its conclusion: | ||
- If the conclusion is "success", the action exits successfully. | ||
- If the conclusion is anything other than "success", the action exits with an error message. | ||
|
||
- Sleeps for `interval` seconds before checking again if the workflow has been completed. | ||
4. When the workflow run is completed, sets the `conclusion` output to the conclusion of the workflow run. | ||
|
||
## Usage | ||
|
||
To use this action, add it to your workflow file with the appropriate inputs: | ||
|
||
```yaml | ||
- name: Wait for Workflow Action | ||
uses: kamilchodola/wait-for-workflow-action@1.1.0 | ||
uses: lucasssvaz/wait-for-workflow-action@v2 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }} | ||
workflow_id: 'workflow_name.yml' | ||
max_wait_minutes: '3' | ||
interval: '5' | ||
timeout: '60' | ||
org_name: 'your-organization' | ||
repo_name: 'your-repository' | ||
ref: '${{ github.ref }}' | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
workflow_name: workflow.yml | ||
max_wait: 3 | ||
interval: 5 | ||
timeout: 60 | ||
ref: ${{ github.ref }} | ||
``` | ||
|
||
In case, you already have run_id, you can pass it this way: | ||
In case, you already have a workflow run ID, you can pass it this way: | ||
|
||
```yaml | ||
- name: Wait for Workflow Action | ||
uses: kamilchodola/wait-for-workflow-action@1.1.0 | ||
uses: lucasssvaz/wait-for-workflow-action@v2 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }} | ||
workflow_id: 'workflow_name.yml' | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
run_id: '123123' | ||
org_name: 'your-organization' | ||
repo_name: 'your-repository' | ||
ref: '${{ github.ref }}' | ||
``` | ||
|
||
To access the outputs of this action, you can use the `id` specified in the action step: | ||
|
||
```yaml | ||
- name: Wait for Workflow Action | ||
uses: lucasssvaz/wait-for-workflow-action@v2 | ||
id: wait-for-workflow | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
workflow_name: workflow.yml | ||
max_wait: 3 | ||
interval: 5 | ||
timeout: 60 | ||
ref: ${{ github.ref }} | ||
|
||
- name: Get the workflow run ID | ||
run: | | ||
echo "Workflow run ID: ${{ steps.wait-for-workflow.outputs.run_id }}" | ||
echo "Workflow conclusion: ${{ steps.wait-for-workflow.outputs.conclusion }}" | ||
``` | ||
|
||
## Notes | ||
|
||
- At least one of the `workflow_name` or `run_id` inputs must be provided. If both are provided, the action will use the `run_id` input. | ||
- If the `ref` input is not provided or is left empty, the action will use the current `github.ref` as the branch reference. This is useful when you want to wait for a workflow run on the same branch that triggered the current workflow. | ||
- The maximum wait time is specified in minutes. The default value is 3 minutes if not provided. If the workflow has not been triggered or completed after the specified maximum wait time, the action will exit with an error. You can increase this value if you expect the workflow to take longer to start or complete. Keep in mind that the GitHub Actions runner has a default timeout of 6 hours for a job, so ensure your wait time falls within this limit. | ||
- The maximum wait time is specified in minutes. If the workflow has not been triggered or completed after the specified maximum wait time, the action will exit with an error. You can increase this value if you expect the workflow to take longer to start or complete. Keep in mind that the GitHub Actions runner has a default timeout of 6 hours for a job, so ensure your wait time falls within this limit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
name: 'Wait for Workflow Action' | ||
name: "Wait for Workflow Action" | ||
branding: | ||
icon: 'clock' | ||
color: 'blue' | ||
description: 'Waits for a specified workflow to complete before proceeding' | ||
icon: "clock" | ||
color: "blue" | ||
description: "Waits for a specified workflow to complete before proceeding" | ||
inputs: | ||
GITHUB_TOKEN: | ||
description: 'GitHub token to access the repository' | ||
required: true | ||
workflow_id: | ||
description: 'ID of the workflow to wait for' | ||
required: false | ||
github-token: | ||
description: "GitHub token to access the repository" | ||
default: "${{ github.token }}" | ||
workflow_name: | ||
description: "File name of the workflow to wait for" | ||
run_id: | ||
description: 'If provided will wait for workflow run with specified id' | ||
required: false | ||
max_wait_minutes: | ||
description: 'Maximum time script will wait to workflow run to be found in minutes' | ||
required: false | ||
default: '5' | ||
description: "Wait for a specific run ID" | ||
max_wait: | ||
description: "Maximum time the script will wait for the workflow run to be found (minutes)" | ||
default: 5 | ||
interval: | ||
description: 'Interval in seconds which will be used for GitHub API calls' | ||
required: false | ||
default: '10' | ||
description: "Interval between checking workflow status (seconds)" | ||
default: 10 | ||
timeout: | ||
description: 'Maximum time script will wait to workflow run to be finished' | ||
required: false | ||
default: '30' | ||
org_name: | ||
description: 'GitHub organization name' | ||
required: true | ||
repo_name: | ||
description: 'GitHub repository name' | ||
required: true | ||
description: "Maximum time the script will wait for the workflow run to be finished (minutes)" | ||
default: 30 | ||
repository: | ||
description: "Repository name with owner" | ||
default: "${{ github.repository }}" | ||
ref: | ||
description: 'Branch reference (if empty, ref selected for trigger would be taken)' | ||
required: false | ||
default: '' | ||
description: "Branch reference to watch for the workflow run" | ||
default: "${{ github.ref }}" | ||
verbose: | ||
description: "Enable verbose output" | ||
default: false | ||
outputs: | ||
run_id: | ||
description: "ID of the workflow run" | ||
value: ${{ steps.wait-for-workflow.outputs.run_id }} | ||
conclusion: | ||
description: "Conclusion of the workflow run. Can be one of the `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, or `action_required`" | ||
value: ${{ steps.wait-for-workflow.outputs.conclusion }} | ||
runs: | ||
using: 'composite' | ||
using: "composite" | ||
steps: | ||
- name: Set execute permissions for script | ||
run: chmod +x ${{ github.action_path }}/scripts/wait-for-workflow.sh | ||
shell: bash | ||
- run: ${{ github.action_path }}/scripts/wait-for-workflow.sh | ||
- id: wait-for-workflow | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} | ||
WORKFLOW_ID: ${{ inputs.workflow_id }} | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
WORKFLOW_NAME: ${{ inputs.workflow_name }} | ||
RUN_ID: ${{ inputs.run_id }} | ||
MAX_WAIT_MINUTES: ${{ inputs.max_wait_minutes }} | ||
MAX_WAIT: ${{ inputs.max_wait }} | ||
INTERVAL: ${{ inputs.interval }} | ||
TIMEOUT: ${{ inputs.timeout }} | ||
ORG_NAME: ${{ inputs.org_name }} | ||
REPO_NAME: ${{ inputs.repo_name }} | ||
REF: ${{ inputs.ref || github.ref }} | ||
REPOSITORY: ${{ inputs.repository }} | ||
REF: ${{ inputs.ref }} | ||
VERBOSE: ${{ inputs.verbose }} | ||
run: | | ||
${{ github.action_path }}/scripts/wait-for-workflow.sh | ||
echo "run_id=$(echo $WORKFLOW_RUN_ID)" >> $GITHUB_OUTPUT | ||
echo "conclusion=$(echo $WORKFLOW_CONCLUSION)" >> $GITHUB_OUTPUT |
Oops, something went wrong.