fixup! 765bef7be1bfa112180469966b0ffd147ca95ba7 #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Merging-Rebase Automation | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Shears branch to update (seen, next, main, maint, or all)' | |
| required: true | |
| type: choice | |
| options: | |
| - all | |
| - seen | |
| - next | |
| - main | |
| - maint | |
| push: | |
| description: 'Push the result after successful rebase' | |
| required: false | |
| type: boolean | |
| default: false | |
| push: | |
| permissions: | |
| contents: write | |
| models: read | |
| env: | |
| BRANCH: ${{ inputs.branch || 'all' }} | |
| PUSH: ${{ github.event_type == 'schedule' && 'true' || inputs.push || 'false' }} | |
| jobs: | |
| rebase: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Install Copilot CLI | |
| run: npm install -g @github/copilot | |
| - name: Verify Copilot CLI works | |
| shell: bash | |
| run: | | |
| echo "Testing Copilot CLI authentication..." | |
| copilot -p "What is the current latest Git version according to git-scm.com?" \ | |
| --allow-tool 'web_fetch' | |
| echo "Copilot CLI is working!" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Git for Windows SDK | |
| uses: git-for-windows/setup-git-for-windows-sdk@v1 | |
| with: | |
| flavor: minimal | |
| - name: Configure git | |
| shell: bash | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| - name: Add upstream remote | |
| shell: bash | |
| run: | | |
| git remote add upstream https://github.com/git/git.git || true | |
| git fetch upstream --no-tags | |
| - name: Run rebase (single branch) | |
| if: env.BRANCH != 'all' | |
| shell: bash | |
| run: | | |
| case "$BRANCH" in | |
| main) UPSTREAM="upstream/master" ;; | |
| *) UPSTREAM="upstream/$BRANCH" ;; | |
| esac | |
| git fetch origin "shears/$BRANCH" | |
| if test 0 = "$(git rev-list --count "origin/shears/$BRANCH..$UPSTREAM")"; then | |
| echo "Nothing to do: $UPSTREAM has no new commits" | |
| exit 0 | |
| fi | |
| ./ci/rebase-branch.sh "origin/shears/$BRANCH" "$UPSTREAM" ./ci | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Run rebase (all branches) | |
| if: env.BRANCH == 'all' | |
| shell: bash | |
| run: | | |
| for BRANCH in seen next main maint; do | |
| echo "" | |
| echo "========================================" | |
| echo "Processing shears/$BRANCH" | |
| echo "========================================" | |
| case "$BRANCH" in | |
| main) UPSTREAM="upstream/master" ;; | |
| *) UPSTREAM="upstream/$BRANCH" ;; | |
| esac | |
| git fetch origin "shears/$BRANCH" | |
| if test 0 = "$(git rev-list --count "origin/shears/$BRANCH..$UPSTREAM")"; then | |
| echo "Nothing to do: $UPSTREAM has no new commits" | |
| continue | |
| fi | |
| ./ci/rebase-branch.sh "origin/shears/$BRANCH" "$UPSTREAM" ./ci || { | |
| echo "Rebase failed for shears/$BRANCH" | |
| exit 1 | |
| } | |
| done | |
| echo "" | |
| echo "All branches processed successfully!" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Upload recovery archive on failure | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: recovery-archive | |
| path: "**/recovery-archive.tar.gz" | |
| if-no-files-found: ignore | |
| - name: Push results | |
| if: env.PUSH == 'true' | |
| shell: bash | |
| run: | | |
| # Find all worktrees created by the script and push them | |
| for worktree in /tmp/tmp.*; do | |
| if test -d "$worktree/.git" || test -f "$worktree/.git"; then | |
| cd "$worktree" | |
| BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true) | |
| if test -n "$BRANCH" && test "$BRANCH" != "HEAD"; then | |
| echo "Pushing $BRANCH..." | |
| git push --force origin "HEAD:$BRANCH" | |
| fi | |
| fi | |
| done |