diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 457f7ba..c8060bb 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -89,6 +89,13 @@ "description": "Create a Claude Code plugin marketplace from existing components using symlinks.", "version": "1.0.0", "keywords": ["marketplace", "plugins", "symlinks", "distribution"] + }, + { + "name": "github-actions", + "source": "./plugins/github-actions", + "description": "Showcase GitHub Actions workflows for Claude Code CI/CD automation.", + "version": "1.0.0", + "keywords": ["github-actions", "ci-cd", "workflows", "automation", "pr-review"] } ] } diff --git a/.claude/commands/setup-github-actions.md b/.claude/commands/setup-github-actions.md new file mode 100644 index 0000000..9b55af6 --- /dev/null +++ b/.claude/commands/setup-github-actions.md @@ -0,0 +1,130 @@ +--- +description: Set up Claude Code GitHub Actions workflows in your repository +allowed-tools: Read, Write, Bash(mkdir:*), Bash(ls:*), AskUserQuestion +--- + +# Setup GitHub Actions for Claude Code + +Help the user set up showcase Claude Code GitHub Actions workflows in their repository. + +## Available Workflows + +| Workflow | Stack | Description | +|----------|-------|-------------| +| **PR Review** | Any | Automatically review pull requests with Claude | +| **Documentation Sync** | Any | Keep docs in sync with code changes | +| **Node.js Code Quality** | Node.js | Periodic code quality audits (requires npm) | +| **Node.js Dependency Audit** | Node.js | Check for outdated/vulnerable dependencies (requires npm) | + +## Your Tasks + +1. **Ask which workflows to set up:** + Use AskUserQuestion to ask which workflows they want: + - PR Review (recommended for all projects, works with any language) + - Documentation Sync (works with any language) + - Node.js Code Quality (Node.js projects only) + - Node.js Dependency Audit (Node.js projects only) + +2. **Check prerequisites:** + - Verify `.github/workflows/` directory exists (create if needed) + - Check if ANTHROPIC_API_KEY secret reminder is needed + +3. **For each selected workflow, create the caller workflow:** + +### PR Review Workflow +```yaml +name: Claude PR Review + +on: + pull_request: + issue_comment: + types: [created] + +permissions: + contents: read + pull-requests: write + issues: read + +jobs: + review: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-pr-review.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +### Documentation Sync Workflow +```yaml +name: Monthly Documentation Sync + +on: + schedule: + - cron: '0 9 1 * *' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + sync: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-docs-sync.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +### Code Quality Workflow +```yaml +name: Weekly Code Quality Review + +on: + schedule: + - cron: '0 8 * * 0' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + quality: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-nodejs-code-quality.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +### Dependency Audit Workflow +```yaml +name: Bi-weekly Dependency Audit + +on: + schedule: + - cron: '0 10 1,15 * *' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + audit: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-nodejs-dependency-audit.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +4. **Remind about secrets:** + Tell the user to add `ANTHROPIC_API_KEY` to their repository secrets: + - Go to Settings → Secrets and variables → Actions + - Click "New repository secret" + - Name: `ANTHROPIC_API_KEY` + - Value: Their Anthropic API key + +5. **Offer customization:** + Ask if they want to customize any inputs (model, timeout, schedule, etc.) + +## Guidelines + +- Create workflows in `.github/workflows/` directory +- Use descriptive filenames like `claude-pr-review.yml` +- Don't overwrite existing workflows without asking +- Remind about the API key secret requirement diff --git a/.claude/skills/github-actions/SKILL.md b/.claude/skills/github-actions/SKILL.md new file mode 100644 index 0000000..eb0a823 --- /dev/null +++ b/.claude/skills/github-actions/SKILL.md @@ -0,0 +1,316 @@ +# GitHub Actions for Claude Code + +Reusable GitHub Actions workflows that integrate Claude Code into your CI/CD pipeline. + +## How It Works + +These are **reusable workflows** (using GitHub's `workflow_call` trigger). You don't copy them—you **call them** from your own repository using a simple caller workflow: + +```yaml +# In YOUR repository: .github/workflows/claude-pr-review.yml +jobs: + review: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-pr-review.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +**Quick setup:** Run `/setup-github-actions` in Claude Code to interactively create caller workflows. + +--- + +## Workflow Compatibility + +| Workflow | Stack | Notes | +|----------|-------|-------| +| [PR Review](#1-pr-review) | **Any** | Language-agnostic, uses git only | +| [Docs Sync](#2-documentation-sync) | **Any** | Language-agnostic, uses git only | +| [Code Quality](#3-code-quality-review) | **Node.js** | Requires npm, configurable lint command | +| [Dependency Audit](#4-dependency-audit) | **Node.js** | Requires npm for dependency management | + +--- + +## Generic Workflows (Any Stack) + +### 1. PR Review (`showcase-pr-review.yml`) + +**Stack: Any** - Uses only git commands, works with any language. + +Automatically reviews pull requests using Claude Code. + +**Triggers on:** +- Pull request opened/synchronized +- Issue comments mentioning `@claude` + +**Usage:** +```yaml +name: Claude PR Review + +on: + pull_request: + issue_comment: + types: [created] + +jobs: + review: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-pr-review.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + with: + model: 'opus' # Optional, auto-updates to latest Opus + timeout_minutes: 30 # Optional +``` + +**Inputs:** +| Input | Type | Default | Description | +|-------|------|---------|-------------| +| `model` | string | `opus` | Claude model alias (`opus`, `sonnet`, `haiku`) | +| `timeout_minutes` | number | `30` | Timeout in minutes | +| `review_prompt` | string | (built-in) | Custom review prompt | + +--- + +### 2. Documentation Sync (`showcase-docs-sync.yml`) + +**Stack: Any** - Uses only git commands, works with any language. + +Periodically checks if documentation is out of sync with code changes. + +**Usage:** +```yaml +name: Monthly Docs Sync + +on: + schedule: + - cron: '0 9 1 * *' # 1st of each month + workflow_dispatch: + +jobs: + sync: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-docs-sync.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + with: + days_back: 30 + code_patterns: '*.py *.go *.rs' # Customize for your stack + docs_paths: 'docs/ README.md' +``` + +**Inputs:** +| Input | Type | Default | Description | +|-------|------|---------|-------------| +| `model` | string | `opus` | Claude model alias | +| `timeout_minutes` | number | `60` | Timeout | +| `days_back` | number | `30` | Days to look back for changes | +| `base_branch` | string | `main` | Base branch for PRs | +| `code_patterns` | string | `*.ts *.tsx *.js *.jsx` | File patterns to check (customize for your stack) | +| `docs_paths` | string | `docs/ README.md` | Documentation paths | +| `custom_prompt` | string | (built-in) | Custom prompt | + +**Stack-specific `code_patterns` examples:** +- **Python**: `*.py` +- **Go**: `*.go` +- **Rust**: `*.rs` +- **Java**: `*.java` +- **Ruby**: `*.rb` + +--- + +## Node.js Workflows + +### 3. Code Quality Review (`showcase-nodejs-code-quality.yml`) + +**Stack: Node.js** - Requires `npm` and a `package.json` with lint scripts. + +Periodically reviews random directories for code quality issues and creates fix PRs. + +**Requirements:** +- Node.js project with `package.json` +- Lint script defined (e.g., `npm run lint`) + +**Usage:** +```yaml +name: Weekly Code Quality + +on: + schedule: + - cron: '0 8 * * 0' # Every Sunday + workflow_dispatch: + +jobs: + quality: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-nodejs-code-quality.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + with: + num_dirs: 3 + source_dir: 'src' + file_extensions: '.ts .tsx' + lint_command: 'npm run lint' +``` + +**Inputs:** +| Input | Type | Default | Description | +|-------|------|---------|-------------| +| `model` | string | `opus` | Claude model alias | +| `timeout_minutes` | number | `45` | Timeout per directory | +| `num_dirs` | number | `3` | Directories to review | +| `source_dir` | string | `src` | Source directory | +| `base_branch` | string | `main` | Base branch for PRs | +| `file_extensions` | string | `.ts .tsx` | Extensions to review | +| `lint_command` | string | `npm run lint` | Lint command | +| `review_checklist_path` | string | `.claude/agents/code-reviewer.md` | Checklist path | +| `custom_prompt` | string | (built-in) | Custom prompt | + +--- + +### 4. Dependency Audit (`showcase-nodejs-dependency-audit.yml`) + +**Stack: Node.js** - Requires `npm` for dependency management. + +Periodically audits dependencies for updates and security vulnerabilities. + +**Requirements:** +- Node.js project with `package.json` and `package-lock.json` +- Test script defined (e.g., `npm test`) + +**Usage:** +```yaml +name: Bi-weekly Dependency Audit + +on: + schedule: + - cron: '0 10 1,15 * *' # 1st and 15th + workflow_dispatch: + +jobs: + audit: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-nodejs-dependency-audit.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + with: + node_version: '20' + lint_command: 'npm run lint' + test_command: 'npm test' +``` + +**Inputs:** +| Input | Type | Default | Description | +|-------|------|---------|-------------| +| `model` | string | `opus` | Claude model alias | +| `timeout_minutes` | number | `45` | Timeout | +| `base_branch` | string | `main` | Base branch for PRs | +| `node_version` | string | `20` | Node.js version | +| `lint_command` | string | `npm run lint` | Lint command | +| `test_command` | string | `npm test` | Test command | +| `custom_prompt` | string | (built-in) | Custom prompt | + +--- + +## Adapting for Other Stacks + +### Python Projects + +The Node.js workflows can be adapted for Python. Here's a guide: + +**Code Quality (Python adaptation):** +```yaml +# Create your own workflow based on showcase-nodejs-code-quality.yml +# Replace npm steps with: +- name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + +- name: Install dependencies + run: pip install -r requirements.txt + +# Change lint_command to: 'ruff check .' or 'flake8' +``` + +**Dependency Audit (Python adaptation):** +```yaml +# Use pip-audit instead of npm audit +- name: Check dependencies + run: | + pip install pip-audit + pip-audit --json > /tmp/audit.json +``` + +### Go Projects + +**Code Quality (Go adaptation):** +```yaml +- name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + +# Change lint_command to: 'golangci-lint run' +# Change file_extensions to: '.go' +``` + +### Rust Projects + +**Code Quality (Rust adaptation):** +```yaml +- name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + +# Change lint_command to: 'cargo clippy -- -D warnings' +# Change file_extensions to: '.rs' +``` + +--- + +## Setup Requirements + +### 1. Add Anthropic API Key + +Add `ANTHROPIC_API_KEY` to your repository secrets: +1. Go to Settings → Secrets and variables → Actions +2. Click "New repository secret" +3. Name: `ANTHROPIC_API_KEY` +4. Value: Your Anthropic API key + +### 2. Configure Permissions + +Ensure your workflow has appropriate permissions: +```yaml +permissions: + contents: write # For creating branches + pull-requests: write # For creating PRs + issues: read # For reading issue comments (PR review) +``` + +### 3. Allow Workflow Calls (for reusable workflows) + +If your repository is private, you may need to allow workflow calls from other repositories in Settings → Actions → General. + +--- + +## Model Aliases + +All workflows use auto-updating model aliases: + +| Alias | Description | +|-------|-------------| +| `opus` | Latest Claude Opus (best for complex analysis) | +| `sonnet` | Latest Claude Sonnet (balanced speed/quality) | +| `haiku` | Latest Claude Haiku (fastest, most economical) | + +--- + +## Quick Start + +Run `/setup-github-actions` to interactively set up these workflows in your repository. + +--- + +## Best Practices + +1. **Start with PR Review** - Works with any stack, immediate value +2. **Use generic workflows first** - PR Review and Docs Sync work everywhere +3. **Customize `code_patterns`** - Match your project's file extensions +4. **Fork for other stacks** - Use Node.js workflows as templates for Python/Go/Rust +5. **Set appropriate timeouts** - Complex codebases may need longer timeouts diff --git a/.github/workflows/pr-claude-code-review.yml b/.github/workflows/pr-claude-code-review.yml index dc724c0..9dfde87 100644 --- a/.github/workflows/pr-claude-code-review.yml +++ b/.github/workflows/pr-claude-code-review.yml @@ -14,6 +14,7 @@ permissions: contents: read pull-requests: write issues: read + id-token: write jobs: review: @@ -62,14 +63,12 @@ jobs: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} model: claude-opus-4-5-20251101 timeout_minutes: 30 - track_progress: true - prompt: | + max_turns: 10 + allowed_tools: "Read,Glob,Grep,Bash(git:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)" + direct_prompt: | Review this Pull Request using the standards in .claude/agents/code-reviewer.md 1. Read .claude/agents/code-reviewer.md for the full checklist 2. Run `git diff origin/${{ steps.pr-info.outputs.base_ref }}...HEAD` to see changes 3. Apply the review checklist to modified files 4. Provide feedback organized by severity (Critical, Warning, Suggestion) - claude_args: | - --max-turns 10 - --allowedTools "Read,Glob,Grep,Bash(git:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)" diff --git a/.github/workflows/scheduled-claude-code-dependency-audit.yml b/.github/workflows/scheduled-claude-code-dependency-audit.yml index 6142266..006453d 100644 --- a/.github/workflows/scheduled-claude-code-dependency-audit.yml +++ b/.github/workflows/scheduled-claude-code-dependency-audit.yml @@ -13,6 +13,7 @@ concurrency: permissions: contents: write pull-requests: write + id-token: write jobs: dependency-audit: @@ -70,8 +71,9 @@ jobs: timeout_minutes: 45 base_branch: main branch_prefix: claude/deps-update- - track_progress: true - prompt: | + max_turns: 40 + allowed_tools: "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*),Bash(npm:*)" + direct_prompt: | # Dependency Audit You are running a scheduled dependency audit. @@ -105,9 +107,6 @@ jobs: - If tests fail after an update, revert that update - Group related updates together - If NO updates are possible, report that and don't create a PR - claude_args: | - --max-turns 40 - --allowedTools "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*),Bash(npm:*)" - name: Report no updates needed if: steps.check-outdated.outputs.has_outdated == 'false' && steps.security-audit.outputs.vulnerabilities == '0' diff --git a/.github/workflows/scheduled-claude-code-docs-sync.yml b/.github/workflows/scheduled-claude-code-docs-sync.yml index a75255b..5f5b67d 100644 --- a/.github/workflows/scheduled-claude-code-docs-sync.yml +++ b/.github/workflows/scheduled-claude-code-docs-sync.yml @@ -18,6 +18,7 @@ concurrency: permissions: contents: write pull-requests: write + id-token: write jobs: docs-sync: @@ -64,8 +65,9 @@ jobs: timeout_minutes: 60 base_branch: main branch_prefix: claude/docs-sync- - track_progress: true - prompt: | + max_turns: 30 + allowed_tools: "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*)" + direct_prompt: | # Monthly Documentation Sync You are running a scheduled documentation sync. Code has changed since ${{ steps.check-changes.outputs.since_date }}. @@ -105,9 +107,6 @@ jobs: - DO NOT add changelog-style entries - ONLY update docs when they are incorrect or misleading - If no problems are found, report that and DO NOT create a PR - claude_args: | - --max-turns 30 - --allowedTools "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*)" - name: Report no changes if: steps.check-changes.outputs.has_changes == 'false' diff --git a/.github/workflows/scheduled-claude-code-quality.yml b/.github/workflows/scheduled-claude-code-quality.yml index 1afd88a..ce28bd4 100644 --- a/.github/workflows/scheduled-claude-code-quality.yml +++ b/.github/workflows/scheduled-claude-code-quality.yml @@ -18,6 +18,7 @@ concurrency: permissions: contents: write pull-requests: write + id-token: write jobs: select-directories: @@ -90,8 +91,9 @@ jobs: timeout_minutes: 45 base_branch: main branch_prefix: claude/code-quality- - track_progress: true - prompt: | + max_turns: 35 + allowed_tools: "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*),Bash(npm run lint*)" + direct_prompt: | # Weekly Code Quality Review You are performing a scheduled code quality review of a specific directory. @@ -136,9 +138,6 @@ jobs: - Fix issues that are clear improvements - Don't refactor working code just for style - If no issues found, report that and skip PR creation - claude_args: | - --max-turns 35 - --allowedTools "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*),Bash(npm run lint*)" report-completion: needs: [select-directories, review-directory] diff --git a/.github/workflows/showcase-docs-sync.yml b/.github/workflows/showcase-docs-sync.yml new file mode 100644 index 0000000..0690633 --- /dev/null +++ b/.github/workflows/showcase-docs-sync.yml @@ -0,0 +1,152 @@ +name: Showcase - Claude Documentation Sync + +on: + workflow_call: + inputs: + model: + description: 'Claude model to use' + required: false + type: string + default: 'opus' + timeout_minutes: + description: 'Timeout in minutes' + required: false + type: number + default: 60 + days_back: + description: 'Number of days to look back for changes' + required: false + type: number + default: 30 + base_branch: + description: 'Base branch for PRs' + required: false + type: string + default: 'main' + code_patterns: + description: 'File patterns to check for changes (space-separated globs)' + required: false + type: string + default: '*.ts *.tsx *.js *.jsx' + docs_paths: + description: 'Documentation paths to update (space-separated)' + required: false + type: string + default: 'docs/ README.md' + custom_prompt: + description: 'Custom prompt (optional, uses default if not provided)' + required: false + type: string + default: '' + secrets: + ANTHROPIC_API_KEY: + required: true + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + docs-sync: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check for code changes in period + id: check-changes + run: | + DAYS_BACK="${{ inputs.days_back }}" + SINCE_DATE=$(date -d "-${DAYS_BACK} days" +%Y-%m-%d) + + echo "Checking for changes since: $SINCE_DATE" + + # Build glob patterns for git log + PATTERNS="${{ inputs.code_patterns }}" + GIT_ARGS="" + for pattern in $PATTERNS; do + GIT_ARGS="$GIT_ARGS $pattern" + done + + # Get changed code files (excluding tests) + CHANGED_FILES=$(git log --since="$SINCE_DATE" --name-only --pretty=format: -- \ + $GIT_ARGS \ + ':!*.test.*' ':!*.spec.*' ':!*.stories.*' \ + | sort -u | grep -v '^$' | head -100) + + if [ -z "$CHANGED_FILES" ]; then + echo "has_changes=false" >> $GITHUB_OUTPUT + echo "No code changes found in the last $DAYS_BACK days" + else + echo "has_changes=true" >> $GITHUB_OUTPUT + echo "changed_files<> $GITHUB_OUTPUT + echo "$CHANGED_FILES" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + echo "Found $(echo "$CHANGED_FILES" | wc -l) changed files" + fi + + echo "since_date=$SINCE_DATE" >> $GITHUB_OUTPUT + + - name: Claude Documentation Sync + if: steps.check-changes.outputs.has_changes == 'true' + uses: anthropics/claude-code-action@beta + env: + SINCE_DATE: ${{ steps.check-changes.outputs.since_date }} + CHANGED_FILES: ${{ steps.check-changes.outputs.changed_files }} + DOCS_PATHS: ${{ inputs.docs_paths }} + BASE_BRANCH: ${{ inputs.base_branch }} + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + model: ${{ inputs.model }} + timeout_minutes: ${{ inputs.timeout_minutes }} + base_branch: ${{ inputs.base_branch }} + branch_prefix: claude/docs-sync- + max_turns: 30 + allowed_tools: "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*)" + direct_prompt: ${{ inputs.custom_prompt != '' && inputs.custom_prompt || ' + # Documentation Sync + + You are running a documentation sync. Check the environment variables for context: + - SINCE_DATE: Date to check changes from + - CHANGED_FILES: List of modified code files + - DOCS_PATHS: Documentation paths to update + - BASE_BRANCH: Branch to create PRs against + + ## Your Tasks + + 1. **Read the changed files list** from the CHANGED_FILES environment variable + + 2. **Analyze Changes**: Review the changed files to understand what functionality was added, modified, or removed. + + 3. **Find Related Documentation**: Search for documentation in the paths specified by DOCS_PATHS. + + 4. **Check for Actual Problems**: For each code change, determine if existing docs are now WRONG: + - Do code examples still work? + - Are API signatures/types now incorrect? + - Are prop interfaces outdated? + + 5. **Fix Only What is Broken**: If you find documentation that is actually wrong: + - Fix incorrect code examples + - Update wrong API signatures and types + - Add docs ONLY for significant new features that have zero documentation + + 6. **Create a PR**: If you made any changes: + - Create a new branch from the BASE_BRANCH + - Commit all documentation updates + - Create a PR with a summary of what was fixed + + ## CRITICAL Guidelines + - Documentation is a LIVING DOCUMENT - only fix things that are actually WRONG + - DO NOT add changelog-style entries + - ONLY update docs when they are incorrect or misleading + - If no problems are found, report that and DO NOT create a PR + ' }} + + - name: Report no changes + if: steps.check-changes.outputs.has_changes == 'false' + run: | + echo "No code changes found in the last ${{ inputs.days_back }} days." + echo "Skipping documentation sync." diff --git a/.github/workflows/showcase-nodejs-code-quality.yml b/.github/workflows/showcase-nodejs-code-quality.yml new file mode 100644 index 0000000..e5ff2b8 --- /dev/null +++ b/.github/workflows/showcase-nodejs-code-quality.yml @@ -0,0 +1,209 @@ +name: Showcase - Node.js Code Quality Review + +on: + workflow_call: + inputs: + model: + description: 'Claude model to use' + required: false + type: string + default: 'opus' + timeout_minutes: + description: 'Timeout in minutes per directory' + required: false + type: number + default: 45 + num_dirs: + description: 'Number of random directories to review' + required: false + type: number + default: 3 + source_dir: + description: 'Source directory to search for code' + required: false + type: string + default: 'src' + base_branch: + description: 'Base branch for PRs' + required: false + type: string + default: 'main' + file_extensions: + description: 'File extensions to review (space-separated)' + required: false + type: string + default: '.ts .tsx' + lint_command: + description: 'Lint command to verify changes' + required: false + type: string + default: 'npm run lint' + review_checklist_path: + description: 'Path to code review checklist (optional)' + required: false + type: string + default: '.claude/agents/code-reviewer.md' + custom_prompt: + description: 'Custom review prompt (optional)' + required: false + type: string + default: '' + secrets: + ANTHROPIC_API_KEY: + required: true + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + select-directories: + runs-on: ubuntu-latest + outputs: + directories: ${{ steps.select.outputs.directories }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Select random directories + id: select + run: | + NUM_DIRS="${{ inputs.num_dirs }}" + SOURCE_DIR="${{ inputs.source_dir }}" + EXTENSIONS="${{ inputs.file_extensions }}" + + # Find directories with matching files (excluding tests) + # Build ls pattern by converting ".ts .tsx" to "*.ts *.tsx" + LS_PATTERNS="" + for ext in $EXTENSIONS; do + LS_PATTERNS="$LS_PATTERNS *$ext" + done + + # Find directories containing files with any of the extensions + DIRS=$(find "$SOURCE_DIR" -type d 2>/dev/null | while read -r dir; do + # Check if directory has matching files (excluding test files) + for ext in $EXTENSIONS; do + if ls "$dir"/*"$ext" 2>/dev/null | grep -qvE '\.(test|spec|stories)\.'; then + echo "$dir" + break + fi + done + done | sort -u | shuf -n "$NUM_DIRS") + + if [ -z "$DIRS" ]; then + echo "No suitable directories found" + echo "directories=[]" >> $GITHUB_OUTPUT + exit 0 + fi + + # Convert to JSON array + JSON_DIRS=$(echo "$DIRS" | jq -R -s -c 'split("\n") | map(select(length > 0))') + echo "directories=$JSON_DIRS" >> $GITHUB_OUTPUT + echo "Selected directories:" + echo "$DIRS" + + review-directory: + needs: select-directories + if: needs.select-directories.outputs.directories != '[]' + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 3 + matrix: + directory: ${{ fromJson(needs.select-directories.outputs.directories) }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Generate branch name + id: branch + run: | + DIR_SLUG=$(echo "${{ matrix.directory }}" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//' | cut -c1-30) + BRANCH_NAME="claude/code-quality-${DIR_SLUG}-$(date +%Y%m%d)" + echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT + + - name: Claude Code Quality Review + uses: anthropics/claude-code-action@beta + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + model: ${{ inputs.model }} + timeout_minutes: ${{ inputs.timeout_minutes }} + base_branch: ${{ inputs.base_branch }} + branch_prefix: claude/code-quality- + max_turns: 35 + allowed_tools: "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*),Bash(${{ inputs.lint_command }}*)" + direct_prompt: | + ${{ inputs.custom_prompt != '' && inputs.custom_prompt || format(' + # Code Quality Review + + You are performing a code quality review of a specific directory. + + ## Target Directory + **Review: `{0}`** + + ## Your Tasks + + 1. **Read the code review standards**: If `{1}` exists, read it for the full checklist + + 2. **Analyze all files in the directory**: + - List all code files (excluding .test., .spec., .stories.) + - Read each file thoroughly + - Apply the review checklist + + 3. **Focus on finding and FIXING issues**: + - TypeScript strict mode violations (any types, missing types) + - React anti-patterns (bad useEffect, unnecessary memoization) + - Code style issues (mutations, deep nesting, poor naming) + - Missing error handling + - Security issues + - Performance problems + + 4. **Make the fixes yourself**: + - Do not just report issues - FIX THEM + - Use Edit tool to update files + - Ensure fixes do not break anything + + 5. **Run verification**: + - Run `{2}` - verify no lint errors introduced + - If errors occur, fix them or revert changes + + 6. **Create PR if fixes were made**: + - Create a branch from {3} + - Commit all fixes with descriptive message + - PR title: "fix({0}): code quality improvements" + - PR body should list fixes applied + + ## Guidelines + - Be thorough but focused on this directory only + - Fix issues that are clear improvements + - Do not refactor working code just for style + - If no issues found, report that and skip PR creation + ', matrix.directory, inputs.review_checklist_path, inputs.lint_command, inputs.base_branch) }} + + report-completion: + needs: [select-directories, review-directory] + if: always() + runs-on: ubuntu-latest + steps: + - name: Summary + run: | + echo "## Code Quality Review Complete" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Reviewed directories:" >> $GITHUB_STEP_SUMMARY + echo '${{ needs.select-directories.outputs.directories }}' | jq -r '.[]' | while read dir; do + echo "- \`$dir\`" >> $GITHUB_STEP_SUMMARY + done + echo "" >> $GITHUB_STEP_SUMMARY + echo "Check for any PRs created by this workflow." >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/showcase-nodejs-dependency-audit.yml b/.github/workflows/showcase-nodejs-dependency-audit.yml new file mode 100644 index 0000000..03535c3 --- /dev/null +++ b/.github/workflows/showcase-nodejs-dependency-audit.yml @@ -0,0 +1,149 @@ +name: Showcase - Node.js Dependency Audit + +on: + workflow_call: + inputs: + model: + description: 'Claude model to use' + required: false + type: string + default: 'opus' + timeout_minutes: + description: 'Timeout in minutes' + required: false + type: number + default: 45 + base_branch: + description: 'Base branch for PRs' + required: false + type: string + default: 'main' + node_version: + description: 'Node.js version to use' + required: false + type: string + default: '20' + lint_command: + description: 'Lint command to verify changes' + required: false + type: string + default: 'npm run lint' + test_command: + description: 'Test command to verify changes' + required: false + type: string + default: 'npm test' + custom_prompt: + description: 'Custom audit prompt (optional)' + required: false + type: string + default: '' + secrets: + ANTHROPIC_API_KEY: + required: true + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + dependency-audit: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Check for outdated dependencies + id: check-outdated + run: | + echo "Checking for outdated dependencies..." + npm outdated --json > /tmp/outdated.json 2>/dev/null || true + + if [ ! -s /tmp/outdated.json ] || [ "$(cat /tmp/outdated.json)" = "{}" ]; then + echo "has_outdated=false" >> $GITHUB_OUTPUT + echo "No outdated dependencies found" + else + echo "has_outdated=true" >> $GITHUB_OUTPUT + echo "Found outdated dependencies" + cat /tmp/outdated.json + fi + + - name: Run security audit + id: security-audit + run: | + echo "Running security audit..." + npm audit --json > /tmp/audit.json 2>/dev/null || true + + if [ -s /tmp/audit.json ]; then + VULNERABILITIES=$(cat /tmp/audit.json | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('metadata',{}).get('vulnerabilities',{}).get('total',0))" 2>/dev/null || echo "0") + echo "vulnerabilities=$VULNERABILITIES" >> $GITHUB_OUTPUT + echo "Found $VULNERABILITIES vulnerabilities" + else + echo "vulnerabilities=0" >> $GITHUB_OUTPUT + fi + + - name: Claude Dependency Analysis & Update + if: steps.check-outdated.outputs.has_outdated == 'true' || steps.security-audit.outputs.vulnerabilities != '0' + uses: anthropics/claude-code-action@beta + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + model: ${{ inputs.model }} + timeout_minutes: ${{ inputs.timeout_minutes }} + base_branch: ${{ inputs.base_branch }} + branch_prefix: claude/deps-update- + max_turns: 40 + allowed_tools: "Read,Write,Edit,Glob,Grep,Bash(git:*),Bash(gh:*),Bash(npm:*)" + direct_prompt: | + ${{ inputs.custom_prompt != '' && inputs.custom_prompt || format(' + # Dependency Audit + + You are running a dependency audit. + + ## Your Tasks + + 1. **Analyze outdated packages**: Run `npm outdated` and review results + + 2. **Analyze security vulnerabilities**: Run `npm audit` and review results + + 3. **Update packages safely**: + - Use `npm update package-name` for minor/patch updates + - For major versions, use `npm install package-name@latest` only if safe + - Run `npm audit fix` for security fixes + + 4. **Verify updates**: + - Run `{0}` to check for lint issues + - Run `{1}` to verify tests pass + - If anything fails, revert that specific update + + 5. **Create PR** if any updates were made: + - Create branch from {2} + - Commit package.json and package-lock.json changes + - PR title: "chore(deps): update dependencies" + - PR body should list: + - Each package updated with old to new version + - Security vulnerabilities fixed (if any) + + ## Guidelines + - Be CONSERVATIVE - when in doubt, do not update + - If tests fail after an update, revert that update + - Group related updates together + - If NO updates are possible, report that and do not create a PR + ', inputs.lint_command, inputs.test_command, inputs.base_branch) }} + + - name: Report no updates needed + if: steps.check-outdated.outputs.has_outdated == 'false' && steps.security-audit.outputs.vulnerabilities == '0' + run: | + echo "All dependencies are up to date and no security vulnerabilities found." + echo "No action needed." diff --git a/.github/workflows/showcase-pr-review.yml b/.github/workflows/showcase-pr-review.yml new file mode 100644 index 0000000..6532cfd --- /dev/null +++ b/.github/workflows/showcase-pr-review.yml @@ -0,0 +1,94 @@ +name: Showcase - Claude PR Review + +on: + workflow_call: + inputs: + model: + description: 'Claude model to use' + required: false + type: string + default: 'opus' + timeout_minutes: + description: 'Timeout in minutes' + required: false + type: number + default: 30 + review_prompt: + description: 'Custom review prompt (optional, uses default if not provided)' + required: false + type: string + default: '' + secrets: + ANTHROPIC_API_KEY: + required: true + +permissions: + contents: read + pull-requests: write + issues: read + id-token: write + +jobs: + review: + # Run on PR events, or on issue comments that mention @claude + if: | + github.event_name == 'pull_request' || + (github.event_name == 'issue_comment' && + github.event.issue.pull_request && + contains(github.event.comment.body, '@claude')) + runs-on: ubuntu-latest + steps: + - name: Checkout repository (PR event) + if: github.event_name == 'pull_request' + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: Checkout repository (issue_comment event) + if: github.event_name == 'issue_comment' + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout PR branch (issue_comment event) + if: github.event_name == 'issue_comment' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh pr checkout ${{ github.event.issue.number }} + + - name: Get PR base branch + id: pr-info + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "base_ref=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT + else + BASE_REF=$(gh pr view ${{ github.event.issue.number }} --json baseRefName -q '.baseRefName') + echo "base_ref=$BASE_REF" >> $GITHUB_OUTPUT + fi + + - name: Claude Code Review + uses: anthropics/claude-code-action@beta + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + model: ${{ inputs.model }} + timeout_minutes: ${{ inputs.timeout_minutes }} + max_turns: 10 + allowed_tools: "Read,Glob,Grep,Bash(git:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)" + direct_prompt: | + ${{ inputs.review_prompt != '' && inputs.review_prompt || format(' + Review this Pull Request thoroughly. + + 1. Run `git diff origin/{0}...HEAD` to see all changes + 2. Analyze the code for: + - Correctness and potential bugs + - TypeScript type safety (no `any` types) + - Error handling + - Security issues + - Performance concerns + - Code style and readability + 3. If a .claude/agents/code-reviewer.md exists, use it as the review checklist + 4. Provide feedback organized by severity (Critical, Warning, Suggestion) + ', steps.pr-info.outputs.base_ref) }} diff --git a/README.md b/README.md index 264c1d5..8ac0092 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ This repository is also a **Claude Code plugin marketplace**. You can install in | `docs-sync` | Command | Documentation synchronization | | `skill-activation` | Hook | Intelligent skill suggestions | | `plugin-marketplace` | Skill | Create marketplaces using symlinks | +| `github-actions` | Bundle | Showcase Claude Code workflows + `/setup-github-actions` | ### Architecture @@ -842,7 +843,47 @@ Recent commits: !`git log --oneline -5` Automate code review, quality checks, and maintenance with Claude Code. -**📄 Examples:** +### Showcase Workflows (Reusable) + +This repository provides **reusable GitHub Actions workflows** that you can call from your own repositories using GitHub's `workflow_call` feature. No need to copy workflow files—just reference them directly. + +**Quick Setup:** +```yaml +# In your repository's .github/workflows/claude-pr-review.yml +name: Claude PR Review + +on: + pull_request: + issue_comment: + types: [created] + +jobs: + review: + uses: aviadr1/claude-code-showcase/.github/workflows/showcase-pr-review.yml@main + secrets: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +``` + +**Available Showcase Workflows:** + +| Workflow | Stack | Purpose | Key Inputs | +|----------|-------|---------|------------| +| [`showcase-pr-review.yml`](.github/workflows/showcase-pr-review.yml) | **Any** | Automatic PR review | `model`, `timeout_minutes`, `review_prompt` | +| [`showcase-docs-sync.yml`](.github/workflows/showcase-docs-sync.yml) | **Any** | Keep docs in sync with code | `days_back`, `docs_paths`, `code_patterns` | +| [`showcase-nodejs-code-quality.yml`](.github/workflows/showcase-nodejs-code-quality.yml) | **Node.js** | Periodic code quality audits | `num_dirs`, `source_dir`, `lint_command` | +| [`showcase-nodejs-dependency-audit.yml`](.github/workflows/showcase-nodejs-dependency-audit.yml) | **Node.js** | Dependency updates & security | `node_version`, `lint_command`, `test_command` | + +**📄 Full documentation:** [github-actions skill](.claude/skills/github-actions/SKILL.md) + +**🛠️ Interactive setup:** Run `/setup-github-actions` in Claude Code + +--- + +### Local Workflows (Examples) + +These are **caller workflows** used by this repository—examples of how to call the reusable showcase workflows above: + +**📄 Example caller workflows:** - [pr-claude-code-review.yml](.github/workflows/pr-claude-code-review.yml) - Auto PR review - [scheduled-claude-code-docs-sync.yml](.github/workflows/scheduled-claude-code-docs-sync.yml) - Monthly docs sync - [scheduled-claude-code-quality.yml](.github/workflows/scheduled-claude-code-quality.yml) - Weekly quality review diff --git a/plugins/github-actions/.claude-plugin/plugin.json b/plugins/github-actions/.claude-plugin/plugin.json new file mode 100644 index 0000000..63db402 --- /dev/null +++ b/plugins/github-actions/.claude-plugin/plugin.json @@ -0,0 +1,8 @@ +{ + "name": "github-actions", + "version": "1.0.0", + "description": "Showcase GitHub Actions workflows for Claude Code CI/CD automation. Includes PR review, docs sync, code quality, and dependency audit workflows.", + "keywords": ["github-actions", "ci-cd", "workflows", "automation", "pr-review", "code-quality"], + "skills": "./skills/", + "commands": "./commands/" +} diff --git a/plugins/github-actions/commands/setup-github-actions.md b/plugins/github-actions/commands/setup-github-actions.md new file mode 120000 index 0000000..85984fe --- /dev/null +++ b/plugins/github-actions/commands/setup-github-actions.md @@ -0,0 +1 @@ +../../../.claude/commands/setup-github-actions.md \ No newline at end of file diff --git a/plugins/github-actions/skills/github-actions b/plugins/github-actions/skills/github-actions new file mode 120000 index 0000000..ad3a1d7 --- /dev/null +++ b/plugins/github-actions/skills/github-actions @@ -0,0 +1 @@ +../../../.claude/skills/github-actions \ No newline at end of file