Fetch Claude Code Documentation #533
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: Fetch Claude Code Documentation | |
| on: | |
| schedule: | |
| # JST 3:00 (UTC 18:00) | |
| - cron: '0 18 * * *' | |
| # JST 9:00 (UTC 0:00) | |
| - cron: '0 0 * * *' | |
| # JST 15:00 (UTC 6:00) | |
| - cron: '0 6 * * *' | |
| # JST 21:00 (UTC 12:00) | |
| - cron: '0 12 * * *' | |
| workflow_dispatch: # Manual trigger | |
| inputs: | |
| force_update: | |
| description: 'Force update all documents' | |
| required: false | |
| default: false | |
| type: boolean | |
| # Prevent concurrent executions to avoid git conflicts | |
| concurrency: | |
| group: fetch-docs | |
| cancel-in-progress: false | |
| jobs: | |
| fetch-docs: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Need write permission to commit changes | |
| issues: write # Need write permission to create issues on failure | |
| id-token: write # Need for Claude Code Action OIDC authentication | |
| outputs: | |
| changed: ${{ steps.git-check.outputs.changed }} | |
| changed_files: ${{ steps.git-check.outputs.changed_files }} | |
| commit_sha: ${{ steps.get-sha.outputs.sha }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper git diff | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Compile TypeScript | |
| run: npm run build | |
| - name: Fetch documentation | |
| run: npm run fetch-docs | |
| env: | |
| NODE_ENV: production | |
| - name: Check for changes | |
| id: git-check | |
| run: | | |
| git add -A | |
| git diff --staged --quiet || echo "changed=true" >> $GITHUB_OUTPUT | |
| # Count changed files | |
| CHANGED_FILES=$(git diff --staged --name-only | wc -l) | |
| echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT | |
| # Get list of changed files | |
| if [ "$CHANGED_FILES" -gt 0 ]; then | |
| echo "Changed files:" | |
| git diff --staged --name-only | |
| fi | |
| - name: Commit changes | |
| if: steps.git-check.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Get timestamp | |
| TIMESTAMP=$(date -u +'%Y-%m-%d %H:%M:%S UTC') | |
| CHANGED_COUNT="${{ steps.git-check.outputs.changed_files }}" | |
| # Create commit message | |
| if [ "$CHANGED_COUNT" -eq 1 ]; then | |
| COMMIT_MSG="📝 Update Claude Code docs - 1 file changed" | |
| else | |
| COMMIT_MSG="📝 Update Claude Code docs - $CHANGED_COUNT files changed" | |
| fi | |
| # Add detailed description | |
| COMMIT_BODY="Automated documentation update at $TIMESTAMP"$'\n\n'"Modified files:" | |
| # Add list of changed files to commit body | |
| for file in $(git diff --staged --name-only | head -20); do | |
| COMMIT_BODY="${COMMIT_BODY}"$'\n'"- $file" | |
| done | |
| if [ "$CHANGED_COUNT" -gt 20 ]; then | |
| REMAINING=$((CHANGED_COUNT - 20)) | |
| COMMIT_BODY="${COMMIT_BODY}"$'\n'"... and ${REMAINING} more files" | |
| fi | |
| # Commit with message and body | |
| git commit -m "$COMMIT_MSG" -m "$COMMIT_BODY" | |
| - name: Push changes | |
| if: steps.git-check.outputs.changed == 'true' | |
| run: | | |
| # Pull latest changes and rebase to avoid conflicts | |
| git pull --rebase origin main | |
| git push | |
| - name: Get commit SHA | |
| id: get-sha | |
| if: steps.git-check.outputs.changed == 'true' | |
| run: | | |
| echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
| - name: Report status | |
| if: always() | |
| run: | | |
| if [ "${{ steps.git-check.outputs.changed }}" == "true" ]; then | |
| echo "✅ Documentation updated successfully!" | |
| echo "📊 Changed files: ${{ steps.git-check.outputs.changed_files }}" | |
| else | |
| echo "ℹ️ No changes detected in documentation" | |
| fi | |
| # Show metadata summary if it exists | |
| if [ -f "metadata/last_update.json" ]; then | |
| echo "" | |
| echo "📈 Fetch Summary:" | |
| cat metadata/last_update.json | |
| fi | |
| - name: Create issue on failure | |
| if: failure() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = `Documentation fetch failed - ${new Date().toISOString()}`; | |
| const body = `The automated documentation fetch failed. | |
| **Workflow run:** ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId} | |
| **Time:** ${new Date().toISOString()} | |
| Please check the workflow logs for more details.`; | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['bug', 'documentation', 'automated'] | |
| }); | |
| # Notify changes via Discord | |
| notify: | |
| needs: fetch-docs | |
| if: needs.fetch-docs.outputs.changed == 'true' | |
| permissions: | |
| contents: read # Required for checkout in reusable workflow | |
| id-token: write # Required for Claude Code Action OIDC authentication | |
| uses: ./.github/workflows/notify-changes.yml | |
| with: | |
| commit_sha: ${{ needs.fetch-docs.outputs.commit_sha }} | |
| changed_files_count: ${{ fromJson(needs.fetch-docs.outputs.changed_files) }} | |
| tracker_name: 'Claude Code Docs' | |
| secrets: | |
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} |