Wait For Ci

______________________________________________________________________

bdperkin updated 1mo ago
Claude CodeGeneric
View source ↗
# Wait for CI

______________________________________________________________________

## title: 'Wait for CI/CD Checks' read_only: false type: 'command'

Monitor and wait for GitHub Actions CI/CD checks to complete on a pull request.

## Process

This command monitors PR checks until all pass, fail, or timeout:

1. **Validate PR Number**

   - Verify PR exists
   - Check PR is not already merged
   - Get current check status

1. **Monitor Checks**

   - Poll `gh pr checks` at regular intervals
   - Count passed, pending, and failed checks
   - Detect when all checks complete
   - Display progress updates

1. **Determine Outcome**

   - **All Pass**: Exit success (0)
   - **Any Fail**: Exit failure (1) with details
   - **Timeout**: Exit timeout (2) with status

1. **Report Results**

   - Show final status
   - List any failed checks
   - Show total duration
   - Provide next steps

## Detection Logic

**Check Status Values** (from `gh pr checks`):

- `pass` - Check passed successfully
- `fail` or `failure` - Check failed
- `pending` - Check still running
- `skipped` - Check was skipped
- `neutral` - Check completed but neutral status

**Completion Detection**:

```bash
# Count checks by status
PASSED=$(gh pr checks <pr> 2>&1 | grep -c "pass")
FAILED=$(gh pr checks <pr> 2>&1 | grep -cE "fail|failure")
PENDING=$(gh pr checks <pr> 2>&1 | grep -c "pending")

# All complete when no pending checks
if [ $PENDING -eq 0 ]; then
  if [ $FAILED -eq 0 ]; then
    echo "✅ All checks passed!"
    exit 0
  else
    echo "❌ $FAILED check(s) failed"
    exit 1
  fi
fi

Usage

# Wait for PR checks (default: 30 min timeout, 30s interval)
/wait-for-ci 53

# Custom timeout (seconds)
/wait-for-ci 53 --timeout 3600

# Custom poll interval (seconds)
/wait-for-ci 53 --interval 15

# Quiet mode (minimal output)
/wait-for-ci 53 --quiet

# Verbose mode (show all check details)
/wait-for-ci 53 --verbose

Examples

Basic Usage

# Monitor PR #53
/wait-for-ci 53

# Output:
# ⏳ Waiting for CI checks on PR #53...
# [1/60] Still running... (12/35 passed, 23 pending)
# [2/60] Still running... (28/35 passed, 7 pending)
# [3/60] Still running... (34/35 passed, 1 pending)
# ✅ All 35 checks passed! (Duration: 1m 45s)

With Failure

# Monitor PR with failing check
/wait-for-ci 54

# Output:
# ⏳ Waiting for CI checks on PR #54...
# [1/60] Still running... (15/35 passed, 20 pending)
# [2/60] Still running... (33/35 passed, 2 pending)
# ❌ 2 check(s) failed:
#   - Test on Python 3.12: https://github.com/.../actions/runs/...
#   - Tox tests with UV (mypy): https://github.com/.../actions/runs/...

Timeout

# Monitor with 5 minute timeout
/wait-for-ci 53 --timeout 300

# Output:
# ⏳ Waiting for CI checks on PR #53...
# [1/10] Still running... (12/35 passed, 23 pending)
# ...
# ⏱️  Timeout after 5 minutes
# Status: 30/35 passed, 5 pending
# Pending checks:
#   - Tox tests with UV (coverage)
#   - Tox tests with UV (mypy)
#   ...

Script Implementation

Location: .github/scripts/wait-for-ci.sh

#!/usr/bin/env bash
# Wait for GitHub Actions CI/CD checks to complete

set -e

# Configuration
PR_NUMBER="$1"
TIMEOUT="${2:-1800}"  # Default: 30 minutes
INTERVAL="${3:-30}"   # Default: 30 seconds
QUIET="${QUIET:-false}"
VERBOSE="${VERBOSE:-false}"

# Validate PR number
if [ -z "$PR_NUMBER" ]; then
  echo "❌ Error: PR number required"
  echo "Usage: $0 <pr-number> [timeout] [interval]"
  exit 1
fi

# Check PR exists
if ! gh pr view "$PR_NUMBER" &>/dev/null; then
  echo "❌ Error: PR #$PR_NUMBER not found"
  exit 1
fi

# Start monitoring
START_TIME=$(date +%s)
MAX_ITERATIONS=$((TIMEOUT / INTERVAL))
ITERATION=0

echo "⏳ Waiting for CI checks on PR #$PR_NUMBER..."
echo "   Timeout: ${TIMEOUT}s, Interval: ${INTERVAL}s"
echo ""

while [ $ITERATION -lt $MAX_ITERATIONS ]; do
  ITERATION=$((ITERATION + 1))

  # Get check status
  STATUS=$(gh pr checks "$PR_NUMBER" 2>&1)

  # Count by status (FIX: use "pass" not "success")
  PASSED=$(echo "$STATUS" | grep -c "pass" || true)
  FAILED=$(echo "$STATUS" | grep -cE "fail|failure" || true)
  PENDING=$(echo "$STATUS" | grep -c "pending" || true)
  TOTAL=$((PASSED + FAILED + PENDING))

  # Check for completion
  if [ "$PENDING" -eq 0 ]; then
    ELAPSED=$(($(date +%s) - START_TIME))
    DURATION=$(printf "%dm %ds" $((ELAPSED / 60)) $((ELAPSED % 60)))

    if [ "$FAILED" -eq 0 ]; then
      echo ""
      echo "✅ All $PASSED checks passed! (Duration: $DURATION)"
      echo ""

      if [ "$VERBOSE" = "true" ]; then
        echo "Passed checks:"
        echo "$STATUS" | grep "pass" | head -10
        echo ""
      fi

      exit 0
    else
      echo ""
      echo "❌ $FAILED check(s) failed:"
      echo "$STATUS" | grep -E "fail|failure"
      echo ""
      echo "Duration: $DURATION"
      exit 1
    fi
  fi

  # Progress update
  if [ "$QUIET" != "true" ]; then
    echo "[$ITERATION/$MAX_ITERATIONS] Still running... ($PASSED/$TOTAL passed, $PENDING pending)"
  fi

  # Show verbose details
  if [ "$VERBOSE" = "true" ]; then
    echo "  Pending:"
    echo "$STATUS" | grep "pending" | head -5
    echo ""
  fi

  sleep "$INTERVAL"
done

# Timeout
ELAPSED=$(($(date +%s) - START_TIME))
DURATION=$(printf "%dm %ds" $((ELAPSED / 60)) $((ELAPSED % 60)))

echo ""
echo "⏱️  Timeout after $DURATION"
echo "Status: $PASSED/$TOTAL passed, $PENDING pending"
echo ""
echo "Pending checks:"
echo "$STATUS" | grep "pending"
echo ""
echo "Re-run: gh run watch \$(gh run list --branch <branch> --limit 1 --json databaseId -q '.[0].databaseId')"

exit 2

Configuration

Environment Variables

# Quiet mode (minimal output)
export QUIET=true

# Verbose mode (detailed check info)
export VERBOSE=true

# Custom timeout (seconds)
export CI_WAIT_TIMEOUT=3600

# Custom poll interval (seconds)
export CI_POLL_INTERVAL=15

Per-Repository Settings

Add to .github/ci-wait.conf:

# Default timeout (seconds)
TIMEOUT=1800

# Poll inte

Maintain Wait For Ci?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Wait For Ci on getagentictools](https://getagentictools.com/loops/bdperkin-wait-for-ci?ref=badge)
npx agentictools info loops/bdperkin-wait-for-ci

The second line is the CLI lookup for this page — handy in READMEs and docs.