CI/CD Pipeline & GitHub Actions
Overview
The Docker build and deployment process is fully automated using GitHub Actions. The pipeline runs tests, builds the application, creates a Docker image, and deploys to production automatically on every push to the master/main branch.
GitHub Actions Workflow Improvements
Enhanced Documentation
The deploy-frontend.yml workflow includes:
- Clear purpose statements for each stage
- When each stage runs (push vs PR, master/main only)
- What causes pipeline failure
- Required secrets and environment variables
- Error messages with troubleshooting tips
Better Naming
- Changed "Use Node.js 20" to "Setup Node.js 20"
- Changed "Check test results" to "Verify test results"
- More descriptive deploy step comments
Improved Error Handling
- Better error messages explaining what went wrong
- Troubleshooting tips in failure messages
- Clear indication of required secrets
Workflow Structure
Two-Stage Pipeline
The deployment pipeline has two distinct stages with different triggers and purposes:
- Push to any branch
- Pull requests"] MainOnly["Runs on:
- Push to master/main only"] end Push --> stage1 stage1 -->|Success| stage2 stage1 -->|Failure| Blocked["β Deployment blocked"] stage1 --> AllCommits stage2 --> MainOnly stage2 --> Success["β Deployed"] stage2 -->|Failure| Failure["β Deployment failed"] style stage1 fill:#e3f2fd style stage2 fill:#c8e6c9 style Success fill:#fff9c4 style Blocked fill:#ffccbc style Failure fill:#ffccbc
Stage 1: Test & Verify (Always Runs)
Trigger: Every commit and pull request to any branch
Purpose: Ensure code quality and prevent broken code from being deployed
Steps
1. Checkout code
ββ Gets the latest code from repository
2. Setup Node.js 20
ββ Installs Node.js runtime environment
3. Use npm cache
ββ Speeds up dependency installation
4. Install dependencies
ββ npm ci (clean install for reproducibility)
ββ Installs all project dependencies
5. Run linter
ββ npm run lint (ESLint)
ββ Checks code style and quality
6. Run tests
ββ npm run test (Vitest)
ββ Runs 478+ unit and integration tests
7. Generate coverage report
ββ Vitest coverage analysis
ββ Ensures adequate test coverage
8. Verify test results
ββ Fails if tests fail
ββ Fails if linting issues foundKey Features
β
Runs on all commits - Including pull
requests
β
Fast feedback - Developers see failures
immediately
β
Prevents bad code - Broken code can't reach
production
β
npm caching - Speeds up repeated runs
β
Coverage tracking - Maintains test
quality
Example Output
β Checkout code
β Setup Node.js 20
β Use npm cache
β Install dependencies (15 seconds)
β Run linter (8 seconds)
ββ No ESLint errors found
β Run tests (45 seconds)
ββ Passed: 478 tests
ββ Failed: 0 tests
β Generate coverage report
ββ Coverage: 87%
β Verify test results
ββ All tests passed!
Stage 2: Build & Deploy (Protected)
Trigger: Only on push to master
or main branch
Runs After: Stage 1 succeeds
Purpose: Build production bundle and deploy to Vercel
Steps
1. Checkout code
ββ Gets the latest code
2. Setup Node.js 20
ββ Installs Node.js runtime
3. Use npm cache
ββ Speeds up builds
4. Install dependencies
ββ npm ci (same as Stage 1)
5. Build production bundle
ββ npm run build (Vite)
ββ Creates optimized dist/ directory
ββ Minifies and bundles code
ββ Optimizes assets
6. Verify build output
ββ Checks dist/ directory exists
ββ Verifies build artifacts
ββ Fails if build errors
7. Build Docker image
ββ docker build (optional - for testing)
ββ Creates container image
ββ Tests multi-stage build
8. Deploy to Vercel
ββ Pushes production build
ββ Triggers Vercel deployment
ββ Makes app live
9. Deployment summary
ββ Shows deployment URL
ββ Logs build time
ββ Provides rollback infoKey Features
β
Master/main only - Production only from
main branch
β
Depends on Stage 1 - Can't deploy if tests
fail
β
Docker verification - Tests build before
deployment
β
Automated deployment - No manual steps
needed
β
Clear summary - Shows deployment status
Example Output
β Checkout code
β Setup Node.js 20
β Use npm cache
β Install dependencies (15 seconds)
β Build production bundle (35 seconds)
ββ dist/index.html: 2.5KB
ββ dist/assets/index.js: 485KB
ββ dist/assets/vendor.js: 250KB
ββ dist/assets/index.css: 45KB
β Verify build output
ββ dist/ directory found
ββ All expected files present
β Build Docker image (30 seconds)
ββ Image size: 45MB
ββ Layers: 5
β Deploy to Vercel (20 seconds)
ββ Build ID: abc123def456
ββ URL: https://stockease-...vercel.app
β Deployment summary
ββ β
Deployed to production
Conditional Execution Logic
When Tests Run
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]| Event | Test Stage | Deploy Stage |
|---|---|---|
| Push to master/main | β Runs | β Runs (if tests pass) |
| Push to feature branch | β Runs | β Skipped |
| Pull request | β Runs | β Skipped |
| Direct commit to master | β Runs | β Runs (if tests pass) |
| Draft PR | β Runs | β Skipped |
Deployment Protection
if: success() && github.ref == 'refs/heads/master'Deployment only happens when:
- All tests pass
- Push is to master/main branch
- No failures in previous stages
- Commit is on main branch (not PR)
Required Configuration
Secrets
Two secrets must be configured in GitHub repository settings:
| Secret | Purpose | Where to Get |
|---|---|---|
VERCEL_TOKEN |
Authentication for Vercel deployment | Vercel Settings |
FRONTEND_API_BASE_URL |
Production API endpoint | Your backend API URL |
Environment Variables
VITE_API_BASE_URL: ${{ secrets.FRONTEND_API_BASE_URL }}
NODE_ENV: productionGitHub Actions Permissions
The workflow needs:
- Read access to repository code
- Write access to deployment status
- Secrets access (automatic)
Error Handling
Test Failures
If tests fail, the pipeline stops before deployment:
β npm run test FAILED
ββ Error: 2 tests failed
ββ LoginPage should render login form
ββ Dashboard should handle API errors
Action: Fix the failing tests before pushing again
Build Failures
If the build fails, deployment is blocked:
β npm run build FAILED
ββ Error: TypeScript compilation error
ββ src/components/Button.tsx:15: Type 'string' is not assignable to type 'number'
Action: Fix the TypeScript error
Deployment Failures
If Vercel deployment fails, you're notified:
β Deploy to Vercel FAILED
ββ Error: Deployment quota exceeded
Action: Check Vercel dashboard or contact support
Monitoring & Debugging
View Workflow Status
- Go to GitHub repository
- Click "Actions" tab
- Click workflow run to see details
- Click job to see step-by-step output
Common Issues & Solutions
Tests Failing
# Run tests locally first
npm run test
# Check linting
npm run lint
# Then push
git push origin feature-branchBuild Failing
# Build locally to verify
npm run build
# Check for build errors
npm run build -- --show-error
# Then push
git pushDeployment Not Triggering
# Ensure you're pushing to master/main
git push origin master
# Not to a feature branch
# (deployment won't trigger on feature branches)Performance Metrics
Typical Pipeline Times
| Stage | Time | Notes |
|---|---|---|
| Test Stage | 60-90 seconds | Includes npm install, lint, tests |
| Build Stage | 50-70 seconds | Includes npm install, build, Docker build |
| Deploy Stage | 20-40 seconds | Vercel deployment |
| Total | 2-3 minutes | From push to live |
Optimization
- npm cache: Reduces install time from 30s β 10s
- Layer caching: Docker reuses dependencies layer
- Parallel execution: Tests run in parallel (if configured)
Best Practices
1. Commit Frequently
Push changes regularly to get fast feedback:
git commit -m "feat: add user profile page"
git push origin feature-branch2. Keep Tests Passing
Don't push code with failing tests:
# Always run locally first
npm run test
npm run lint
# Then push
git push3. Use Meaningful Commit Messages
# Good
git commit -m "fix: handle API timeout in product list"
# Bad
git commit -m "fix stuff"4. Create Pull Requests
Don't push directly to master:
# Create feature branch
git checkout -b feature/add-search
# Work and push
git push origin feature/add-search
# Create PR on GitHub
# Let tests run on PR
# Get review
# Merge to master5. Monitor Deployments
Check GitHub Actions and Vercel dashboards after merging:
# Check Actions
open https://github.com/Keglev/stockease-frontend/actions
# Check Vercel
open https://vercel.com/keglev/stockease-frontendDeployment Workflow
Complete Development Cycle
1. Create feature branch
git checkout -b feature/new-feature
2. Make changes
Edit files, commit regularly
3. Run tests locally
npm run test
npm run lint
4. Push to GitHub
git push origin feature/new-feature
5. Create Pull Request
- Tests run on PR
- Get code review
- Fix any issues
6. Merge to master
- Tests run again
- If all pass, deploy starts
7. Vercel deployment
- Build happens
- Tests in production
- App goes live
8. Monitor
- Check Vercel dashboard
- Monitor error tracking
- Watch logs
Troubleshooting
Pipeline Not Running
Check:
- Branch is master/main
- Pushed to GitHub (not just committed locally)
.github/workflows/deploy-frontend.ymlexists- Repository settings allow Actions
Fix:
# Verify remote is GitHub
git remote -v
# Push again
git push origin masterDeployment Stuck
Check:
- GitHub Actions status
- Vercel deployment status
- Check for hanging processes
Fix:
# Cancel workflow on GitHub (Actions tab)
# Then push again
git push origin masterAPI Errors After Deployment
Check:
VITE_API_BASE_URLis correct- API server is running
- CORS is configured correctly
Fix:
# Check what URL is in the build
docker run your-image:latest cat /usr/share/nginx/html/assets/*.js | grep api
# Rebuild with correct URL
docker build --build-arg VITE_API_BASE_URL=https://api.correct.com .Related Documentation
- Docker Overview
- Build Stage
- Production Stage
- Configuration
- Local Usage
- Security & Performance
- Main Pipeline Documentation
- GitHub Actions Official Docs
Last Updated: November 12, 2025
Status: β
Production Ready
Maintenance: Automated via GitHub Actions