mirror of
https://github.com/kamilchodola/wait-for-workflow-action.git
synced 2026-04-29 15:47:40 -05:00
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
with:
|
||||
workflow: to_be_triggered.yml
|
||||
token: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
|
||||
ref: main
|
||||
ref: "${{ inputs.ref || github.ref }}"
|
||||
|
||||
- name: Wait for the triggered workflow to complete
|
||||
run: |
|
||||
@@ -34,8 +34,10 @@ jobs:
|
||||
export GITHUB_TOKEN="${{ secrets.REPOSITORY_DISPATCH_TOKEN }}"
|
||||
export WORKFLOW_ID="to_be_triggered.yml"
|
||||
export RUN_ID="${{ inputs.run_id }}"
|
||||
export MAX_WAIT_MINUTES="5"
|
||||
export MAX_WAIT_MINUTES="2"
|
||||
export INTERVAL="5"
|
||||
export TIMEOUT="2"
|
||||
export ORG_NAME="kamilchodola"
|
||||
export REPO_NAME="wait-for-workflow-action"
|
||||
export REF="${{ inputs.ref }}"
|
||||
export REF="${{ inputs.ref || github.ref }}"
|
||||
./scripts/wait-for-workflow.sh
|
||||
|
||||
@@ -11,7 +11,9 @@ This GitHub Action waits for a specified workflow to complete before proceeding
|
||||
| `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 wait time in minutes before giving up | No | 5 |
|
||||
| `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 |
|
||||
| `timeouts`| Maximum time script will wait to workflow run to be finished | No | 30 |
|
||||
| `organization` | Organization name where the repository is located | Yes | |
|
||||
| `repository` | Repository name to monitor for the workflow run | Yes | |
|
||||
| `ref` | Branch reference to watch for the workflow run | No | |
|
||||
@@ -46,6 +48,8 @@ To use this action, add it to your workflow file with the appropriate inputs:
|
||||
GITHUB_TOKEN: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
|
||||
workflow_id: 'workflow_name.yml'
|
||||
max_wait_minutes: '3'
|
||||
interval: '5'
|
||||
timeout: '60'
|
||||
organization: 'your-organization'
|
||||
repository: 'your-repository'
|
||||
ref: ${{ github.ref }}
|
||||
|
||||
14
action.yml
14
action.yml
@@ -15,8 +15,16 @@ inputs:
|
||||
required: false
|
||||
max_wait_minutes:
|
||||
description: 'Maximum time script will wait to workflow run to be found in minutes'
|
||||
required: true
|
||||
required: false
|
||||
default: '5'
|
||||
interval:
|
||||
description: 'Interval in seconds which will be used for GitHub API calls'
|
||||
required: false
|
||||
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
|
||||
@@ -37,6 +45,8 @@ runs:
|
||||
WORKFLOW_ID: ${{ inputs.workflow_id }}
|
||||
RUN_ID: ${{ inputs.run_id }}
|
||||
MAX_WAIT_MINUTES: ${{ inputs.max_wait_minutes }}
|
||||
INTERVAL: ${{ inputs.interval }}
|
||||
TIMEOUT: ${{ inputs.timeout }}
|
||||
ORG_NAME: ${{ inputs.organization }}
|
||||
REPO_NAME: ${{ inputs.repository }}
|
||||
REF: ${{ inputs.ref }
|
||||
REF: ${{ inputs.ref || github.ref }}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
# Set the maximum waiting time (in minutes) and initialize the counter
|
||||
max_wait_minutes="${MAX_WAIT_MINUTES}"
|
||||
timeout="${TIMEOUT}"
|
||||
interval="${INTERVAL}"
|
||||
counter=0
|
||||
|
||||
# Get the current time in ISO 8601 format
|
||||
@@ -18,6 +20,8 @@ echo "ℹ️ Organization: ${ORG_NAME}"
|
||||
echo "ℹ️ Repository: ${REPO_NAME}"
|
||||
echo "ℹ️ Reference: $REF"
|
||||
echo "ℹ️ Maximum wait time: ${max_wait_minutes} minutes"
|
||||
echo "ℹ️ Timeout for the workflow to complete: ${timeout} minutes"
|
||||
echo "ℹ️ Interval between checks: ${interval} seconds"
|
||||
|
||||
# If RUN_ID is not empty, use it directly
|
||||
if [ -n "${RUN_ID}" ]; then
|
||||
@@ -49,16 +53,17 @@ else
|
||||
|
||||
# Increment the counter and check if the maximum waiting time is reached
|
||||
counter=$((counter + 1))
|
||||
if [ $((counter * 30)) -ge $((max_wait_minutes * 60)) ]; then
|
||||
if [ $((counter * $interval)) -ge $((max_wait_minutes * 60)) ]; then
|
||||
echo "❌ Maximum waiting time for the workflow to be triggered has been reached. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 30
|
||||
sleep $interval
|
||||
done
|
||||
fi
|
||||
|
||||
# Wait for the triggered workflow to complete and check its conclusion
|
||||
timeout_counter=0
|
||||
while true; do
|
||||
echo "⌛ Waiting for the workflow to complete..."
|
||||
run_data=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $GITHUB_TOKEN" \
|
||||
@@ -75,5 +80,13 @@ while true; do
|
||||
break
|
||||
fi
|
||||
fi
|
||||
sleep 30
|
||||
|
||||
# Increment the timeout counter and check if the timeout has been reached
|
||||
timeout_counter=$((timeout_counter + 1))
|
||||
if [ $((timeout_counter * interval)) -ge $((timeout * 60)) ]; then
|
||||
echo "❌ Timeout waiting for the workflow to complete. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep $interval
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user