4.6 KiB
4.6 KiB
CI/CD Setup Guide
Overview
This project uses GitHub Actions for continuous integration and deployment.
Workflows
1. CI Workflow (.github/workflows/ci.yml)
Runs on every push and pull request to main/develop branches.
Steps:
- Checkout code
- Setup Node.js (18.x, 20.x matrix)
- Install dependencies
- Run linter
- Run type check
- Run tests
- Generate coverage report
- Upload coverage to Codecov
- Build application
- Upload build artifacts
- Security audit
2. Deploy Workflow (.github/workflows/deploy.yml)
Runs on push to main branch or manual trigger.
Steps:
- Checkout code
- Setup Node.js
- Install dependencies
- Run tests
- Build for production
- Deploy to Netlify/Vercel
- Notify deployment status
Required Secrets
Configure these in GitHub Settings > Secrets and variables > Actions:
For CI
CODECOV_TOKEN- Codecov upload token (optional)SNYK_TOKEN- Snyk security scanning token (optional)VITE_BACKEND_API_URL- API URL for build
For Deployment
Netlify
NETLIFY_AUTH_TOKEN- Netlify authentication tokenNETLIFY_SITE_ID- Netlify site IDVITE_BACKEND_API_URL_PROD- Production API URLVITE_SENTRY_DSN- Sentry DSN for error tracking
Vercel (Alternative)
VERCEL_TOKEN- Vercel authentication tokenVERCEL_ORG_ID- Vercel organization IDVERCEL_PROJECT_ID- Vercel project IDVITE_BACKEND_API_URL_PROD- Production API URLVITE_SENTRY_DSN- Sentry DSN
Setup Instructions
1. Enable GitHub Actions
GitHub Actions is enabled by default for all repositories.
2. Configure Secrets
Go to your repository:
Settings > Secrets and variables > Actions > New repository secret
Add all required secrets listed above.
3. Configure Codecov (Optional)
- Sign up at codecov.io
- Add your repository
- Copy the upload token
- Add as
CODECOV_TOKENsecret
4. Configure Netlify
- Sign up at netlify.com
- Create a new site
- Get your Site ID from Site settings
- Generate a Personal Access Token
- Add both as secrets
5. Configure Vercel (Alternative)
- Sign up at vercel.com
- Install Vercel CLI:
npm i -g vercel - Run
vercel login - Run
vercel linkin your project - Get tokens from Vercel dashboard
- Add as secrets
Manual Deployment
Trigger via GitHub UI
- Go to Actions tab
- Select "Deploy to Production"
- Click "Run workflow"
- Select branch
- Click "Run workflow"
Trigger via CLI
gh workflow run deploy.yml
Monitoring
View Workflow Runs
Repository > Actions tab
View Logs
Click on any workflow run to see detailed logs.
Notifications
Configure notifications in:
Settings > Notifications > Actions
Troubleshooting
Build Fails
- Check logs in Actions tab
- Verify all secrets are set correctly
- Test build locally:
npm run build
Tests Fail
- Run tests locally:
npm run test:run - Check for environment-specific issues
- Verify test setup is correct
Deployment Fails
- Check deployment logs
- Verify API URL is correct
- Check Netlify/Vercel dashboard for errors
Best Practices
- Always run tests before merging
- Use pull requests for code review
- Keep secrets secure - never commit them
- Monitor build times - optimize if needed
- Review security audit results
- Keep dependencies updated
Advanced Configuration
Branch Protection Rules
Recommended settings:
Settings > Branches > Add rule
Branch name pattern: main
☑ Require a pull request before merging
☑ Require status checks to pass before merging
- test
- build
☑ Require branches to be up to date before merging
☑ Do not allow bypassing the above settings
Caching
The workflows use npm caching to speed up builds:
- uses: actions/setup-node@v4
with:
cache: 'npm'
Matrix Testing
Tests run on multiple Node.js versions:
strategy:
matrix:
node-version: [18.x, 20.x]
Cost Optimization
GitHub Actions is free for public repositories and includes:
- 2,000 minutes/month for private repos (free tier)
- Unlimited for public repos
Tips to reduce usage:
- Use caching
- Run tests only on changed files
- Skip redundant jobs
- Use self-hosted runners for heavy workloads