Skip to content

Commit 1f318be

Browse files
authored
update docs sync workflow logic (#639)
* update msg publishing logic * test: add example to StreamingResponse.send() docs * docs: expand observability documentation with comprehensive examples and best practices * fix: clarify docs sync evaluation criteria - ALWAYS sync if docs/ changed * fix: add Write tool to allowed tools for creating new doc files * fix: prevent Claude from fetching wrong PR data - use only context variables * fix: prevent Claude from adding custom PR descriptions beyond template * feat: update existing cloudflare-docs PR instead of creating duplicates * fix: properly format comment body with newlines using printf * fix: remove Co-Authored-By line from PR descriptions * revert: restore observability.md to original state
1 parent b2187b4 commit 1f318be

File tree

1 file changed

+60
-21
lines changed

1 file changed

+60
-21
lines changed

.github/workflows/sync-docs.yml

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,23 @@ jobs:
6363
if: steps.get-diffs.outputs.skip != 'true'
6464
id: create-prompt
6565
run: |
66+
# Store PR metadata in environment variables to avoid shell escaping issues
67+
PR_NUMBER="${{ github.event.pull_request.number }}"
68+
PR_TITLE="${{ github.event.pull_request.title }}"
69+
PR_URL="https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
70+
6671
cat > /tmp/claude_prompt.md << EOF
6772
# Intelligent Documentation Sync Task
6873
74+
⚠️ **CRITICAL INSTRUCTION**: All PR metadata is provided in the Context section below.
75+
DO NOT run \`gh pr view\`, \`gh api\`, or any other command to fetch PR information from GitHub.
76+
The PR number, title, and URL below are the ONLY source of truth. Use them EXACTLY as written.
77+
6978
## Context
7079
- **Source Repository:** ${{ github.repository }}
71-
- **Original PR:** #${{ github.event.pull_request.number }}
72-
- **PR Title:** ${{ github.event.pull_request.title }}
80+
- **Original PR Number:** ${PR_NUMBER}
81+
- **Original PR Title:** ${PR_TITLE}
82+
- **Original PR URL:** ${PR_URL}
7383
- **PR Description:**
7484
${{ github.event.pull_request.body }}
7585
@@ -86,55 +96,84 @@ jobs:
8696
8797
Please review the changes in this PR and determine if they require documentation updates in cloudflare-docs:
8898
89-
- **DO sync if:**
90-
- Documentation files in docs/ were directly changed
99+
- **ALWAYS sync if ANY of these are true:**
100+
- Documentation files in docs/ were directly changed (even if other non-doc files also changed)
91101
- New public API features or functions were added
92102
- Breaking changes that affect user-facing behavior
93103
- New configuration options or environment variables
94104
- New examples or usage patterns that should be documented
95105
- Bug fixes that clarify documented behavior
96106
97-
- **DO NOT sync if:**
107+
- **DO NOT sync ONLY if ALL changes are:**
98108
- Only internal code refactoring with no behavior changes
99109
- Test-only changes
100-
- CI/workflow changes
110+
- CI/workflow changes (UNLESS docs/ files also changed)
101111
- Minor typo fixes in code comments
102112
- Internal dependency updates with no API changes
103113
114+
**IMPORTANT**: If this PR includes ANY changes to files in the docs/ directory, you MUST proceed with the sync, even if the PR also includes other types of changes like workflow updates.
115+
104116
**Step 2: If Documentation Sync is Needed**
105117
106118
If you determine documentation updates are required, YOU MUST COMPLETE ALL STEPS:
107119
108-
1. Navigate to ./cloudflare-docs (already cloned, branch sync-docs-pr-${{ github.event.pull_request.number }} checked out)
120+
1. Navigate to ./cloudflare-docs (already cloned, branch sync-docs-pr-${PR_NUMBER} checked out)
109121
2. Adapt changes for cloudflare-docs repository structure and style
110122
3. Create or update the appropriate markdown files
111123
4. Ensure content follows cloudflare-docs conventions
112124
113125
5. **CRITICAL - Commit changes:**
114-
Run: `cd cloudflare-docs && git add . && git commit -m "Sync docs from PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"`
126+
Run exactly: `cd cloudflare-docs && git add . && git commit -m "Sync docs from cloudflare/agents#${PR_NUMBER}: ${PR_TITLE}"`
115127
116128
6. **CRITICAL - Push to remote:**
117-
Run: `cd cloudflare-docs && git push origin sync-docs-pr-${{ github.event.pull_request.number }}`
129+
Run exactly: `cd cloudflare-docs && git push origin sync-docs-pr-${PR_NUMBER}`
118130
119-
7. **CRITICAL - Create PR in cloudflare-docs:**
120-
Run: `gh pr create --repo cloudflare/cloudflare-docs --base main --head sync-docs-pr-${{ github.event.pull_request.number }} --title "📚 Sync docs from ${{ github.repository }}#${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}" --body "🤖 Automated sync from https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"`
131+
7. **CRITICAL - Create or update PR in cloudflare-docs:**
132+
⚠️ **CRITICAL**:
133+
- DO NOT fetch PR data from GitHub API to get title/description
134+
- DO NOT add your own description or summary
135+
- Use ONLY the PR_NUMBER, PR_TITLE, and PR_URL from the Context section above
136+
137+
First check if PR already exists, then create or update:
138+
```bash
139+
# Check if PR already exists
140+
EXISTING_PR=$(gh pr list --repo cloudflare/cloudflare-docs --head sync-docs-pr-${PR_NUMBER} --json number --jq '.[0].number')
141+
142+
PR_TITLE_TEXT="📚 Sync docs from cloudflare/agents#${PR_NUMBER}: ${PR_TITLE}"
143+
PR_BODY_TEXT="Syncs documentation changes from [cloudflare/agents#${PR_NUMBER}](${PR_URL}): **${PR_TITLE}**"
144+
145+
if [ -n "$EXISTING_PR" ]; then
146+
# Update existing PR
147+
echo "Updating existing PR #$EXISTING_PR"
148+
gh pr edit $EXISTING_PR --repo cloudflare/cloudflare-docs --title "$PR_TITLE_TEXT" --body "$PR_BODY_TEXT"
149+
else
150+
# Create new PR
151+
echo "Creating new PR"
152+
gh pr create --repo cloudflare/cloudflare-docs --base main --head sync-docs-pr-${PR_NUMBER} --title "$PR_TITLE_TEXT" --body "$PR_BODY_TEXT"
153+
fi
154+
```
155+
156+
DO NOT modify the PR_TITLE_TEXT or PR_BODY_TEXT variables.
121157
122158
8. **CRITICAL - Comment on original PR (or edit existing comment):**
123-
Get the docs PR URL, then create or update comment:
159+
Get the docs PR URL, then create or update comment using PR_NUMBER from context:
124160
```bash
125-
DOCS_PR_URL=$(gh pr list --repo cloudflare/cloudflare-docs --head sync-docs-pr-${{ github.event.pull_request.number }} --json url --jq '.[0].url')
161+
DOCS_PR_URL=$(gh pr list --repo cloudflare/cloudflare-docs --head sync-docs-pr-${PR_NUMBER} --json url --jq '.[0].url')
126162
127-
# Check if bot comment already exists (look for comments from github-actions bot containing "Documentation sync")
128-
EXISTING_COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --json comments --jq '.comments[] | select(.author.login == "github-actions" and (.body | contains("Documentation sync"))) | .id' | head -1)
163+
# Check if bot comment already exists (look for unique marker)
164+
EXISTING_COMMENT_ID=$(gh api repos/cloudflare/agents/issues/${PR_NUMBER}/comments --jq '.[] | select(.body | contains("docs-sync-bot-comment-marker")) | .id' | head -1)
129165
130-
COMMENT_BODY="📚 **Documentation sync PR:** $DOCS_PR_URL\n\n_This comment will be updated as the PR changes._"
166+
# Create comment body with proper newlines using printf
167+
COMMENT_BODY=$(printf '<!-- docs-sync-bot-comment-marker -->\n\n📚 **Documentation sync PR:** %s\n\n_This comment will be updated as the PR changes._' "$DOCS_PR_URL")
131168
132169
if [ -n "$EXISTING_COMMENT_ID" ]; then
133-
# Edit existing comment
134-
gh api --method PATCH /repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID -f body="$COMMENT_BODY"
170+
# Update existing comment
171+
echo "Updating existing comment ID: $EXISTING_COMMENT_ID"
172+
gh api --method PATCH /repos/cloudflare/agents/issues/comments/$EXISTING_COMMENT_ID -f body="$COMMENT_BODY"
135173
else
136174
# Create new comment
137-
gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "$COMMENT_BODY"
175+
echo "Creating new comment on PR #${PR_NUMBER}"
176+
gh pr comment ${PR_NUMBER} --repo cloudflare/agents --body "$COMMENT_BODY"
138177
fi
139178
```
140179
@@ -176,7 +215,7 @@ jobs:
176215
- Use the GH_TOKEN environment variable for authentication with gh CLI
177216
- Adapt paths, links, and references as needed for cloudflare-docs structure
178217
- Follow existing patterns in the cloudflare-docs repository
179-
- Be conservative but thorough - when in doubt, create the sync PR for human review
218+
- **DEFAULT TO SYNCING**: When in doubt about whether changes warrant a sync, ALWAYS create the sync PR for human review. It's better to create an unnecessary PR than to miss important documentation updates.
180219
181220
Begin your evaluation now.
182221
EOF
@@ -192,6 +231,6 @@ jobs:
192231
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
193232
github_token: ${{ secrets.GITHUB_TOKEN }}
194233
prompt: ${{ steps.create-prompt.outputs.prompt }}
195-
claude_args: "--allowed-tools Bash,Edit"
234+
claude_args: "--allowed-tools Bash,Edit,Write"
196235
env:
197236
GH_TOKEN: ${{ secrets.AGENTS_GITHUB_TOKEN }}

0 commit comments

Comments
 (0)