feat(ci): 添加 runner 自主维护 workflow(每6小时健康检查)
Node.js Build / build (push) Has been skipped

This commit is contained in:
2026-08-06 11:20:41 +08:00
parent 3d8bee740c
commit 8aa417989e
+67
View File
@@ -0,0 +1,67 @@
name: Runner Self-Maintenance
on:
schedule:
- cron: "0 */6 * * *"
workflow_dispatch:
jobs:
health-check:
runs-on: docker
steps:
- name: Check Gitea health
id: gitea
run: |
STATUS=$(curl -sf http://gitea:3000/api/healthz | grep -c '"status":"pass"' || echo 0)
if [ "$STATUS" -ge 1 ]; then
echo "result=ok|Gitea 健康检查通过" >> $GITHUB_OUTPUT
else
echo "result=fail|Gitea 健康检查失败" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check Verdaccio health
id: verdaccio
run: |
if curl -sf http://verdaccio:4873/-/ping | grep -q '"status":"ok"\|"status": "ok"'; then
echo "result=ok|Verdaccio 正常" >> $GITHUB_OUTPUT
elif curl -sf http://verdaccio:4873/-/ping >/dev/null 2>&1; then
echo "result=ok|Verdaccio 可访问" >> $GITHUB_OUTPUT
else
echo "result=fail|Verdaccio 不可达" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check runner registration
id: runner
run: |
RESP=$(curl -sf -u "${{ secrets.CI_USER }}:${{ secrets.CI_PASSWORD }}" \
"http://gitea:3000/api/v1/admin/actions/runners")
ONLINE=$(echo "$RESP" | grep -c '"status":"online"' || echo 0)
if [ "$ONLINE" -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: Cleanup stale action containers
id: cleanup
run: |
REMOVED=0
for cid in $(docker ps -a --filter "label=org.opencontainers.image.source=gitea/act_runner" -q 2>/dev/null); do
STATE=$(docker inspect -f '{{.State.Status}}' "$cid" 2>/dev/null || echo unknown)
if [ "$STATE" = "exited" ]; then
docker rm "$cid" >/dev/null 2>&1 && REMOVED=$((REMOVED+1)) || true
fi
done
echo "result=ok|清理 ${REMOVED} 个已退出的 job 容器" >> $GITHUB_OUTPUT
continue-on-error: true
- 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- 清理: ${{ steps.cleanup.outputs.result }}\n\n请检查 gitea-runner 容器状态"}}'