66 lines
2.4 KiB
YAML
66 lines
2.4 KiB
YAML
name: Runner Self-Maintenance
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 */6 * * *"
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
GITEA_URL: https://gitea.windychen00n.work
|
|
VERDACCIO_URL: http://172.172.2.4:4873
|
|
|
|
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: |
|
|
if curl -sf "$GITEA_URL/api/healthz" | grep -q '"status":"pass"'; 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 "$VERDACCIO_URL/-/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 }}" \
|
|
"$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 容器"}}'
|