Skip to content

Commit 67b6100

Browse files
committed
feat: add automated documentation update workflow
Add GitHub Actions workflow that automatically updates documentation when PRs are opened or updated. The workflow: - Triggers on PR events (opened, synchronize, reopened, ready_for_review) - Uses Cursor AI to analyze changes and update relevant docs in docs/docs directory - Creates a persistent docs branch for each PR - Posts PR comments with links to view/merge doc updates - Skips execution for docs-only branches to prevent infinite loops This automation ensures documentation stays current with code changes while maintaining consistency with repository style.
1 parent 8841660 commit 67b6100

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Auto Update Docs
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
auto-docs:
13+
if: ${{ !startsWith(github.head_ref, 'docs/') }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install Cursor CLI
22+
run: |
23+
curl https://cursor.com/install -fsS | bash
24+
echo "$HOME/.cursor/bin" >> $GITHUB_PATH
25+
26+
- name: Configure git
27+
run: |
28+
git config user.name "Cursor Agent"
29+
git config user.email "[email protected]"
30+
31+
- name: Generate docs updates (no commit/push/comment)
32+
env:
33+
MODEL: gpt-5
34+
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
BRANCH_PREFIX: docs
37+
run: |
38+
cursor-agent -p "You are operating in a GitHub Actions runner.
39+
40+
The GitHub CLI is available as 'gh'.
41+
login to github using the token: 'gh auth login --with-token < $GH_TOKEN'
42+
Git is available as well.
43+
44+
IMPORTANT: Do NOT create branches, commit, push, or post PR comments. Only modify files in the working directory as needed. A later workflow step is responsible for publishing changes and commenting on the PR.
45+
46+
# Context:
47+
- Repo: ${{ github.repository }}
48+
- Owner: ${{ github.repository_owner }}
49+
- PR Number: ${{ github.event.pull_request.number }}
50+
- Base Ref: ${{ github.base_ref }}
51+
- Head Ref: ${{ github.head_ref }}
52+
53+
# Goal:
54+
- Update repository documentation based on incremental changes introduced by this PR.
55+
56+
# Context:
57+
- Docs for the repository are located in the 'docs/docs/' directory in a flat, markdown files structure.
58+
59+
# Requirements:
60+
1) Determine what changed in the original PR (use 'gh pr diff' and git history as needed). If an existing persistent docs branch '${{ env.BRANCH_PREFIX }}/${{ github.head_ref }}' exists, you may use it as a read-only reference point to understand prior updates.
61+
2) Update only the relevant docs based on those changes. Keep edits minimal and consistent with repo style.
62+
3) Do NOT commit, push, create branches, or post PR comments. Leave the working tree with updated files only; a later step will publish.
63+
64+
# Inputs and conventions:
65+
- Use 'gh pr diff' and git history to detect changes and focus documentation edits accordingly.
66+
- Proceed with making changes only when any '*.py' files in 'application_sdk' are added, modified, or deleted.
67+
- If no doc updates are necessary, make no changes and produce no output.
68+
69+
# Deliverables when updates occur:
70+
- Modified documentation files in the working directory only (no commits/pushes/comments).
71+
" --force --model "$MODEL" --output-format=text
72+
73+
- name: Publish docs branch
74+
id: publish_docs
75+
env:
76+
BRANCH_PREFIX: docs
77+
HEAD_REF: ${{ github.head_ref }}
78+
PR_NUMBER: ${{ github.event.pull_request.number }}
79+
run: |
80+
echo "changes_published=false" >> "$GITHUB_OUTPUT"
81+
82+
DOCS_BRANCH="${BRANCH_PREFIX}/${HEAD_REF}"
83+
84+
# Ensure we are on a local branch that we can push
85+
git fetch origin --prune
86+
87+
# Create/switch to the persistent docs branch, keeping current working tree changes
88+
git checkout -B "$DOCS_BRANCH"
89+
90+
# Stage and detect changes
91+
git add -A
92+
if git diff --staged --quiet; then
93+
echo "No docs changes to publish. Skipping commit/push."
94+
exit 0
95+
fi
96+
97+
COMMIT_MSG="docs: update for PR #${PR_NUMBER} (${HEAD_REF} @ $(git rev-parse --short HEAD))"
98+
git commit -m "$COMMIT_MSG"
99+
git push --set-upstream origin "$DOCS_BRANCH"
100+
101+
echo "changes_published=true" >> "$GITHUB_OUTPUT"
102+
103+
- name: Post or update PR comment
104+
if: steps.publish_docs.outputs.changes_published == 'true'
105+
env:
106+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
BRANCH_PREFIX: docs
108+
REPO: ${{ github.repository }}
109+
BASE_REF: ${{ github.base_ref }}
110+
HEAD_REF: ${{ github.head_ref }}
111+
PR_NUMBER: ${{ github.event.pull_request.number }}
112+
run: |
113+
114+
DOCS_BRANCH="${BRANCH_PREFIX}/${HEAD_REF}"
115+
COMPARE_URL="https://github.com/${REPO}/compare/${BASE_REF}...${DOCS_BRANCH}?quick_pull=1&title=docs%3A+updates+for+PR+%23${PR_NUMBER}"
116+
117+
COMMENT_FILE="${RUNNER_TEMP}/auto-docs-comment.md"
118+
{
119+
echo "Cursor updated docs branch: \`${DOCS_BRANCH}\`"
120+
echo "You can now [view the diff and quick-create a PR to merge these docs updates](${COMPARE_URL})."
121+
echo
122+
echo "_This comment will be updated on subsequent runs as the PR changes._"
123+
echo
124+
echo "<!-- auto-update-docs-split -->"
125+
} > "$COMMENT_FILE"
126+
127+
# If editing the last bot comment fails (older gh), fall back to creating a new comment
128+
if gh pr comment "$PR_NUMBER" --body-file "$COMMENT_FILE" --edit-last; then
129+
echo "Updated existing PR comment."
130+
else
131+
gh pr comment "$PR_NUMBER" --body-file "$COMMENT_FILE"
132+
echo "Posted new PR comment."
133+
fi

0 commit comments

Comments
 (0)