@@ -30,104 +30,120 @@ on:
3030 required : true
3131 type : string
3232
33+ env :
34+ TARGET : ${{ inputs.target_branch }}
35+ SOURCE : ${{ inputs.source_branch }}
36+ PR_NUMBER : ${{ inputs.pr_number }}
37+
3338jobs :
3439 merge_and_resolve :
3540 runs-on : ubuntu-latest
3641 permissions :
3742 contents : write
3843 pull-requests : write
3944 steps :
40- - name : Install jq
41- run : |
42- if ! command -v jq &> /dev/null; then
43- sudo apt-get update && sudo apt-get install -y jq
44- fi
4545 - name : Create or update comment
46- if : inputs.pr_number && inputs.pr_number != '0'
46+ if : env.PR_NUMBER && env.PR_NUMBER != '0'
4747 uses : peter-evans/create-or-update-comment@v5
4848 with :
49- issue-number : ${{ inputs.pr_number }}
49+ issue-number : ${{ env.PR_NUMBER }}
5050 body : |
51- ⏳ Attempting to automatically resolve conflicts for branch `${{ inputs.source_branch }}`...
51+ ⏳ Attempting to automatically resolve conflicts for branch `${{ env.SOURCE }}`...
5252 <!-- id: conflict-resolver-bot -->
5353 token : ${{ secrets.GITHUB_TOKEN }}
5454
5555 - name : Checkout source branch
5656 uses : actions/checkout@v4
5757 with :
58- ref : ${{ inputs.source_branch }}
58+ ref : ${{ env.SOURCE }}
5959 fetch-depth : 0
60- token : ${{ secrets.CI_BOT_PAT || secrets. ARI_PAT || secrets.GITHUB_TOKEN }}
60+ token : ${{ secrets.ARI_PAT || secrets.GITHUB_TOKEN }}
6161
6262 - name : Validate branches
6363 id : validate_branches
64+ shell : bash
6465 run : |
65- if ! git ls-remote --exit-code --heads origin ${{ inputs.target_branch }}; then
66- echo "::error::Target branch '${{ inputs.target_branch }}' not found."
67- exit 1
66+ if ! git ls-remote --exit-code --heads origin "$TARGET" > /dev/null 2>&1; then
67+ echo "::warning::Target branch $TARGET missing. Skipping resolver."
68+ echo "skipped=true" >> $GITHUB_OUTPUT
69+ echo "error_msg=❌ Error: Target branch \`$TARGET\` not found. Please ensure the target branch exists and the bot has permissions to access it." >> $GITHUB_OUTPUT
70+ exit 0
6871 fi
69- if ! git ls-remote --exit-code --heads origin ${{ inputs.source_branch }}; then
70- echo "::error::Source branch '${{ inputs.source_branch }}' not found."
71- exit 1
72+
73+ if ! git ls-remote --exit-code --heads origin "$SOURCE" > /dev/null 2>&1; then
74+ echo "::warning::Source branch $SOURCE missing. Skipping resolver."
75+ echo "skipped=true" >> $GITHUB_OUTPUT
76+ echo "error_msg=❌ Error: Source branch \`$SOURCE\` not found. It may have been deleted or renamed." >> $GITHUB_OUTPUT
77+ exit 0
7278 fi
73- # Capture base SHA (target branch)
74- git fetch origin ${{ inputs.target_branch }}
75- echo "base_sha=$(git rev-parse origin/${{ inputs.target_branch }})" >> $GITHUB_OUTPUT
79+
80+ git fetch origin "$TARGET"
81+ echo "base_sha=$(git rev-parse origin/"$TARGET")" >> $GITHUB_OUTPUT
82+ echo "skipped=false" >> $GITHUB_OUTPUT
83+
84+ - name : Comment on validation failure
85+ if : steps.validate_branches.outputs.skipped == 'true' && env.PR_NUMBER && env.PR_NUMBER != '0'
86+ uses : peter-evans/create-or-update-comment@v5
87+ with :
88+ issue-number : ${{ env.PR_NUMBER }}
89+ body : |
90+ ${{ steps.validate_branches.outputs.error_msg }}
91+ <!-- id: conflict-resolver-bot -->
92+ token : ${{ secrets.GITHUB_TOKEN }}
7693
7794 - name : Merge target branch
95+ if : steps.validate_branches.outputs.skipped != 'true'
7896 run : |
7997 git config user.name "github-actions[bot]"
8098 git config user.email "github-actions[bot]@users.noreply.github.com"
81- git fetch origin ${{ inputs.target_branch }}
82- git merge origin/${{ inputs.target_branch }} --no-commit --no-ff || true
99+ git fetch origin "$TARGET"
100+ git merge origin/"$TARGET" --no-commit --no-ff || true
83101
84102 - name : Resolve conflicts
103+ if : steps.validate_branches.outputs.skipped != 'true'
85104 id : resolve
86105 uses : VeyronSakai/conflict-resolver@7d650534ba240658a381241823f8b4f13861c2ad # pin to v0.5.1
87106 with :
88107 config-path : .github/conflict-resolver.yml
89108
90109 - name : Commit and push changes
91- if : steps.resolve.outputs.unresolved-files == ''
110+ if : steps.validate_branches.outputs.skipped != 'true' && steps. resolve.outputs.unresolved-files == ''
92111 run : |
93112 git add .
94- git commit -m "Auto-resolve merge conflicts by merging ${{ inputs.target_branch }} "
113+ git commit -m "Auto-resolve merge conflicts by merging $TARGET "
95114 git push --force
96115 echo "resolved_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
97116 id : commit_push
98117
99118 - name : Trigger Gemini Orchestrator
100- if : steps.resolve.outputs.unresolved-files == '' && inputs.pr_number && inputs.pr_number != '0'
119+ if : steps.validate_branches.outputs.skipped != 'true' && steps. resolve.outputs.unresolved-files == '' && env.PR_NUMBER && env.PR_NUMBER != '0'
101120 env :
102- # Use CI_BOT_PAT if available to ensure workflow is triggered (GITHUB_TOKEN prevents recursion)
103- GH_TOKEN : ${{ secrets.CI_BOT_PAT || secrets.ARI_PAT || secrets.GITHUB_TOKEN }}
104- SOURCE_BRANCH : ${{ inputs.source_branch }}
121+ GH_TOKEN : ${{ secrets.ARI_PAT || secrets.GITHUB_TOKEN }}
105122 HEAD_SHA : ${{ steps.commit_push.outputs.resolved_sha }}
106123 BASE_SHA : ${{ steps.validate_branches.outputs.base_sha }}
107- PR_NUMBER : ${{ inputs.pr_number }}
108124 run : |
109- gh workflow run "Gemini Orchestrator" --ref "$SOURCE_BRANCH " -f pr_number="$PR_NUMBER" -f base_ref="$BASE_SHA" -f head_ref="$HEAD_SHA" -f base_branch="$TARGET_BRANCH "
125+ gh workflow run "Gemini Orchestrator" --ref "$SOURCE " -f pr_number="$PR_NUMBER" -f base_ref="$BASE_SHA" -f head_ref="$HEAD_SHA" -f base_branch="$TARGET "
110126
111127 - name : Update comment on success
112- if : success() && steps.resolve.outputs.unresolved-files == '' && inputs.pr_number && inputs.pr_number != '0'
128+ if : steps.validate_branches.outputs.skipped != 'true' && success() && steps.resolve.outputs.unresolved-files == '' && env.PR_NUMBER && env.PR_NUMBER != '0'
113129 uses : peter-evans/create-or-update-comment@v5
114130 with :
115- issue-number : ${{ inputs.pr_number }}
131+ issue-number : ${{ env.PR_NUMBER }}
116132 body : |
117- ✅ Successfully resolved all conflicts by merging the latest changes from `${{ inputs.target_branch }}`. The pull request has been updated.
133+ ✅ Successfully resolved all conflicts by merging the latest changes from `${{ env.TARGET }}`. The pull request has been updated.
118134
119135 ---
120136 #### 🤖 [Gemini Manual Trigger Guide](${{ github.server_url }}/${{ github.repository }}/blob/leader/docs/workflows/MANUAL_TRIGGERS.md)
121137 <!-- id: conflict-resolver-bot -->
122138 token : ${{ secrets.GITHUB_TOKEN }}
123139
124140 - name : Update comment on failure
125- if : (failure() || (success() && steps.resolve.outputs.unresolved-files != '')) && inputs.pr_number && inputs.pr_number != '0'
141+ if : steps.validate_branches.outputs.skipped != 'true' && (failure() || (success() && steps.resolve.outputs.unresolved-files != '')) && env.PR_NUMBER && env.PR_NUMBER != '0'
126142 uses : peter-evans/create-or-update-comment@v5
127143 env :
128144 UNRESOLVED_FILES : ${{ steps.resolve.outputs.unresolved-files }}
129145 with :
130- issue-number : ${{ inputs.pr_number }}
146+ issue-number : ${{ env.PR_NUMBER }}
131147 body : |
132148 ❌ **Error: Unable to automatically resolve all conflicts.**
133149 The following files have unresolved conflicts:
@@ -142,7 +158,5 @@ jobs:
142158 token : ${{ secrets.GITHUB_TOKEN }}
143159
144160 - name : Fail the workflow if conflicts were not resolved
145- if : steps.resolve.outputs.unresolved-files != ''
146- run : |
147- echo "Workflow failed because unresolved conflicts remain."
148- exit 1
161+ if : steps.validate_branches.outputs.skipped != 'true' && steps.resolve.outputs.unresolved-files != ''
162+ run : exit 1
0 commit comments