-
Notifications
You must be signed in to change notification settings - Fork 519
177 lines (146 loc) · 7.37 KB
/
main.yml
File metadata and controls
177 lines (146 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Update llms.txt and llms-full.txt in subdirectories
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: write
pull-requests: write
jobs:
auto-docs:
if: ${{ !startsWith(github.head_ref, 'docs/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Install Cursor CLI
run: |
curl https://cursor.com/install -fsS | bash
echo "$HOME/.cursor/bin" >> $GITHUB_PATH
- name: Configure git
run: |
git config user.name "Cursor Agent"
git config user.email "cursoragent@cursor.com"
- name: Detect changed subdirectories
id: detect-changes
run: |
echo "=== Detecting changed subdirectories ==="
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- docs/)
echo "Changed files in docs/:"
echo "$changed_files"
changed_subdirs=""
for file in $changed_files; do
subdir=$(echo "$file" | sed -n 's|^docs/\([^/]*\)/.*|\1|p')
if [ -n "$subdir" ] && [ -f "docs/$subdir/llms.txt" ] && [ -f "docs/$subdir/llms-full.txt" ]; then
if [[ ! "$changed_subdirs" =~ (^|[[:space:]])"$subdir"($|[[:space:]]) ]]; then
changed_subdirs="$changed_subdirs $subdir"
echo "Found subdirectory with llms files: $subdir"
fi
fi
done
changed_subdirs=$(echo "$changed_subdirs" | xargs)
echo "changed_subdirs=$changed_subdirs" >> $GITHUB_OUTPUT
echo "=== Final changed subdirectories: $changed_subdirs ==="
- name: Generate llms.txt updates (restricted)
if: steps.detect-changes.outputs.changed_subdirs != ''
env:
MODEL: gpt-5
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGED_SUBDIRS: ${{ steps.detect-changes.outputs.changed_subdirs }}
run: |
echo "=== Starting restricted file modification process ==="
echo "Processing subdirectories: $CHANGED_SUBDIRS"
cursor-agent -p "You are updating documentation summary files in a GitHub Actions runner.
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.
# Context:
- Repo: ${{ github.repository }}
- PR Number: ${{ github.event.pull_request.number }}
- Base Ref: ${{ github.base_ref }}
- Head Ref: ${{ github.head_ref }}
- Changed Subdirectories: $CHANGED_SUBDIRS
# Your Task:
Update llms.txt and llms-full.txt files in the changed subdirectories based on documentation changes in this PR.
# Step-by-Step Process (print each step as you do it):
1. Print 'STEP 1: Getting PR diff'
2. Get PR changes: \`gh pr diff ${{ github.event.pull_request.number }}\`
3. Print 'STEP 2: Processing subdirectories: $CHANGED_SUBDIRS'
4. For each subdirectory in CHANGED_SUBDIRS:
a. Print 'STEP 3a: Reading docs/[subdirectory]/llms.txt'
b. Print 'STEP 3b: Reading docs/[subdirectory]/llms-full.txt'
c. Print 'STEP 3c: Analyzing if updates are needed for [subdirectory]'
d. If updates needed: Print 'STEP 3d: Updating files for [subdirectory]' and modify the files
e. If no updates needed: Print 'STEP 3e: No updates needed for [subdirectory]'
5. Print 'STEP 4: File modifications complete'
6. Print 'TASK_FINISHED' and exit
# File Requirements:
- Only modify docs/[subdirectory]/llms.txt and docs/[subdirectory]/llms-full.txt files
- Do NOT modify root-level llms.txt or llms-full.txt files
- llms.txt should be a concise summary/index of the documentation in that subdirectory
- llms-full.txt should be a comprehensive guide with code examples and detailed explanations
- Maintain existing format and style
- Only update files that actually need changes based on PR content
# Critical Restrictions:
- NO git operations (no commit, push, branch creation)
- NO PR comments or API calls except gh pr diff
- Only file modifications in working directory
- Must print progress steps as you go
- Must end with 'TASK_FINISHED'
Begin now and print each step clearly.
" --force --model "$MODEL" --output-format=text
echo "=== Cursor agent file modification completed ==="
- name: Commit changes to PR branch (deterministic)
if: steps.detect-changes.outputs.changed_subdirs != ''
id: commit_changes
run: |
echo "=== Checking for file changes to commit ==="
# Stage all changes
git add -A
# Check if there are any changes to commit
if git diff --staged --quiet; then
echo "No llms.txt changes to commit."
echo "changes_committed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Changes detected in the following files:"
git diff --staged --name-only
echo "=== Committing changes to PR branch ==="
COMMIT_MSG="docs: update llms summaries for subdirectories (${{ steps.detect-changes.outputs.changed_subdirs }})"
git commit -m "$COMMIT_MSG"
git push origin ${{ github.head_ref }}
echo "changes_committed=true" >> "$GITHUB_OUTPUT"
echo "=== Changes committed and pushed successfully ==="
- name: Post PR comment (deterministic)
if: steps.commit_changes.outputs.changes_committed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
echo "=== Posting PR comment about updates ==="
# Get list of changed llms files
changed_llms_files=$(git diff HEAD~1 --name-only | grep -E "llms(-full)?\.txt$" | head -10)
COMMENT_FILE="${RUNNER_TEMP}/llms-update-comment.md"
{
echo "🤖 **LLM summary files updated**"
echo ""
echo "Updated the following documentation summary files based on changes in subdirectories: \`${{ steps.detect-changes.outputs.changed_subdirs }}\`"
echo ""
echo "**Files updated:**"
for file in $changed_llms_files; do
echo "- \`$file\`"
done
echo ""
echo "_This comment will be updated if you make more changes to the PR._"
echo ""
echo "<!-- auto-update-llms -->"
} > "$COMMENT_FILE"
# Try to update existing comment, fall back to new comment
if gh pr comment "$PR_NUMBER" --body-file "$COMMENT_FILE" --edit-last; then
echo "Updated existing PR comment."
else
gh pr comment "$PR_NUMBER" --body-file "$COMMENT_FILE"
echo "Posted new PR comment."
fi
echo "=== PR comment posted successfully ==="