diff --git a/.github/workflows/ci-check.yml b/.github/workflows/ci-check.yml index 0f27819fc..df4ba3b08 100644 --- a/.github/workflows/ci-check.yml +++ b/.github/workflows/ci-check.yml @@ -4,12 +4,50 @@ on: pull_request: branches: [main] +# 同一 PR 连推多次时取消旧任务,只保留最新一次 +concurrency: + group: ci-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: build: runs-on: self-hosted + timeout-minutes: 20 steps: + # runner 到 github.com 偶发断连;先做 30 秒内的可达性探测, + # 避免 checkout 三次重试各等 2 分钟以上(一次故障白跑 7 分钟) + - name: Probe github.com egress + run: | + for i in 1 2 3; do + if curl -sS --max-time 10 -o /dev/null https://github.com; then + echo "github.com reachable (attempt $i)" + exit 0 + fi + echo "Attempt $i failed, retrying..." + sleep 5 + done + echo "::error::github.com unreachable from runner" + exit 1 - uses: actions/checkout@v5 + # 只改 workflow / README / LICENSE 的 PR 不影响站点构建: + # 保留 job(必需检查 build 必须上报),跳过全部重活 + - name: Detect metadata-only changes + id: meta + run: | + # checkout 的是浅克隆的 PR merge commit,拿不到共同祖先; + # 改为分别取 PR 分支和 base 分支的最新提交再比较 + git fetch --no-tags --depth=50 origin "+refs/heads/${{ github.head_ref }}:refs/remotes/pr-head" || true + git fetch --no-tags --depth=50 origin "${{ github.base_ref }}" || true + base=$(git merge-base FETCH_HEAD refs/remotes/pr-head 2>/dev/null) + if [ -n "$base" ] && git diff --quiet "$base" refs/remotes/pr-head -- . ':(exclude).github/**' ':(exclude)README.md' ':(exclude)LICENSE*'; then + echo "skip=true" >> "$GITHUB_OUTPUT" + echo "Only metadata files changed; skipping build." + else + echo "skip=false" >> "$GITHUB_OUTPUT" + echo "Source changes detected (or merge-base unavailable); running full build." + fi - name: Detect local Node.js on runner + if: steps.meta.outputs.skip != 'true' id: detect_node run: | if command -v node >/dev/null 2>&1 && command -v npm >/dev/null 2>&1; then @@ -21,24 +59,27 @@ jobs: echo "has_node=false" >> "$GITHUB_OUTPUT" fi - name: Setup Node.js (fallback if runner has no Node) - if: steps.detect_node.outputs.has_node != 'true' + if: steps.meta.outputs.skip != 'true' && steps.detect_node.outputs.has_node != 'true' uses: actions/setup-node@v5 with: node-version: '24' cache: 'npm' - name: Doc quality (advisory) + if: steps.meta.outputs.skip != 'true' uses: D-Robotics/doc-skills/.github/actions/doc-quality@v1 continue-on-error: true with: changed-only: 'true' advisory: 'true' - name: Clean install dependencies + if: steps.meta.outputs.skip != 'true' run: | rm -rf node_modules npm ci - name: Build site (strict broken-link checking) + if: steps.meta.outputs.skip != 'true' run: npm run build:ci - if: always() run: | echo "## Build Summary" >> $GITHUB_STEP_SUMMARY - echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file + echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 20e8332ca..96dd4087b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,13 +6,34 @@ on: - main # 当 main 分支有推送时触发部署 workflow_dispatch: # 允许手动触发 +# 部署串行执行,不取消进行中的任务:取消可能留下半套 gh-pages 产物 +concurrency: + group: deploy-main + cancel-in-progress: false + jobs: build: runs-on: self-hosted + timeout-minutes: 20 env: GUAJI_ASSISTANT_ORIGIN: https://developer.d-robotics.cc steps: + # runner 到 github.com 偶发断连;先做 30 秒内的可达性探测, + # 避免 checkout 三次重试各等 2 分钟以上(一次故障白跑 7 分钟) + - name: Probe github.com egress + run: | + for i in 1 2 3; do + if curl -sS --max-time 10 -o /dev/null https://github.com; then + echo "github.com reachable (attempt $i)" + exit 0 + fi + echo "Attempt $i failed, retrying..." + sleep 5 + done + echo "::error::github.com unreachable from runner" + exit 1 + - name: Checkout repository uses: actions/checkout@v5 @@ -28,7 +49,7 @@ jobs: run: | git config --global user.email "liql01@qq.com" git config --global user.name "liqinglian01" - + - name: Setup SSH run: | mkdir -p ~/.ssh