diff --git a/.github/workflows/validate-llms.yml b/.github/workflows/validate-llms.yml new file mode 100644 index 0000000..3b212a9 --- /dev/null +++ b/.github/workflows/validate-llms.yml @@ -0,0 +1,135 @@ +name: Validate and Update llms.txt + +on: + pull_request_target: + types: [opened, synchronize, reopened] + paths: + - 'packages/*/src/**' + - 'packages/*/llms.txt' + +concurrency: + group: llms-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: write + pull-requests: write + +jobs: + validate-llms: + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + token: ${{ secrets.ACTION_TOKEN }} + fetch-depth: 0 + + - name: Configure git + run: | + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git remote set-url origin https://x-access-token:${{ secrets.ACTION_TOKEN }}@github.com/${{ github.repository }} + + - name: Validate and auto-update llms.txt per package + uses: anthropics/claude-code-action@v1 + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + github_token: ${{ secrets.ACTION_TOKEN }} + prompt: | + `packages/` 아래 변경된 패키지들의 `llms.txt`를 검사하고 필요하면 자동 업데이트해줘. + + ## 작업 순서 + + ### 1. 변경된 패키지 파악 + + ```bash + git diff --name-only origin/${{ github.base_ref }}...HEAD -- packages/ + ``` + + `packages//` 수준의 고유 패키지 목록을 추출. + `packages/` 이하 경로가 없으면 조용히 종료. + + ### 2. 각 패키지별 처리 + + 변경된 각 패키지(`PKG=packages/`)에 대해: + + #### 2-1. 현재 공개 API 수집 + + ```bash + # 공개 exports 목록 (src/index.ts 기준) + cat "$PKG/src/index.ts" + ``` + + `export ... from '...'` 구문에서 export된 심볼 목록을 추출. + + #### 2-2. 함수별 설명 수집 + + 각 export된 심볼에 대해 동일 디렉토리의 `.md` 파일 확인: + + ```bash + # 예: src/utils/formatNumberWithComma.ts 옆에 formatNumberWithComma.md 존재 + find "$PKG/src" -name "*.md" | sort + ``` + + `.md` 파일이 있으면 그 내용(첫 문단 설명)을 llms.txt 설명으로 사용. + `.md` 파일이 없으면 `.ts` 파일의 JSDoc `@description` 또는 첫 번째 주석을 사용. + + #### 2-3. 현재 llms.txt와 비교 + + `$PKG/llms.txt`를 읽어 `## API` 섹션의 항목과 비교: + - **추가된 export**: `index.ts`에는 있지만 `llms.txt`에 없는 것 + - **삭제된 export**: `llms.txt`에는 있지만 `index.ts`에 없는 것 + - **설명 변경**: `.md` 파일이 수정된 경우 해당 항목 설명 업데이트 + + #### 2-4. llms.txt 업데이트 (변경이 있을 때만) + + `$PKG/llms.txt`의 `## API` 섹션 수정: + - 삭제된 항목 제거 + - 추가된 항목 알파벳 순 삽입, 형식: + ``` + - `symbolName(signature)` — 설명 (영문, 한 줄) + ``` + - `.md` 파일 수정에 따른 설명 업데이트 + - `## API` 섹션 외 (Installation, Usage 등)는 절대 수정하지 않음 + + ### 3. 변경된 파일 커밋 + + 업데이트된 `llms.txt` 파일이 하나라도 있으면: + + ```bash + git add packages/*/llms.txt + git diff --cached --exit-code || git commit -m "chore: auto-update llms.txt API section" + git push origin HEAD:${{ github.head_ref }} + ``` + + ### 4. PR 코멘트 작성 + + 기존에 이 워크플로가 남긴 코멘트(`` 태그 포함)가 있으면 업데이트, 없으면 새로 작성. + + **업데이트된 패키지가 있는 경우:** + ```markdown + + ### 📝 llms.txt 자동 업데이트 + + API 변경사항이 감지되어 아래 패키지의 `llms.txt`를 자동으로 업데이트했습니다. + + **@naverpay/utils** + | 구분 | 항목 | + |------|------| + | ➕ 추가 | `formatPrice`, `formatDate` | + | ➖ 제거 | `oldUtil` | + | ✏️ 설명 변경 | `formatNumberWithComma` | + + 변경된 설명이 올바른지 확인 후 머지해주세요. + ``` + + **모두 최신 상태인 경우:** + ```markdown + + ✅ 변경된 패키지의 `llms.txt`가 모두 최신 상태입니다. + ``` + claude_args: | + --allowedTools "Bash(git diff:*),Bash(git log:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(git config:*),Bash(ls:*),Bash(find:*),Bash(cat:*),Bash(grep:*),Bash(sed:*),Read,Write,Edit,Glob" + --max-turns 15