From f37841fcf782541057cab7db11e2cdcf3b5949c4 Mon Sep 17 00:00:00 2001 From: FlyBot Runtime Dev Date: Sun, 29 Nov 2026 13:03:55 +0000 Subject: [PATCH] ci: retry the upstream tracker pull request instead of skipping on an existing branch `Find the target release` treated an existing `upstream/ds-bot-` branch as "already done", so after `gh pr create` failed once (runs 45976212422 on 11-27 and 46128184106 on 11-28) every later run skipped sync, suite, smoke and the pull request step and reported success (run 46244596502 on 11-29) while main stayed pinned to v0.3.10 and no pull request was ever opened. - Done now means an open pull request for the head branch, not the branch existing; the skip message and the step summary name the pull request number. - A branch that exists without an open pull request is reused instead of skipped: a new `Check out the sync branch` step fetches and tracks it, `Sync` is gated on the branch being absent, and the suite, the smoke and the pull request step still run, so one failed `gh pr create` cannot stall the tracker. - A run that cannot open the pull request stays red and names the branch, the upstream ref and the tag main is pinned to. No change to the pin, to the vendored tree, or to any container file. Related #3448 --- .github/workflows/ds-bot-upstream-track.yml | 52 +++++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ds-bot-upstream-track.yml b/.github/workflows/ds-bot-upstream-track.yml index 7c83447e4..7686618b9 100644 --- a/.github/workflows/ds-bot-upstream-track.yml +++ b/.github/workflows/ds-bot-upstream-track.yml @@ -54,21 +54,54 @@ jobs: pinned=$(node -p "require('./runtime/ds-bot-upstream.pin.json').tag || require('./runtime/ds-bot-upstream.pin.json').commit") branch="upstream/ds-bot-$ref" skip=false - if [ "$ref" = "$pinned" ]; then echo "Already pinned to $ref"; skip=true; fi - if [ "$skip" = false ] && git ls-remote --exit-code --heads origin "$branch" >/dev/null; then echo "Branch $branch already exists"; skip=true; fi - { echo "ref=$ref"; echo "branch=$branch"; echo "skip=$skip"; echo "pinned=$pinned"; } >> "$GITHUB_OUTPUT" - - name: Sync + branch_exists=false + open_pr='' + if [ "$ref" = "$pinned" ]; then + echo "Already pinned to $ref"; skip=true + else + if git ls-remote --exit-code --heads origin "$branch" >/dev/null; then branch_exists=true; fi + open_pr=$(gh pr list --head "$branch" --state open --limit 1 --json number --jq '.[].number') + if [ -n "$open_pr" ]; then + echo "Pull request #$open_pr is already open for $branch" + skip=true + elif [ "$branch_exists" = true ]; then + echo "Branch $branch exists but has no open pull request; reusing it instead of skipping" + fi + fi + { echo "ref=$ref"; echo "branch=$branch"; echo "skip=$skip"; echo "pinned=$pinned"; echo "branch_exists=$branch_exists"; echo "open_pr=$open_pr"; } >> "$GITHUB_OUTPUT" + if [ "$skip" = true ]; then + if [ -n "$open_pr" ]; then + echo "Skipped: pull request #$open_pr is already open for \`$branch\`." >> "$GITHUB_STEP_SUMMARY" + else + echo "Skipped: main is already pinned to \`$ref\`." >> "$GITHUB_STEP_SUMMARY" + fi + fi + - name: Check out the sync branch if: steps.target.outputs.skip == 'false' env: TRACK_BRANCH: ${{ steps.target.outputs.branch }} - TRACK_REF: ${{ steps.target.outputs.ref }} + TRACK_BRANCH_EXISTS: ${{ steps.target.outputs.branch_exists }} run: | set -euo pipefail - case "$TRACK_REF" in *[!A-Za-z0-9._-]*) echo "bad ref: $TRACK_REF"; exit 1 ;; esac case "$TRACK_BRANCH" in *[!A-Za-z0-9._/-]*) echo "bad branch: $TRACK_BRANCH"; exit 1 ;; esac git config user.name 'flybot-workspace-upstream-bot' git config user.email 'flybot-workspace-upstream-bot@users.noreply.github.com' - git switch -c "$TRACK_BRANCH" + if [ "$TRACK_BRANCH_EXISTS" = true ]; then + git fetch origin "refs/heads/$TRACK_BRANCH:refs/remotes/origin/$TRACK_BRANCH" + git switch -c "$TRACK_BRANCH" --track "origin/$TRACK_BRANCH" + echo "Reusing the existing branch $TRACK_BRANCH; its committed sync is kept and nothing is re-synced." + else + git switch -c "$TRACK_BRANCH" + fi + - name: Sync + if: steps.target.outputs.skip == 'false' && steps.target.outputs.branch_exists == 'false' + env: + TRACK_BRANCH: ${{ steps.target.outputs.branch }} + TRACK_REF: ${{ steps.target.outputs.ref }} + run: | + set -euo pipefail + case "$TRACK_REF" in *[!A-Za-z0-9._-]*) echo "bad ref: $TRACK_REF"; exit 1 ;; esac + case "$TRACK_BRANCH" in *[!A-Za-z0-9._/-]*) echo "bad branch: $TRACK_BRANCH"; exit 1 ;; esac node scripts/ds-bot-upstream.mjs sync "$TRACK_REF" node scripts/ds-bot-upstream.mjs check sed -i -E "s/\*\*v[0-9]+\.[0-9]+\.[0-9]+\*\*, commit \`[0-9a-f]{40}\`, ds-bot package \`[^\`]+\`/**$(node -p "require('./runtime/ds-bot-upstream.pin.json').tag")**, commit \`$(node -p "require('./runtime/ds-bot-upstream.pin.json').commit")\`, ds-bot package \`$(node -p "require('./runtime/ds-bot-upstream.pin.json').version")\`/; s/expect DeepSeek Harness \(DSH\) \`[^\`]+\`/expect DeepSeek Harness (DSH) \`$(node -p "require('./runtime/ds-bot-upstream.pin.json').dsh")\`/" runtime/ds-bot-upstream/UPSTREAM.md @@ -138,10 +171,11 @@ jobs: ) draft=() if [ "$SUITE" != success ] || [ "$SMOKE" != success ]; then draft=(--draft); fi - if ! gh pr create --base main --head "$TRACK_BRANCH" --title "runtime: track upstream DS Bot $TRACK_REF" --body "$body" "${draft[@]}"; then - echo "::error::Could not open the pull request. Allow GitHub Actions to create pull requests in the repository settings, or set the DS_BOT_TRACK_TOKEN secret. The branch $TRACK_BRANCH is pushed." + if ! pr_url=$(gh pr create --base main --head "$TRACK_BRANCH" --title "runtime: track upstream DS Bot $TRACK_REF" --body "$body" "${draft[@]}"); then + echo "::error::No pull request could be opened for branch $TRACK_BRANCH (upstream $TRACK_REF), so main stays pinned to $TRACK_PINNED. Allow GitHub Actions to create pull requests in the repository settings, or set the DS_BOT_TRACK_TOKEN secret. The branch is already pushed, and the next run reuses it and retries this step instead of skipping." exit 1 fi + echo "Opened $pr_url for \`$TRACK_BRANCH\` (upstream $TRACK_REF)." >> "$GITHUB_STEP_SUMMARY" - name: Fail the run when either check did not pass if: always() && steps.target.outputs.skip == 'false' env: