Add GitHub Action to automate the creation of LLMs.txt and LLMs-full.txt #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | | |
| changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- docs/) | |
| 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" | |
| fi | |
| fi | |
| done | |
| changed_subdirs=$(echo "$changed_subdirs" | xargs) | |
| echo "changed_subdirs=$changed_subdirs" >> $GITHUB_OUTPUT | |
| echo "Found changed subdirectories: $changed_subdirs" | |
| - name: Generate llms.txt updates with forced completion | |
| 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: | | |
| # Create a script that will force completion | |
| cat > force_complete.sh << 'EOF' | |
| #!/bin/bash | |
| set -euo pipefail | |
| echo "=== Starting forced completion approach ===" | |
| # Run cursor-agent in background | |
| cursor-agent -p "You are updating documentation summary files. | |
| TASK: Check if docs/$CHANGED_SUBDIRS/llms.txt and docs/$CHANGED_SUBDIRS/llms-full.txt need updates based on PR ${{ github.event.pull_request.number }}. | |
| PROCESS: | |
| 1. Get diff: gh pr diff ${{ github.event.pull_request.number }} | |
| 2. Read docs/$CHANGED_SUBDIRS/llms.txt | |
| 3. Read docs/$CHANGED_SUBDIRS/llms-full.txt | |
| 4. If changes warrant updates: modify the files | |
| 5. If no updates needed: do nothing | |
| 6. Print 'ANALYSIS_COMPLETE' and stop | |
| CRITICAL: You have 5 minutes to complete this. Print 'ANALYSIS_COMPLETE' when done and exit immediately. Do not commit or push." \ | |
| --force --model "$MODEL" --output-format=text & | |
| AGENT_PID=$! | |
| echo "Started cursor-agent with PID: $AGENT_PID" | |
| # Force kill after 5 minutes | |
| (sleep 300; echo "=== Forcing completion after 5 minutes ==="; kill -9 $AGENT_PID 2>/dev/null) & | |
| KILLER_PID=$! | |
| # Wait for completion | |
| if wait $AGENT_PID 2>/dev/null; then | |
| echo "=== Agent completed normally ===" | |
| kill $KILLER_PID 2>/dev/null || true | |
| else | |
| echo "=== Agent was terminated ===" | |
| fi | |
| echo "=== Process finished ===" | |
| EOF | |
| chmod +x force_complete.sh | |
| ./force_complete.sh | |
| - name: Commit changes directly to PR branch | |
| if: steps.detect-changes.outputs.changed_subdirs != '' | |
| id: commit_changes | |
| run: | | |
| echo "changes_committed=false" >> "$GITHUB_OUTPUT" | |
| git add -A | |
| if git diff --staged --quiet; then | |
| echo "No llms.txt changes to commit." | |
| exit 0 | |
| fi | |
| echo "Changes detected:" | |
| git diff --staged --name-only | |
| COMMIT_MSG="docs: update llms summaries for PR #${{ github.event.pull_request.number }}" | |
| git commit -m "$COMMIT_MSG" | |
| git push origin ${{ github.head_ref }} | |
| echo "changes_committed=true" >> "$GITHUB_OUTPUT" | |
| - name: Comment on PR about updates | |
| if: steps.commit_changes.outputs.changes_committed == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: | | |
| 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 "🤖 **LLMs summaries updated**" | |
| echo "" | |
| echo "Updated documentation summary files:" | |
| for file in $changed_llms_files; do | |
| echo "- \`$file\`" | |
| done | |
| echo "" | |
| echo "<!-- auto-update-llms -->" | |
| } > "$COMMENT_FILE" | |
| 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 |