@@ -53,11 +53,15 @@ jobs:
5353 with :
5454 fetch-depth : 0
5555 token : ${{ secrets.PAT_TOKEN }}
56+ persist-credentials : true
5657
5758 - name : Setup Git
5859 run : |
5960 git config --global user.name "github-actions[bot]"
6061 git config --global user.email "github-actions[bot]@users.noreply.github.com"
62+
63+ # Configure git to use the PAT for authentication
64+ git config --global url."https://${{ secrets.PAT_TOKEN }}@github.com/".insteadOf "https://github.com/"
6165
6266 - name : Extract target branches from input
6367 if : github.event_name == 'workflow_dispatch'
@@ -146,11 +150,35 @@ jobs:
146150 # Commit the changes
147151 git commit -m "Sync changes from main to ${{ matrix.target_branch }} - Applied recent commits, updated versions & framework, preserved .csproj files"
148152
149- echo "📤 Pushing sync branch: $sync_branch"
150- git push origin "$sync_branch"
153+ echo "📤 Attempting to push sync branch: $sync_branch"
154+
155+ # Try to push to origin, if it fails try to push to a fork
156+ if git push origin "$sync_branch" 2>/dev/null; then
157+ echo "✅ Pushed to origin successfully"
158+ PUSH_REPO="${{ github.repository }}"
159+ else
160+ echo "⚠️ Cannot push to origin, trying fork approach..."
161+
162+ # Check if we have a fork configured
163+ FORK_OWNER="${{ vars.FORK_OWNER || 'arcenox' }}"
164+ FORK_URL="https://${{ secrets.PAT_TOKEN }}@github.com/${FORK_OWNER}/TickerQ.git"
165+
166+ # Add fork as remote if not exists
167+ git remote add fork "$FORK_URL" 2>/dev/null || git remote set-url fork "$FORK_URL"
168+
169+ # Push to fork
170+ if git push fork "$sync_branch"; then
171+ echo "✅ Pushed to fork: ${FORK_OWNER}/TickerQ"
172+ PUSH_REPO="${FORK_OWNER}/TickerQ"
173+ else
174+ echo "❌ Failed to push to both origin and fork"
175+ exit 1
176+ fi
177+ fi
151178
152- # Store branch name for PR creation
179+ # Store branch name and repo for PR creation
153180 echo "sync_branch=$sync_branch" >> $GITHUB_ENV
181+ echo "push_repo=$PUSH_REPO" >> $GITHUB_ENV
154182 else
155183 echo "ℹ️ No commits to apply"
156184 git checkout main
@@ -192,13 +220,26 @@ jobs:
192220 EOF
193221 )
194222
195- # Create PR without labels first (they might not exist)
196- gh pr create \
197- --base "${{ matrix.target_branch }}" \
198- --head "${{ env.sync_branch }}" \
199- --title "🔄 Sync main branch changes to ${{ matrix.target_branch }}" \
200- --body "$PR_BODY" \
201- 2>&1 | tee pr_output.txt
223+ # Create PR (from fork if necessary)
224+ if [ "${{ env.push_repo }}" = "${{ github.repository }}" ]; then
225+ # Creating PR from same repo
226+ gh pr create \
227+ --base "${{ matrix.target_branch }}" \
228+ --head "${{ env.sync_branch }}" \
229+ --title "🔄 Sync main branch changes to ${{ matrix.target_branch }}" \
230+ --body "$PR_BODY" \
231+ 2>&1 | tee pr_output.txt
232+ else
233+ # Creating PR from fork
234+ FORK_OWNER=$(echo "${{ env.push_repo }}" | cut -d'/' -f1)
235+ gh pr create \
236+ --base "${{ matrix.target_branch }}" \
237+ --head "${FORK_OWNER}:${{ env.sync_branch }}" \
238+ --repo "${{ github.repository }}" \
239+ --title "🔄 Sync main branch changes to ${{ matrix.target_branch }}" \
240+ --body "$PR_BODY" \
241+ 2>&1 | tee pr_output.txt
242+ fi
202243
203244 # Extract PR number if created
204245 PR_NUMBER=$(grep -oP '(?<=pull/)\d+' pr_output.txt || echo "")
0 commit comments