Подключить CI Пеппы #2
47
.gitea/peppa-check.sh
Normal file
47
.gitea/peppa-check.sh
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Шаг CI Пеппы: bash .gitea/peppa-check.sh <проверка>
|
||||
# Команда — .peppa/project.json → checks.<проверка>; нет команды — шаг пропущен.
|
||||
# Результат: статус коммита «peppa/<проверка>» в Gitea и отчёт в Пеппу с хвостом лога
|
||||
# (подпись 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: Пеппа недоступна — статус заберёт опрос"
|
||||
fi
|
||||
exit "$code"
|
||||
38
.gitea/workflows/ci.yml
Normal file
38
.gitea/workflows/ci.yml
Normal file
@ -0,0 +1,38 @@
|
||||
# CI проекта Пеппы (PEP-57). Команды проверок — в .peppa/project.json → "checks";
|
||||
# под стек проекта этот файл менять не нужно. Изменение этого файла или "checks"
|
||||
# PM видит отдельно, и такой PR не мержится автоматически.
|
||||
name: ci
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
env:
|
||||
PEPPA_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
PEPPA_BRANCH: ${{ github.head_ref || github.ref_name }}
|
||||
PEPPA_PR: ${{ github.event.pull_request.number }}
|
||||
PEPPA_CI_SECRET: ${{ secrets.PEPPA_CI_SECRET }}
|
||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
jobs:
|
||||
checks:
|
||||
# Раннер с docker.sock хоста: только ветки этого репозитория, PR из форков не запускаются.
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
||||
runs-on: peppa-trusted
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.PEPPA_SHA }}
|
||||
- id: install
|
||||
name: install
|
||||
run: bash .gitea/peppa-check.sh install
|
||||
- name: lint
|
||||
if: (success() || failure()) && steps.install.outcome == 'success'
|
||||
run: bash .gitea/peppa-check.sh lint
|
||||
- name: typecheck
|
||||
if: (success() || failure()) && steps.install.outcome == 'success'
|
||||
run: bash .gitea/peppa-check.sh typecheck
|
||||
- name: test
|
||||
if: (success() || failure()) && steps.install.outcome == 'success'
|
||||
run: bash .gitea/peppa-check.sh test
|
||||
- name: build
|
||||
if: (success() || failure()) && steps.install.outcome == 'success'
|
||||
run: bash .gitea/peppa-check.sh build
|
||||
@ -1 +1,12 @@
|
||||
{ "slug": "sandbox", "key": "SBX", "name": "Peppa Sandbox", "peppaUrl": "https://peppa.telecom.quest" }
|
||||
{
|
||||
"slug": "sandbox",
|
||||
"key": "SBX",
|
||||
"name": "Peppa Sandbox",
|
||||
"peppaUrl": "https://peppa.telecom.quest",
|
||||
"checks": {
|
||||
"lint": "test -f README.md && grep -q . AGENTS.md",
|
||||
"typecheck": "jq empty .peppa/project.json",
|
||||
"test": "test -d openspec",
|
||||
"build": "echo 'nothing to build yet'"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user