Files
windychen-utils/.gitea/workflows/runner-maintenance.yaml
T
2026-08-06 11:23:19 +08:00

78 lines
2.9 KiB
YAML

name: Runner Self-Maintenance
on:
schedule:
- cron: "0 */6 * * *"
workflow_dispatch:
jobs:
health-check:
runs-on: docker
steps:
- name: Install tools
run: |
if command -v apk >/dev/null 2>&1; then
apk add --no-cache curl grep
elif command -v apt-get >/dev/null 2>&1; then
apt-get update -qq && apt-get install -y -qq curl grep
else
echo "No supported package manager"; exit 1
fi
- name: Check Gitea health
id: gitea
run: |
GITEA_URL="${{ vars.GITEA_URL }}"
GITEA_INTERNAL="${{ vars.GITEA_INTERNAL }}"
OK=0
for URL in "$GITEA_URL/api/healthz" "$GITEA_INTERNAL/api/healthz" "http://gitea:3000/api/healthz"; do
if curl -sf "$URL" | grep -q '"status":"pass"'; then
echo "result=ok|Gitea 健康 ($URL)" >> $GITHUB_OUTPUT
OK=1
break
fi
done
if [ "$OK" -eq 0 ]; then
echo "result=fail|Gitea 健康检查失败(外网+内网均不可达)" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check Verdaccio health
id: verdaccio
run: |
VERD="${{ vars.VERDACCIO_INTERNAL }}"
OK=0
for URL in "$VERD/-/ping" "http://verdaccio:4873/-/ping"; do
if curl -sf "$URL" >/dev/null 2>&1; then
echo "result=ok|Verdaccio 正常 ($URL)" >> $GITHUB_OUTPUT
OK=1
break
fi
done
if [ "$OK" -eq 0 ]; then
echo "result=fail|Verdaccio 不可达" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check runner registration
id: runner
run: |
GITEA_URL="${{ vars.GITEA_URL }}"
RESP=$(curl -sf -u "${{ secrets.CI_USER }}:${{ secrets.CI_PASSWORD }}" \
"${GITEA_URL}/api/v1/admin/actions/runners")
ONLINE=$(echo "$RESP" | grep -c '"status":"online"' || true)
if [ "${ONLINE:-0}" -ge 1 ]; then
NAME=$(echo "$RESP" | grep -o '"name":"[^"]*"' | head -1 | cut -d'"' -f4)
echo "result=ok|Runner ${NAME} 在线 (${ONLINE} 个)" >> $GITHUB_OUTPUT
else
echo "result=fail|无在线 Runner" >> $GITHUB_OUTPUT
exit 1
fi
- name: Notify DingTalk on failure
if: failure()
run: |
curl -s -X POST "https://oapi.dingtalk.com/robot/send?access_token=${{ secrets.DINGDING_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"msgtype":"markdown","markdown":{"title":"❌ Gitea Runner 自主维护告警 chen-fnos","text":"## ❌ Gitea Runner 自主维护告警 chen-fnos\n\n- Gitea: ${{ steps.gitea.outputs.result }}\n- Verdaccio: ${{ steps.verdaccio.outputs.result }}\n- Runner: ${{ steps.runner.outputs.result }}\n\n请检查 gitea-runner 容器"}}'