Add GitHub Action to automate the creation of LLMs.txt and LLMs-full.txt #6
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: Update docs for changed subdirectories | |
| 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: | | |
| # Set timeout and error handling | |
| set -euo pipefail | |
| # Run cursor-agent with 30-minute timeout (1800 seconds) | |
| timeout 1800 cursor-agent -p "You are operating in a GitHub Actions runner to update documentation summary files. | |
| The GitHub CLI is available as \`gh\` and authenticated via \`GH_TOKEN\`. Git is available. | |
| # 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 | |
| - Current Branch: ${{ github.head_ref }} | |
| # Goal: | |
| Update llms.txt and llms-full.txt files in changed subdirectories and commit directly to the PR branch. | |
| # Critical Instructions: | |
| 1) Check what changed in the PR using \`gh pr diff ${{ github.event.pull_request.number }}\` | |
| 2) For each subdirectory in CHANGED_SUBDIRS, read the current llms.txt and llms-full.txt files | |
| 3) Determine if the changes warrant updates to these summary files | |
| 4) If updates are needed: | |
| - Update the files | |
| - Commit with message: 'docs: update llms summaries for [subdirectory]' | |
| - Push to current branch | |
| - Add a brief PR comment explaining the updates | |
| 5) If NO updates are needed: | |
| - Print 'NO_UPDATES_NEEDED' and exit immediately | |
| - Do not create commits, branches, or comments | |
| # IMPORTANT EXIT BEHAVIOR: | |
| - Always end your response with either 'UPDATES_COMPLETED' or 'NO_UPDATES_NEEDED' | |
| - Do not hang or wait for additional input | |
| - Exit cleanly after determining the outcome | |
| # File Requirements: | |
| - Only update llms.txt and llms-full.txt in the specified subdirectories | |
| - Do NOT update root-level llms files | |
| - Maintain existing format and style | |
| - llms.txt = concise summary/index | |
| - llms-full.txt = comprehensive guide with code examples | |
| Remember: Always conclude with 'UPDATES_COMPLETED' or 'NO_UPDATES_NEEDED' and exit. | |
| " --force --model "$MODEL" --output-format=text || { | |
| echo "Cursor agent completed or timed out after 30 minutes" | |
| exit 0 | |
| } | |
| echo "Documentation update process completed" | |
| - name: Check for any uncommitted changes | |
| if: steps.detect-changes.outputs.changed_subdirs != '' | |
| run: | | |
| if git diff --quiet && git diff --cached --quiet; then | |
| echo "No changes were made to commit" | |
| else | |
| echo "Changes detected but not committed - this might indicate an issue" | |
| git status | |
| fi |