From fb70c200671786a31dedbec6f6ed8c4d96b6e4b0 Mon Sep 17 00:00:00 2001 From: Brian Madison Date: Sun, 31 Aug 2025 20:30:52 -0500 Subject: [PATCH] feat: add PR validation workflow and contribution checks --- .github/FORK_GUIDE.md | 4 +- .github/workflows/pr-validation.yaml | 55 +++++++++++++++++++ CONTRIBUTING.md | 41 ++++++++++++++ bmad-core/workflows/brownfield-fullstack.yaml | 4 +- bmad-core/workflows/brownfield-service.yaml | 4 +- bmad-core/workflows/brownfield-ui.yaml | 4 +- bmad-core/workflows/greenfield-fullstack.yaml | 8 +-- bmad-core/workflows/greenfield-service.yaml | 4 +- bmad-core/workflows/greenfield-ui.yaml | 6 +- package.json | 3 + tools/setup-hooks.sh | 37 +++++++++++++ 11 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/pr-validation.yaml create mode 100755 tools/setup-hooks.sh diff --git a/.github/FORK_GUIDE.md b/.github/FORK_GUIDE.md index 073d9c29..d7ed2bd4 100644 --- a/.github/FORK_GUIDE.md +++ b/.github/FORK_GUIDE.md @@ -60,6 +60,7 @@ npm run build ### Pull Request CI When you open a Pull Request to the main repository: + - All CI/CD workflows automatically run - You get full validation of your changes - No configuration needed @@ -67,6 +68,7 @@ When you open a Pull Request to the main repository: ### GitHub Codespaces Use GitHub Codespaces for a full development environment: + - All tools pre-configured - Same environment as CI/CD - No local setup required @@ -101,4 +103,4 @@ Use GitHub Codespaces for a full development environment: --- -> 💡 **Pro Tip**: This fork-friendly approach is particularly valuable for projects using AI/LLM tools that create many experimental commits, as it prevents unnecessary CI runs while maintaining code quality standards. \ No newline at end of file +> 💡 **Pro Tip**: This fork-friendly approach is particularly valuable for projects using AI/LLM tools that create many experimental commits, as it prevents unnecessary CI runs while maintaining code quality standards. diff --git a/.github/workflows/pr-validation.yaml b/.github/workflows/pr-validation.yaml new file mode 100644 index 00000000..5bacb4f0 --- /dev/null +++ b/.github/workflows/pr-validation.yaml @@ -0,0 +1,55 @@ +name: PR Validation + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened] + +jobs: + validate: + runs-on: ubuntu-latest + if: github.event.repository.fork != true || vars.ENABLE_CI_IN_FORK == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Run validation + run: npm run validate + + - name: Check formatting + run: npm run format:check + + - name: Run linter + run: npm run lint + + - name: Run tests (if available) + run: npm test --if-present + + - name: Comment on PR if checks fail + if: failure() + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `❌ **PR Validation Failed** + + This PR has validation errors that must be fixed before merging: + - Run \`npm run validate\` to check agent/team configs + - Run \`npm run format:check\` to check formatting (fix with \`npm run format\`) + - Run \`npm run lint\` to check linting issues (fix with \`npm run lint:fix\`) + + Please fix these issues and push the changes.` + }) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe988154..2ad976dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,6 +17,47 @@ Also note, we use the discussions feature in GitHub to have a community to discu By participating in this project, you agree to abide by our Code of Conduct. Please read it before participating. +## Before Submitting a PR + +**IMPORTANT**: All PRs must pass validation checks before they can be merged. + +### Required Checks + +Before submitting your PR, run these commands locally: + +```bash +# Run all validation checks +npm run pre-release + +# Or run them individually: +npm run validate # Validate agent/team configs +npm run format:check # Check code formatting +npm run lint # Check for linting issues +``` + +### Fixing Issues + +If any checks fail, use these commands to fix them: + +```bash +# Fix all issues automatically +npm run fix + +# Or fix individually: +npm run format # Fix formatting issues +npm run lint:fix # Fix linting issues +``` + +### Setup Git Hooks (Optional but Recommended) + +To catch issues before committing: + +```bash +# Run this once after cloning +chmod +x tools/setup-hooks.sh +./tools/setup-hooks.sh +``` + ## How to Contribute ### Reporting Bugs diff --git a/bmad-core/workflows/brownfield-fullstack.yaml b/bmad-core/workflows/brownfield-fullstack.yaml index 6a7d7d87..a696b0a8 100644 --- a/bmad-core/workflows/brownfield-fullstack.yaml +++ b/bmad-core/workflows/brownfield-fullstack.yaml @@ -160,7 +160,7 @@ workflow: - Dev Agent (New Chat): Address remaining items - Return to QA for final approval - - repeat_development_cycle: + - step: repeat_development_cycle action: continue_for_all_stories notes: | Repeat story cycle (SM → Dev → QA) for all epic stories @@ -177,7 +177,7 @@ workflow: - Validate epic was completed correctly - Document learnings and improvements - - workflow_end: + - step: workflow_end action: project_complete notes: | All stories implemented and reviewed! diff --git a/bmad-core/workflows/brownfield-service.yaml b/bmad-core/workflows/brownfield-service.yaml index e2af23de..6c8148cd 100644 --- a/bmad-core/workflows/brownfield-service.yaml +++ b/bmad-core/workflows/brownfield-service.yaml @@ -106,7 +106,7 @@ workflow: - Dev Agent (New Chat): Address remaining items - Return to QA for final approval - - repeat_development_cycle: + - step: repeat_development_cycle action: continue_for_all_stories notes: | Repeat story cycle (SM → Dev → QA) for all epic stories @@ -123,7 +123,7 @@ workflow: - Validate epic was completed correctly - Document learnings and improvements - - workflow_end: + - step: workflow_end action: project_complete notes: | All stories implemented and reviewed! diff --git a/bmad-core/workflows/brownfield-ui.yaml b/bmad-core/workflows/brownfield-ui.yaml index 4a9ffd76..9e249f4e 100644 --- a/bmad-core/workflows/brownfield-ui.yaml +++ b/bmad-core/workflows/brownfield-ui.yaml @@ -113,7 +113,7 @@ workflow: - Dev Agent (New Chat): Address remaining items - Return to QA for final approval - - repeat_development_cycle: + - step: repeat_development_cycle action: continue_for_all_stories notes: | Repeat story cycle (SM → Dev → QA) for all epic stories @@ -130,7 +130,7 @@ workflow: - Validate epic was completed correctly - Document learnings and improvements - - workflow_end: + - step: workflow_end action: project_complete notes: | All stories implemented and reviewed! diff --git a/bmad-core/workflows/greenfield-fullstack.yaml b/bmad-core/workflows/greenfield-fullstack.yaml index 1425d9f2..1fa8a6a8 100644 --- a/bmad-core/workflows/greenfield-fullstack.yaml +++ b/bmad-core/workflows/greenfield-fullstack.yaml @@ -65,12 +65,12 @@ workflow: condition: po_checklist_issues notes: "If PO finds issues, return to relevant agent to fix and re-export updated documents to docs/ folder." - - project_setup_guidance: + - step: project_setup_guidance action: guide_project_structure condition: user_has_generated_ui notes: "If user generated UI with v0/Lovable: For polyrepo setup, place downloaded project in separate frontend repo alongside backend repo. For monorepo, place in apps/web or packages/frontend directory. Review architecture document for specific guidance." - - development_order_guidance: + - step: development_order_guidance action: guide_development_sequence notes: "Based on PRD stories: If stories are frontend-heavy, start with frontend project/directory first. If backend-heavy or API-first, start with backend. For tightly coupled features, follow story sequence in monorepo setup. Reference sharded PRD epics for development order." @@ -138,7 +138,7 @@ workflow: - Dev Agent (New Chat): Address remaining items - Return to QA for final approval - - repeat_development_cycle: + - step: repeat_development_cycle action: continue_for_all_stories notes: | Repeat story cycle (SM → Dev → QA) for all epic stories @@ -155,7 +155,7 @@ workflow: - Validate epic was completed correctly - Document learnings and improvements - - workflow_end: + - step: workflow_end action: project_complete notes: | All stories implemented and reviewed! diff --git a/bmad-core/workflows/greenfield-service.yaml b/bmad-core/workflows/greenfield-service.yaml index c30c0132..c8339678 100644 --- a/bmad-core/workflows/greenfield-service.yaml +++ b/bmad-core/workflows/greenfield-service.yaml @@ -114,7 +114,7 @@ workflow: - Dev Agent (New Chat): Address remaining items - Return to QA for final approval - - repeat_development_cycle: + - step: repeat_development_cycle action: continue_for_all_stories notes: | Repeat story cycle (SM → Dev → QA) for all epic stories @@ -131,7 +131,7 @@ workflow: - Validate epic was completed correctly - Document learnings and improvements - - workflow_end: + - step: workflow_end action: project_complete notes: | All stories implemented and reviewed! diff --git a/bmad-core/workflows/greenfield-ui.yaml b/bmad-core/workflows/greenfield-ui.yaml index 2b3e5f46..14678458 100644 --- a/bmad-core/workflows/greenfield-ui.yaml +++ b/bmad-core/workflows/greenfield-ui.yaml @@ -64,7 +64,7 @@ workflow: condition: po_checklist_issues notes: "If PO finds issues, return to relevant agent to fix and re-export updated documents to docs/ folder." - - project_setup_guidance: + - step: project_setup_guidance action: guide_project_structure condition: user_has_generated_ui notes: "If user generated UI with v0/Lovable: For polyrepo setup, place downloaded project in separate frontend repo. For monorepo, place in apps/web or frontend/ directory. Review architecture document for specific guidance." @@ -133,7 +133,7 @@ workflow: - Dev Agent (New Chat): Address remaining items - Return to QA for final approval - - repeat_development_cycle: + - step: repeat_development_cycle action: continue_for_all_stories notes: | Repeat story cycle (SM → Dev → QA) for all epic stories @@ -150,7 +150,7 @@ workflow: - Validate epic was completed correctly - Document learnings and improvements - - workflow_end: + - step: workflow_end action: project_complete notes: | All stories implemented and reviewed! diff --git a/package.json b/package.json index 3bbd7627..8033b6a8 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "build": "node tools/cli.js build", "build:agents": "node tools/cli.js build --agents-only", "build:teams": "node tools/cli.js build --teams-only", + "fix": "npm run format && npm run lint:fix", "flatten": "node tools/flattener/main.js", "format": "prettier --write \"**/*.{js,cjs,mjs,json,md,yaml}\"", "format:check": "prettier --check \"**/*.{js,cjs,mjs,json,md,yaml}\"", @@ -34,12 +35,14 @@ "lint": "eslint . --ext .js,.cjs,.mjs,.yaml --max-warnings=0", "lint:fix": "eslint . --ext .js,.cjs,.mjs,.yaml --fix", "list:agents": "node tools/cli.js list:agents", + "pre-release": "npm run validate && npm run format:check && npm run lint", "prepare": "husky", "preview:release": "node tools/preview-release-notes.js", "release:major": "gh workflow run \"Manual Release\" -f version_bump=major", "release:minor": "gh workflow run \"Manual Release\" -f version_bump=minor", "release:patch": "gh workflow run \"Manual Release\" -f version_bump=patch", "release:watch": "gh run watch", + "setup:hooks": "chmod +x tools/setup-hooks.sh && ./tools/setup-hooks.sh", "validate": "node tools/cli.js validate", "version:all": "node tools/bump-all-versions.js", "version:all:major": "node tools/bump-all-versions.js major", diff --git a/tools/setup-hooks.sh b/tools/setup-hooks.sh new file mode 100755 index 00000000..f8838508 --- /dev/null +++ b/tools/setup-hooks.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Setup script for git hooks +echo "Setting up git hooks..." + +# Install husky +npm install --save-dev husky + +# Initialize husky +npx husky init + +# Create pre-commit hook +cat > .husky/pre-commit << 'EOF' +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +# Run validation checks before commit +echo "Running pre-commit checks..." + +npm run validate +npm run format:check +npm run lint + +if [ $? -ne 0 ]; then + echo "❌ Pre-commit checks failed. Please fix the issues before committing." + echo " Run 'npm run format' to fix formatting issues" + echo " Run 'npm run lint:fix' to fix some lint issues" + exit 1 +fi + +echo "✅ Pre-commit checks passed!" +EOF + +chmod +x .husky/pre-commit + +echo "✅ Git hooks setup complete!" +echo "Now commits will be validated before they're created." \ No newline at end of file