diff --git a/.gitea/workflows/runner-maintenance.yaml b/.gitea/workflows/runner-maintenance.yaml index bdb12a4..39ad12f 100644 --- a/.gitea/workflows/runner-maintenance.yaml +++ b/.gitea/workflows/runner-maintenance.yaml @@ -8,12 +8,16 @@ on: jobs: health-check: runs-on: docker + container: + image: alpine:3.20 steps: + - name: Install tools + run: apk add --no-cache curl docker-cli grep + - 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 + if curl -sf http://gitea:3000/api/healthz | grep -q '"status":"pass"'; then echo "result=ok|Gitea 健康检查通过" >> $GITHUB_OUTPUT else echo "result=fail|Gitea 健康检查失败" >> $GITHUB_OUTPUT @@ -23,10 +27,8 @@ jobs: - name: Check Verdaccio health id: verdaccio run: | - if curl -sf http://verdaccio:4873/-/ping | grep -q '"status":"ok"\|"status": "ok"'; then + if curl -sf http://verdaccio:4873/-/ping >/dev/null 2>&1; 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 @@ -37,8 +39,8 @@ jobs: 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 + 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 @@ -50,7 +52,7 @@ jobs: 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 + for cid in $(docker ps -a --filter "label=org.opencontainers.image.source=gitea/act_runner" -q 2>/dev/null || true); 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