Co-authored-by: daffy0208 <207889146+daffy0208@users.noreply.github.com>
13 KiB
CI/CD Setup Guide
Complete guide for the automated CI/CD pipeline.
🎯 Overview
ai-dev-standards uses GitHub Actions for fully automated:
- ✅ Testing (unit + integration)
- ✅ Linting & formatting checks
- ✅ Type checking
- ✅ Code coverage reporting
- ✅ Security audits
- ✅ Automated releases
- ✅ Changelog generation
🚀 Workflows
1. CI Workflow (.github/workflows/ci.yml)
Triggers:
- Push to
mainordevelop - Pull requests to
mainordevelop
Jobs:
-
Test (Node 18.x, 20.x)
- Runs all tests
- Generates coverage report
- Uploads to Codecov
-
Lint
- Runs ESLint
- Checks code formatting (Prettier)
-
Type Check
- Runs TypeScript compiler
- Validates all type definitions
-
Build
- Builds CLI package
- Verifies build succeeds
-
Security
- Runs
npm audit - Checks for known vulnerabilities
- Runs
-
Registry Validation
- Verifies all skills are registered
- Checks CLI uses registry data
- Validates README accuracy
-
Codex Code Review (PR only)
- Automatically reviews changed code
- Detects bugs, security vulnerabilities
- Posts review comments on PR
- Fails CI on HIGH/CRITICAL issues
-
Status Check
- Aggregates all job results
- Fails if any job fails
Status: ✅ All checks must pass to merge
2. Codex Automated Code Review (.github/workflows/codex-review.yml)
Triggers:
- Pull requests (opened, synchronized, reopened)
Scope:
- Reviews only changed files in:
CLI/commands/**/*.jsscripts/brain/**/*.tsscripts/**/*.jssrc/**/*.jsandsrc/**/*.ts
Process:
- Detects changed files in PR
- Runs Codex CLI review in read-only sandbox
- Analyzes for:
- Logic errors and edge cases
- Security vulnerabilities (SQL injection, XSS, etc.)
- Error handling gaps
- Resource leaks
- Race conditions
- Type safety violations
- Categorizes findings by severity:
- CRITICAL: Security vulnerabilities, hardcoded secrets
- HIGH: Logic errors, missing error handling
- MEDIUM: Code quality issues
- LOW: Minor improvements
- Posts results as PR comment
- Fails CI if HIGH or CRITICAL issues found
Requirements:
- Codex CLI v0.50.0+
- Completes in <5 minutes
- GitHub token needs
comments:writepermission
Helper Script:
scripts/ci/codex-review.sh- Takes file list as arguments
- Outputs structured JSON
- Exit code 1 for HIGH/CRITICAL issues
Example Output:
{
"summary": {
"files_reviewed": 3,
"high_critical": 2,
"medium": 1,
"low": 0
},
"findings": [
{
"file": "CLI/commands/sync.js",
"severity": "HIGH_CRITICAL",
"issue": "CRITICAL: SQL injection vulnerability on line 45"
}
]
}
Status: ⚠️ PR fails if HIGH or CRITICAL issues found
3. Coverage Workflow (.github/workflows/coverage.yml)
Triggers:
- Push to
main - Pull requests to
main
Actions:
- Generates detailed coverage report
- Uploads to Codecov with visualizations
- Comments coverage changes on PRs
- Uploads coverage artifacts (30-day retention)
Coverage Thresholds:
{
"lines": 80,
"functions": 80,
"branches": 75,
"statements": 80
}
Status: ⚠️ PR fails if coverage drops below threshold
4. Release Workflow (.github/workflows/release.yml)
Triggers:
- Push to
main(after PR merge) - Ignores documentation-only changes
Process:
- Runs full test suite
- Builds project
- Analyzes commit messages
- Determines version bump
- Updates CHANGELOG.md
- Creates GitHub release
- Creates git tag
- Updates documentation
Version Bumping:
feat:commits → Minor version (1.0.0 → 1.1.0)fix:commits → Patch version (1.0.0 → 1.0.1)BREAKING CHANGE:→ Major version (1.0.0 → 2.0.0)
Status: Fully automated, no manual intervention needed
🔧 Configuration Files
ESLint (.eslintrc.json)
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"prettier"
]
}
Rules:
- TypeScript strict mode
- React hooks validation
- No unused variables
- Prefer const over let
Prettier (.prettierrc.json)
{
"semi": false,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
Style:
- No semicolons
- Single quotes
- 100 character line width
- No trailing commas
Semantic Release (.releaserc.json)
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/git",
"@semantic-release/github"
]
}
Commit Convention:
- Follows Conventional Commits
- Automatic CHANGELOG generation
- GitHub release notes
📊 Status Badges
Add these to your README to show build status:
[](https://github.com/daffy0208/ai-dev-standards/actions/workflows/ci.yml)
[](https://codecov.io/gh/daffy0208/ai-dev-standards)
[](https://opensource.org/licenses/MIT)
Result:
🔑 Required Secrets
GitHub Repository Secrets
Navigate to: Settings → Secrets and variables → Actions
-
CODECOV_TOKEN(Optional, recommended)- Get from: https://codecov.io/
- Improves coverage upload reliability
-
NPM_TOKEN(Optional, for npm publish)- Get from: https://www.npmjs.com/
- Only needed if publishing to npm
Note: GITHUB_TOKEN is automatically provided by GitHub Actions.
🚦 Branch Protection Rules
Recommended Settings for main branch:
-
Require status checks to pass
- ✅ Test (Node 18.x)
- ✅ Test (Node 20.x)
- ✅ Lint
- ✅ Type Check
- ✅ Build
- ✅ Codex Code Review (PR only)
- ✅ Registry Validation
-
Require pull request reviews
- Minimum: 1 approval
- Dismiss stale reviews on push
-
Require linear history
- Use "Squash and merge"
-
Do not allow bypassing
- No force pushes
- No deletions
Setup Instructions:
- Go to: Settings → Branches
- Click Add rule
- Branch name pattern:
main - Enable protection rules above
- Save changes
🔄 Workflow Triggers
Automatic Triggers
| Event | Workflows |
|---|---|
Push to main |
CI, Coverage, Release |
Push to develop |
CI |
| Pull Request | CI, Coverage, Codex Review |
| Schedule (daily) | Security Audit |
Manual Triggers
You can manually trigger workflows from GitHub UI:
- Go to Actions tab
- Select workflow
- Click Run workflow
- Choose branch
- Click Run workflow button
📝 Commit Message Format
Structure
<type>(<scope>): <subject>
<body>
<footer>
Types
feat:- New feature → Minor version bumpfix:- Bug fix → Patch version bumpdocs:- Documentation → No version bumpstyle:- Formatting → No version bumprefactor:- Code refactoring → Patch version bumptest:- Tests → No version bumpchore:- Maintenance → No version bump
Breaking Changes
feat(api)!: change authentication method
BREAKING CHANGE: JWT tokens are now required instead of API keys
Result: Major version bump (1.0.0 → 2.0.0)
Examples
# Feature
feat(tools): add database query tool with PostgreSQL support
# Bug fix
fix(api-caller): prevent memory leak in retry logic
# Documentation
docs(readme): update installation instructions
# Multiple commits (will create one release)
feat(integrations): add Stripe payment integration
feat(components): add payment form component
fix(validation): handle edge case in email validator
🐛 Troubleshooting
CI Failing
Test failures:
# Run tests locally
npm test
# Debug specific test
npm run test:watch -- validation.test.ts
Lint errors:
# Check what's wrong
npm run lint
# Auto-fix issues
npm run lint:fix
Type errors:
# Check type errors
npm run typecheck
Coverage below threshold:
# See coverage report
npm run test:coverage
# View detailed HTML report
open coverage/index.html
Codex review failures:
# Test locally before pushing
chmod +x scripts/ci/codex-review.sh
./scripts/ci/codex-review.sh CLI/commands/sync.js
# Run on multiple files
./scripts/ci/codex-review.sh $(git diff --name-only main... | grep -E '\.(js|ts)$')
# Check results
cat codex-review-results.json | jq '.'
Testing Codex Review Locally
Before creating a PR, test the review workflow:
# 1. Install Codex CLI if not already installed
npm install -g @anthropics/codex-cli@latest
# 2. Make your changes to code files
vim CLI/commands/my-command.js
# 3. Run review on changed files
./scripts/ci/codex-review.sh CLI/commands/my-command.js
# 4. Review the findings
cat codex-review-results.json | jq '.summary'
# 5. Fix HIGH/CRITICAL issues before committing
# (MEDIUM and LOW issues are warnings only)
Expected Results:
- Exit code 0: No HIGH/CRITICAL issues
- Exit code 1: HIGH/CRITICAL issues found (CI will fail)
- Exit code 2: Script error (check Codex installation)
Release Not Triggered
Check commit messages:
- Ensure using conventional format
- Must have
feat:orfix:for release - Docs/style/test commits don't trigger releases
Check branch:
- Releases only from
mainbranch - Ensure PR was merged, not just pushed
Check logs:
- Go to Actions tab
- Check Release workflow logs
- Look for errors in semantic-release
Coverage Not Uploading
Missing Codecov token:
- Sign up at https://codecov.io/
- Add repository
- Copy token
- Add as
CODECOV_TOKENsecret
Workaround:
- Coverage will still work without token
- Token improves reliability and features
📚 Resources
Documentation
Useful Commands
# Run full CI locally
npm run ci
# Run individual checks
npm test
npm run lint
npm run typecheck
# Preview what release would do
npx semantic-release --dry-run
🎯 Best Practices
1. Always Run CI Locally First
Before pushing:
npm run ci
2. Write Good Commit Messages
# ✅ Good
feat(auth): add OAuth2 support for Google login
# ❌ Bad
update stuff
fix bug
WIP
3. Keep PRs Focused
- One feature/fix per PR
- Small, reviewable changes
- All tests pass
4. Monitor CI/CD
- Watch Actions tab after push
- Fix failures quickly
- Don't merge on red CI
5. Review Changelogs
- Check generated CHANGELOG.md
- Verify version bumps are correct
- Ensure release notes are clear
🚀 What Happens on Merge?
-
PR merged to
mainUser clicks "Squash and merge" -
CI runs (2-3 minutes)
✅ Tests pass ✅ Lint passes ✅ Types check ✅ Build succeeds -
semantic-release analyzes commits (30 seconds)
Found: feat(tools): add new tool Decision: Bump minor version Current: 1.2.3 → New: 1.3.0 -
Updates files
✅ package.json → version: 1.3.0 ✅ CHANGELOG.md → added entry ✅ Git tag → v1.3.0 created -
Creates GitHub release
✅ Release notes generated ✅ Assets attached ✅ Published -
Documentation updated
✅ BUILD-STATUS.md date updated
Total time: ~4-5 minutes from merge to release! 🚀
✅ Checklist for New Contributors
Before first contribution:
- Read CONTRIBUTING.md
- Understand commit message convention
- Set up local development environment
- Run
npm run cisuccessfully locally - Fork repository
- Create feature branch
- Make changes with tests
- Commit with conventional format
- Push and create PR
- Wait for CI to pass
- Address review feedback
- Celebrate when merged! 🎉
Your contributions power this project. Thank you! 🙏
Updated: 2025-10-27