@@ -13,13 +13,15 @@ jobs:
1313 id-token : write
1414 contents : read
1515
16+ # Allow concurrent runs
1617 concurrency :
1718 group : update-rpcn-connector-docs
18- cancel-in-progress : true
19+ cancel-in-progress : false
1920
2021 env :
21- NODE_VERSION : ' 22 '
22+ NODE_VERSION : ' 24 '
2223 DOCS_OVERRIDES : docs-data/overrides.json
24+ AUTO_BRANCH : auto-docs/update-rpcn-connector-docs
2325
2426 steps :
2527 - uses : aws-actions/configure-aws-credentials@v4
3638 uses : actions/checkout@v4
3739 with :
3840 token : ${{ env.ACTIONS_BOT_TOKEN }}
41+ fetch-depth : 0 # Full history for rebasing
42+
43+ - name : Check for existing PR branch and set up workspace
44+ id : setup
45+ run : |
46+ git config user.name "github-actions[bot]"
47+ git config user.email "github-actions[bot]@users.noreply.github.com"
48+
49+ # Check if the auto-docs branch exists on remote
50+ if git ls-remote --heads origin $AUTO_BRANCH | grep -q "$AUTO_BRANCH"; then
51+ echo "branch_exists=true" >> "$GITHUB_OUTPUT"
52+ echo "Found existing branch $AUTO_BRANCH"
53+
54+ # Fetch and checkout the existing branch
55+ git fetch origin $AUTO_BRANCH
56+ git checkout $AUTO_BRANCH
57+
58+ # Rebase on main to get latest changes
59+ if git rebase origin/main; then
60+ echo "rebase_success=true" >> "$GITHUB_OUTPUT"
61+ echo "Successfully rebased on main"
62+ else
63+ echo "rebase_success=false" >> "$GITHUB_OUTPUT"
64+ echo "Rebase failed - will handle conflicts"
65+ git rebase --abort
66+ # Stay on the branch but note we couldn't rebase
67+ fi
68+
69+ # Check for manual commits (commits not from the bot)
70+ MANUAL_COMMITS=$(git log origin/main..$AUTO_BRANCH --author="^(?!github-actions).*" --perl-regexp --oneline | head -20)
71+ if [ -n "$MANUAL_COMMITS" ]; then
72+ echo "has_manual_commits=true" >> "$GITHUB_OUTPUT"
73+ echo "Found manual commits:"
74+ echo "$MANUAL_COMMITS"
75+ # Save the list for the PR body
76+ {
77+ echo "manual_commits<<EOF"
78+ echo "$MANUAL_COMMITS"
79+ echo "EOF"
80+ } >> "$GITHUB_OUTPUT"
81+ else
82+ echo "has_manual_commits=false" >> "$GITHUB_OUTPUT"
83+ fi
84+ else
85+ echo "branch_exists=false" >> "$GITHUB_OUTPUT"
86+ echo "has_manual_commits=false" >> "$GITHUB_OUTPUT"
87+ echo "rebase_success=true" >> "$GITHUB_OUTPUT"
88+ echo "Branch $AUTO_BRANCH does not exist, will create new"
89+
90+ # Create new branch from main
91+ git checkout -b $AUTO_BRANCH
92+ fi
3993
4094 - name : Set up Node.js (with npm cache)
4195 uses : actions/setup-node@v3
@@ -95,25 +149,92 @@ jobs:
95149
96150 rm -f full_output.txt pr_summary.txt
97151
98- - name : Check if branch already exists
99- id : check_branch
152+ - name : Check for changes
153+ id : changes
100154 run : |
101- if git ls-remote --heads origin auto-docs/update-rpcn-connector-docs | grep -q auto-docs ; then
102- echo "exists=true " >> "$GITHUB_OUTPUT"
103- echo "Branch auto-docs/update-rpcn-connector-docs already exists. Skipping PR creation to preserve manual changes. "
155+ if git diff --quiet && git diff --staged --quiet ; then
156+ echo "has_changes=false " >> "$GITHUB_OUTPUT"
157+ echo "No changes detected "
104158 else
105- echo "exists=false" >> "$GITHUB_OUTPUT"
106- echo "Branch does not exist. Will create new PR."
159+ echo "has_changes=true" >> "$GITHUB_OUTPUT"
160+ echo "Changes detected:"
161+ git status --short
107162 fi
108163
109- - name : Create Pull Request
110- if : steps.check_branch.outputs.exists == 'false'
164+ - name : Commit and push changes
165+ if : steps.changes.outputs.has_changes == 'true'
166+ id : commit
167+ run : |
168+ git add -A
169+
170+ # Create commit message with timestamp for tracking
171+ TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M UTC")
172+ git commit -m "docs: Update RPCN connector docs
173+
174+ Auto-generated at $TIMESTAMP"
175+
176+ # Push to the branch
177+ if git push origin $AUTO_BRANCH --force-with-lease; then
178+ echo "push_success=true" >> "$GITHUB_OUTPUT"
179+ else
180+ echo "push_success=false" >> "$GITHUB_OUTPUT"
181+ echo "Push failed - likely a concurrent update. Will retry."
182+
183+ # Fetch latest and try to rebase our commit
184+ git fetch origin $AUTO_BRANCH
185+ if git rebase origin/$AUTO_BRANCH; then
186+ git push origin $AUTO_BRANCH --force-with-lease
187+ echo "push_success=true" >> "$GITHUB_OUTPUT"
188+ else
189+ echo "push_success=false" >> "$GITHUB_OUTPUT"
190+ git rebase --abort
191+ fi
192+ fi
193+
194+ - name : Create or Update Pull Request
195+ if : steps.changes.outputs.has_changes == 'true' && steps.commit.outputs.push_success == 'true'
111196 uses : peter-evans/create-pull-request@v6
112197 with :
113198 token : ${{ env.ACTIONS_BOT_TOKEN }}
114199 base : main
115- branch : auto-docs/update-rpcn-connector-docs
200+ branch : ${{ env.AUTO_BRANCH }}
116201 title : ' auto-docs: Update RPCN connector docs'
117202 commit-message : ' docs: Update RPCN connector docs'
118- body : ${{ steps.generate.outputs.delta_report }}
203+ body : |
204+ ${{ steps.generate.outputs.delta_report }}
205+
206+ ${{ steps.setup.outputs.has_manual_commits == 'true' && format('
207+ ---
208+
209+ ⚠️ **This PR contains manual commits that have been preserved:**
210+
211+ ```
212+ {0}
213+ ```
214+
215+ The automation has added new changes on top of these manual edits.
216+ ', steps.setup.outputs.manual_commits) || '' }}
119217 labels : auto-docs
218+ # Don't delete branch on merge - let the normal PR process handle it
219+ delete-branch : false
220+
221+ - name : Handle no changes
222+ if : steps.changes.outputs.has_changes == 'false'
223+ run : |
224+ echo "No documentation changes detected. This could mean:"
225+ echo "- The connector docs are already up to date"
226+ echo "- The generation produced identical output"
227+ echo ""
228+ if [ "${{ steps.setup.outputs.branch_exists }}" == "true" ]; then
229+ echo "Existing PR branch preserved with any manual changes intact."
230+ fi
231+
232+ - name : Handle push failure
233+ if : steps.changes.outputs.has_changes == 'true' && steps.commit.outputs.push_success == 'false'
234+ run : |
235+ echo "::error::Failed to push changes after retry. This usually means:"
236+ echo "- Another automation run is in progress"
237+ echo "- There are unresolvable conflicts"
238+ echo ""
239+ echo "Manual intervention may be required."
240+ exit 1
0 commit comments