peppa/scripts/mock-act-runner.sh
Асель 56a7756e71 PEP-22: scripts/ci.sh, PR status peppa/ci, mock-act-runner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 15:00:28 +05:00

44 lines
1.6 KiB
Bash
Executable File

#!/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 "<number> <sha>" 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" </dev/null
done
}
pass
while [ -n "$LOOP" ]; do sleep "$LOOP"; pass; done