44 pull_request :
55 types : [closed]
66 branches : [main]
7+ workflow_dispatch :
8+ inputs :
9+ commit_sha :
10+ description : ' Commit SHA to analyze for documentation updates'
11+ required : true
12+ type : string
713
814jobs :
915 docs-sync :
10- if : github.event.pull_request.merged == true
16+ if : github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
1117 runs-on : ubuntu-latest
1218 permissions :
1319 contents : read
@@ -22,10 +28,18 @@ jobs:
2228
2329 - name : Get changed files
2430 id : changed-files
31+ env :
32+ COMMIT_SHA : ${{ github.event.inputs.commit_sha }}
2533 run : |
26- # Get list of changed files in the merged PR
27- git fetch origin main
28- CHANGED_FILES=$(git diff --name-only origin/main~1 origin/main)
34+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
35+ # Get changed files for the specified commit
36+ git fetch origin
37+ CHANGED_FILES=$(git diff --name-only "$COMMIT_SHA"~1 "$COMMIT_SHA")
38+ else
39+ # Get list of changed files in the merged PR
40+ git fetch origin main
41+ CHANGED_FILES=$(git diff --name-only origin/main~1 origin/main)
42+ fi
2943 echo "changed_files<<EOF" >> $GITHUB_OUTPUT
3044 echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
3145 echo "EOF" >> $GITHUB_OUTPUT
@@ -73,15 +87,21 @@ jobs:
7387 - name : Analyze changes and update docs
7488 if : steps.check-docs.outputs.needs_update == 'true'
7589 uses : anthropics/claude-code-action@beta
90+ env :
91+ PR_TITLE : ${{ github.event.pull_request.title }}
92+ PR_BODY : ${{ github.event.pull_request.body }}
93+ COMMIT_SHA : ${{ github.event.inputs.commit_sha }}
94+ MERGE_COMMIT_SHA : ${{ github.event.pull_request.merge_commit_sha }}
7695 with :
7796 anthropic_api_key : ${{ secrets.ANTHROPIC_API_KEY }}
7897 direct_prompt : |
7998 I need you to analyze the changes in this controller repository PR and update the documentation in the cartridge-gg/docs repository accordingly.
8099
81- **PR Information:**
82- - Title: ${{ github.event.pull_request.title }}
83- - Description: ${{ github.event.pull_request.body }}
100+ **Change Information:**
101+ - Title: ${{ env.PR_TITLE || format('Manual trigger for commit {0}', env.COMMIT_SHA) }}
102+ - Description: ${{ env.PR_BODY || 'Manually triggered documentation sync' }}
84103 - Files changed: ${{ steps.changed-files.outputs.changed_files }}
104+ - Commit SHA: ${{ env.MERGE_COMMIT_SHA || env.COMMIT_SHA }}
85105
86106 **Your tasks:**
87107 1. Review the changed files and PR description to understand what functionality was added, modified, or removed
@@ -106,6 +126,12 @@ jobs:
106126 - name : Create branch and commit changes
107127 if : steps.check-docs.outputs.needs_update == 'true'
108128 working-directory : docs-repo
129+ env :
130+ GITHUB_TOKEN : ${{ secrets.CREATE_PR_TOKEN }}
131+ PR_TITLE : ${{ github.event.pull_request.title }}
132+ PR_NUMBER : ${{ github.event.pull_request.number }}
133+ COMMIT_SHA : ${{ github.event.inputs.commit_sha }}
134+ CHANGED_FILES : ${{ steps.changed-files.outputs.changed_files }}
109135 run : |
110136 # Configure git
111137 git config user.name "github-actions[bot]"
@@ -119,31 +145,51 @@ jobs:
119145
120146 # Add and commit changes
121147 git add .
122- git commit -m "docs: Update documentation for controller PR #${{ github.event.pull_request.number }}
148+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
149+ git commit -m "docs: Update documentation for controller commit $COMMIT_SHA
123150
124- Updates documentation to reflect changes made in:
125- ${{ github.event.pull_request.title }}
126-
127- Related controller PR: cartridge-gg/controller#${{ github.event.pull_request.number }}"
151+ Updates documentation to reflect changes made in commit :
152+ $COMMIT_SHA
153+
154+ Manually triggered documentation sync"
155+ else
156+ git commit -m "docs : Update documentation for controller PR # $PR_NUMBER
157+
158+ Updates documentation to reflect changes made in :
159+ $PR_TITLE
160+
161+ Related controller PR : cartridge-gg/controller#$PR_NUMBER"
162+ fi
128163
129164 # Push branch
130165 git push origin "$BRANCH_NAME"
131166
132167 # Create PR
133- gh pr create \
134- --title "docs: Update documentation for controller PR #${{ github.event.pull_request.number }}" \
135- --body "This PR updates the documentation to reflect changes made in cartridge-gg/controller#${{ github.event.pull_request.number }}
136-
137- **Original PR Details:**
138- - Title: ${{ github.event.pull_request.title }}
139- - Files changed: ${{ steps.changed-files.outputs.changed_files }}
140-
141- Please review the documentation changes to ensure they accurately reflect the controller updates."
168+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
169+ gh pr create \
170+ --title "docs : Update documentation for controller commit $COMMIT_SHA" \
171+ --body "This PR updates the documentation to reflect changes made in cartridge-gg/controller commit $COMMIT_SHA
172+
173+ **Commit Details:**
174+ - Commit SHA : $COMMIT_SHA
175+ - Files changed : $CHANGED_FILES
176+ - Trigger : Manual documentation sync
177+
178+ Please review the documentation changes to ensure they accurately reflect the controller updates."
179+ else
180+ gh pr create \
181+ --title "docs : Update documentation for controller PR # $PR_NUMBER" \
182+ --body "This PR updates the documentation to reflect changes made in cartridge-gg/controller#$PR_NUMBER
183+
184+ **Original PR Details:**
185+ - Title : $PR_TITLE
186+ - Files changed : $CHANGED_FILES
187+
188+ Please review the documentation changes to ensure they accurately reflect the controller updates."
189+ fi
142190 else
143191 echo "No documentation changes were made by Claude"
144192 fi
145- env :
146- GITHUB_TOKEN : ${{ secrets.CREATE_PR_TOKEN }}
147193
148194 - name : Cleanup
149195 if : always()
0 commit comments