peppa/template/.gitea/peppa-check.sh
peppa-bot 10363f8592 PEP-270: задачи агентов — предложения, не больше 5 в сутки на проект
- MCP create_task агента: origin agent + «Предложено» (раньше — задача человека, диспетчер брал её сам)
- AgentLimits.perDay (5, скользящие 24 ч), proposalRoom/proposalsToday; сверх — отказ агенту,
  находки приёмки — в недельную сводку; событие proposal_limited
- CLI agent-limits perDay=N, правило агентам в template/RULES.md, тест proposal-daily-limit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 17:02:04 +00:00

48 lines
2.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Шаг CI FORGE: bash .gitea/peppa-check.sh <проверка>
# Команда — .peppa/project.json → checks.<проверка>; нет команды — шаг пропущен.
# Результат: статус коммита «peppa/<проверка>» в Gitea и отчёт в FORGE с хвостом лога
# (подпись HMAC-SHA256 секретом PEPPA_CI_SECRET). Шаг «install» сообщает только о провале.
# Локально (без CI): bash .gitea/peppa-check.sh test — просто выполнит команду.
set -uo pipefail
check="$1"
cfg=.peppa/project.json
cmd=$(jq -r --arg c "$check" '.checks[$c] // empty' "$cfg" 2>/dev/null)
if [[ -z "$cmd" ]]; then
echo "peppa: проверка «$check» не настроена — пропуск"
exit 0
fi
log=$(mktemp)
started=$(date +%s)
bash -o pipefail -c "$cmd" 2>&1 | tee "$log"
code=${PIPESTATUS[0]}
took=$(($(date +%s) - started))
[[ -n "${GITHUB_ACTIONS:-}" ]] || exit "$code"
state=success
[[ $code -eq 0 ]] || state=failure
[[ $check == install && $state == success ]] && exit 0
sha="${PEPPA_SHA:-$GITHUB_SHA}"
# Относительная ссылка, как у статусов самой Gitea (GITHUB_SERVER_URL здесь внутренний).
run_url="/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_NUMBER"
if [[ -n "${GITEA_TOKEN:-}" ]]; then
jq -n --arg s "$state" --arg c "peppa/$check" --arg u "$run_url" --arg d "$check: $state за ${took}с" \
'{state:$s, context:$c, target_url:$u, description:$d}' |
curl -fsS -o /dev/null -X POST -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
--data-binary @- "$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/statuses/$sha" ||
echo "peppa: не удалось записать статус коммита"
fi
peppa_url=$(jq -r '.peppaUrl // empty' "$cfg")
if [[ -n "$peppa_url" && -n "${PEPPA_CI_SECRET:-}" ]]; then
body=$(tail -n 200 "$log" | jq -Rs --arg repo "$GITHUB_REPOSITORY" --arg sha "$sha" --arg branch "${PEPPA_BRANCH:-}" \
--arg pr "${PEPPA_PR:-}" --arg check "$check" --arg state "$state" --arg url "$run_url" --argjson took "$took" \
'{repository:$repo, sha:$sha, branch:$branch, pr:($pr|tonumber? // null), check:$check, state:$state, run_url:$url, duration_sec:$took, log_tail:.}')
sig=$(printf '%s' "$body" | openssl dgst -sha256 -hmac "$PEPPA_CI_SECRET" | awk '{print $NF}')
curl -fsS -o /dev/null -m 20 -X POST "$peppa_url/api/hooks/gitea" -H "Content-Type: application/json" \
-H "X-Peppa-Event: check" -H "X-Gitea-Signature: $sig" --data-binary "$body" ||
echo "peppa: FORGE недоступна — статус заберёт опрос"
fi
exit "$code"