Files
Jyotisha/.gitea/workflows/monitor-public-health.yml
T
ClaudeandClaude Opus 5.5 52872d1af2
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m0s
Independent Staging Quality Gate / validate-python (push) Successful in 8m18s
Independent Staging Quality Gate / publish (push) Successful in 4m11s
ci(monitor): the public health probe reads only its two scripts and fits in 3 minutes (BUG-2389)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-25 20:29:06 +08:00

86 lines
4.1 KiB
YAML

name: Monitor Public Health
# BUG-2348: availability probe from outside the production server. Every 10
# minutes the runner opens the public health URL three times, 20 seconds apart.
# BUG-2389: it used to check out the whole repository (a shallow fetch of the
# ~105 MB tree takes 4-8 minutes from this runner), so every run hit the 5-minute
# limit and was cancelled with exit code -1 while holding the runner. It now
# reads only its two scripts, has a 3-minute budget (worst case about 2 minutes), and a newer run replaces an
# older one, so it can never queue up behind or in front of a release.
# Three failures in a row send one alert (Feishu and/or email); the first good
# probe afterwards sends one recovery. State lives under the runner user's home
# so an outage alerts once, not every run.
#
# Secrets (repository → Actions → Secrets): MONITOR_FEISHU_WEBHOOK_URL,
# MONITOR_FEISHU_SIGN_SECRET (optional), MONITOR_ALERT_EMAIL_TO,
# MONITOR_ALERT_EMAIL_FROM, MONITOR_RESEND_API_KEY. Any channel left empty is
# skipped; with none set the alert stays in the runner's local alerts.log.
on:
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: monitor-public-health
cancel-in-progress: true
jobs:
probe:
if: gitea.ref == 'refs/heads/main'
runs-on: xiaoxin
timeout-minutes: 3
env:
GITEA_SHA: ${{ gitea.sha }}
GITEA_REF: ${{ gitea.ref }}
GITEA_API_URL: ${{ gitea.api_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
steps:
- name: Probe https://jyotisha.chat/api/health
env:
MONITOR_FEISHU_WEBHOOK_URL: ${{ secrets.MONITOR_FEISHU_WEBHOOK_URL }}
MONITOR_FEISHU_SIGN_SECRET: ${{ secrets.MONITOR_FEISHU_SIGN_SECRET }}
MONITOR_ALERT_EMAIL_TO: ${{ secrets.MONITOR_ALERT_EMAIL_TO }}
MONITOR_ALERT_EMAIL_FROM: ${{ secrets.MONITOR_ALERT_EMAIL_FROM }}
MONITOR_RESEND_API_KEY: ${{ secrets.MONITOR_RESEND_API_KEY }}
run: |
set -euo pipefail
set +x
[[ "$GITEA_REF" == "refs/heads/main" ]]
[[ "$GITEA_SHA" =~ ^[0-9a-f]{40}$ ]]
# Only the two monitor scripts are needed: from the runner's bare mirror when it
# has this SHA, otherwise from the Gitea raw API, each request capped at 20 seconds.
install -d deploy/monitor
for script in healthcheck-alert.sh notify-feishu.sh; do
path="deploy/monitor/$script"
if ! timeout 20 git --git-dir=/root/.cache/jyotisha-mirror.git show "$GITEA_SHA:$path" >"$path" 2>/dev/null; then
curl --fail --silent --show-error --connect-timeout 10 --max-time 20 \
--header "Authorization: token $GITEA_TOKEN" \
"$GITEA_API_URL/repos/$GITEA_REPOSITORY/raw/$path?ref=$GITEA_SHA" --output "$path"
fi
test -s "$path"
done
work="${RUNNER_TEMP}/monitor-public-health"
install -m 700 -d "$work"
env_file="$work/monitor.env"
: >"$env_file"
chmod 600 "$env_file"
[ -z "$MONITOR_FEISHU_WEBHOOK_URL" ] || printf 'FEISHU_WEBHOOK_URL=%s\n' "$MONITOR_FEISHU_WEBHOOK_URL" >>"$env_file"
[ -z "$MONITOR_FEISHU_SIGN_SECRET" ] || printf 'FEISHU_SIGN_SECRET=%s\n' "$MONITOR_FEISHU_SIGN_SECRET" >>"$env_file"
[ -z "$MONITOR_ALERT_EMAIL_TO" ] || printf 'ALERT_EMAIL_TO=%s\n' "$MONITOR_ALERT_EMAIL_TO" >>"$env_file"
[ -z "$MONITOR_ALERT_EMAIL_FROM" ] || printf 'ALERT_EMAIL_FROM=%s\n' "$MONITOR_ALERT_EMAIL_FROM" >>"$env_file"
[ -z "$MONITOR_RESEND_API_KEY" ] || printf 'RESEND_API_KEY=%s\n' "$MONITOR_RESEND_API_KEY" >>"$env_file"
trap 'rm -rf -- "$work"' EXIT
export JYOTISHA_MONITOR_ENV="$env_file"
export JYOTISHA_APP_ENV_FILE="$work/no-app-env"
export JYOTISHA_COMMIT_ALERT=off
export JYOTISHA_MONITOR_STATE_DIR="${HOME}/.jyotisha-monitor/public-health"
for attempt in 1 2 3; do
bash deploy/monitor/healthcheck-alert.sh --mode health
[ "$attempt" -eq 3 ] || sleep 20
done