#!/usr/bin/env bash # Stand-in for Gitea Actions' act_runner until one is registered for peppa-bot/peppa (PEP-22): # picks up open PRs whose head commit has no `peppa/ci` status yet and runs scripts/ci.sh --pr # for each, which reports the status back like a workflow job would. # # scripts/mock-act-runner.sh one pass over open PRs # scripts/mock-act-runner.sh --loop 120 keep polling every 120 s (foreground; not a service) # scripts/mock-act-runner.sh --dry-run only list PRs that would be checked set -uo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" . "$ROOT/scripts/lib/ci-env.sh" . "$ROOT/scripts/gitea-lib.sh" REPO="${PEPPA_CI_REPO:-peppa-bot/peppa}" LOOP="" DRY=0 while [ $# -gt 0 ]; do case "$1" in --loop) LOOP=$2; shift 2 ;; --dry-run) DRY=1; shift ;; *) echo "unknown argument: $1" >&2; exit 2 ;; esac done # Prints " " for open PRs without a peppa/ci status on their head. pending_prs() { gitea_api "$GITEA_URL/api/v1/repos/$REPO/pulls?state=open&limit=50" | python3 -c 'import json,sys for p in json.load(sys.stdin): print(p["number"], p["head"]["sha"])' | while read -r n sha; do gitea_api "$GITEA_URL/api/v1/repos/$REPO/commits/$sha/statuses" | python3 -c 'import json,sys; sys.exit(0 if any(s["context"]=="peppa/ci" for s in json.load(sys.stdin)) else 1)' || echo "$n $sha" done } pass() { pending_prs | while read -r n sha; do echo "mock-act-runner: PR $n @ ${sha:0:8}" [ "$DRY" = 1 ] || bash "$ROOT/scripts/ci.sh" --pr "$n"