|
| 1 | +# GitHub Actions Workflows |
| 2 | + |
| 3 | +## CI Workflow |
| 4 | + |
| 5 | +The CI workflow (`ci.yml`) ensures the application builds successfully before merging. |
| 6 | + |
| 7 | +### Triggers |
| 8 | + |
| 9 | +- **Push** to `main` branch only |
| 10 | +- **Pull requests** targeting `main` |
| 11 | + |
| 12 | +### Node.js Version |
| 13 | + |
| 14 | +- Node.js 20.x (Current LTS) |
| 15 | + |
| 16 | +### Steps |
| 17 | + |
| 18 | +1. **Checkout code** - Clone the repository |
| 19 | +2. **Setup Node.js** - Install Node.js 20.x with npm cache |
| 20 | +3. **Install dependencies** - Run `npm ci` in app directory (uses workspace) |
| 21 | +4. **Build backend** - Compile TypeScript backend to JavaScript |
| 22 | +5. **Build frontend** - Build React frontend with Vite |
| 23 | +6. **Verify artifacts** - Check that all expected build files exist |
| 24 | +7. **Upload artifacts** - Store build outputs for inspection (7 days retention) |
| 25 | + |
| 26 | +### Why Only One Node.js Version? |
| 27 | + |
| 28 | +The workflow uses Node.js 20.x (Current LTS) to: |
| 29 | +- Reduce CI runtime and resource usage |
| 30 | +- Avoid duplicate runs (push + PR would create 4 jobs with matrix) |
| 31 | +- Focus on the primary supported version |
| 32 | +- Keep feedback fast for developers |
| 33 | + |
| 34 | +The devcontainer also uses Node.js 20, ensuring consistency between local development and CI. |
| 35 | + |
| 36 | +### Build Verification |
| 37 | + |
| 38 | +The workflow verifies these artifacts are created: |
| 39 | + |
| 40 | +**Backend:** |
| 41 | +- `backend/dist/server.js` |
| 42 | +- `backend/dist/discount-rules.js` |
| 43 | +- `backend/dist/types.js` |
| 44 | + |
| 45 | +**Frontend:** |
| 46 | +- `frontend/dist/index.html` |
| 47 | +- `frontend/dist/assets/` (CSS and JS bundles) |
| 48 | + |
| 49 | +### Status Badge |
| 50 | + |
| 51 | +Add to README.md: |
| 52 | +```markdown |
| 53 | + |
| 54 | +``` |
| 55 | + |
| 56 | +### Local Testing |
| 57 | + |
| 58 | +To test the same build process locally: |
| 59 | + |
| 60 | +```bash |
| 61 | +cd app |
| 62 | +npm ci |
| 63 | +npm run build --workspace=backend |
| 64 | +npm run build --workspace=frontend |
| 65 | +``` |
| 66 | + |
| 67 | +Ensure you're using Node.js 20.x: |
| 68 | +```bash |
| 69 | +node --version # Should show v20.x.x |
| 70 | +``` |
| 71 | + |
| 72 | +### Troubleshooting |
| 73 | + |
| 74 | +**If CI fails:** |
| 75 | + |
| 76 | +1. Check the workflow run logs on GitHub Actions tab |
| 77 | +2. Look for TypeScript compilation errors |
| 78 | +3. Verify all dependencies are in package.json |
| 79 | +4. Test the build locally with Node.js 20.x |
| 80 | +5. Ensure package-lock.json is committed |
| 81 | + |
| 82 | +**Common issues:** |
| 83 | + |
| 84 | +- Missing dependencies: Run `npm install` and commit updated package-lock.json |
| 85 | +- TypeScript errors: Fix type issues in source code |
| 86 | +- Build configuration: Check tsconfig.json and vite.config.ts |
0 commit comments