Подключить CI Пеппы (Gitea Actions)
All checks were successful
All checks were successful
This commit is contained in:
parent
33a539cdb3
commit
66abeb285c
@ -83,6 +83,39 @@ healthy() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# PEP-44: скриншоты превью для ревью PM. Headless Chromium в контейнере в сети Traefik
|
||||||
|
# (job сам в контейнере — PNG идёт через stdout в base64, без томов). Страницы —
|
||||||
|
# deploy.screenshots (по умолчанию ["/"], [] — выключить). Сбой не валит деплой.
|
||||||
|
screenshots() {
|
||||||
|
local peppa_url paths shots=() p url png body sig file
|
||||||
|
peppa_url=$(jq -r '.peppaUrl // empty' "$cfg")
|
||||||
|
[[ -n "$peppa_url" && -n "${PEPPA_CI_SECRET:-}" ]] || return 0
|
||||||
|
paths=()
|
||||||
|
while IFS= read -r p; do [[ -n "$p" ]] && paths+=("$p"); done < <(jq -r '(.deploy.screenshots // ["/"])[:6][]' "$cfg" 2>/dev/null)
|
||||||
|
((${#paths[@]})) || return 0
|
||||||
|
local limit=()
|
||||||
|
command -v timeout >/dev/null && limit=(timeout "${PEPPA_SCREENSHOT_TIMEOUT:-90}")
|
||||||
|
local base="${PEPPA_SCREENSHOT_BASE:-${PEPPA_HEALTH_BASE:-http://$container:$port}}"
|
||||||
|
base="${base//\{project\}/$project}"
|
||||||
|
file=$(mktemp)
|
||||||
|
echo '[]' > "$file"
|
||||||
|
for p in "${paths[@]}"; do
|
||||||
|
url="$base$p"
|
||||||
|
png=$(${limit[@]+"${limit[@]}"} docker run --rm --network "${PEPPA_SCREENSHOT_NETWORK:-traefik_default}" --entrypoint sh \
|
||||||
|
"${PEPPA_SCREENSHOT_IMAGE:-zenika/alpine-chrome:124}" -c \
|
||||||
|
'chromium-browser --headless --no-sandbox --disable-gpu --hide-scrollbars --window-size=1280,800 --virtual-time-budget=5000 --screenshot=/tmp/s.png "$1" >/dev/null 2>&1 && base64 /tmp/s.png | tr -d "\n"' _ "$url" 2>/dev/null) || png=""
|
||||||
|
if [[ -z "$png" ]]; then echo "peppa: скриншот $p не снят"; continue; fi
|
||||||
|
jq --arg path "$p" --rawfile png <(printf '%s' "$png") '. + [{path:$path, png:$png}]' "$file" > "$file.n" && mv "$file.n" "$file"
|
||||||
|
echo "peppa: скриншот $p снят"
|
||||||
|
done
|
||||||
|
[[ $(jq length "$file") -gt 0 ]] || return 0
|
||||||
|
body=$(jq -c --arg repo "${GITHUB_REPOSITORY:-}" --arg sha "$sha" --arg pr "$pr" '{repository:$repo, sha:$sha, pr:($pr|tonumber? // null), shots:.}' "$file")
|
||||||
|
sig=$(printf '%s' "$body" | openssl dgst -sha256 -hmac "$PEPPA_CI_SECRET" | awk '{print $NF}')
|
||||||
|
printf '%s' "$body" | curl -fsS -o /dev/null -m 60 -X POST "$peppa_url/api/hooks/gitea" -H "Content-Type: application/json" \
|
||||||
|
-H "X-Peppa-Event: screenshots" -H "X-Gitea-Signature: $sig" --data-binary @- || echo "peppa: скриншоты не отправлены"
|
||||||
|
rm -f "$file"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ $mode == preview-down ]]; then
|
if [[ $mode == preview-down ]]; then
|
||||||
dc "$image" down --remove-orphans || true
|
dc "$image" down --remove-orphans || true
|
||||||
report removed
|
report removed
|
||||||
@ -99,6 +132,7 @@ fi
|
|||||||
dc "$image" up -d --remove-orphans || { report failed "docker compose up не удался"; exit 1; }
|
dc "$image" up -d --remove-orphans || { report failed "docker compose up не удался"; exit 1; }
|
||||||
if healthy; then
|
if healthy; then
|
||||||
report healthy
|
report healthy
|
||||||
|
[[ $env_name == preview ]] && screenshots
|
||||||
docker image prune -af --filter "label=peppa.project=$slug" --filter "until=336h" >/dev/null 2>&1 || true
|
docker image prune -af --filter "label=peppa.project=$slug" --filter "until=336h" >/dev/null 2>&1 || true
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user