Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions .github/workflows/ds-bot-upstream-track.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Loading