CI smoke (PEP-57) #1

Closed
peppa-bot wants to merge 2 commits from ci-smoke into main
3 changed files with 96 additions and 1 deletions

46
.gitea/peppa-check.sh Normal file
View File

@ -0,0 +1,46 @@
#!/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}"
run_url="$GITHUB_SERVER_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
View 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

View File

@ -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": "echo lint ok",
"typecheck": "echo types ok",
"test": "echo running tests; test -f README.md",
"build": "echo build ok"
}
}