|
1 | 1 | name: CI/CD Pipeline for Budget Management API
|
| 2 | + |
2 | 3 | on:
|
3 | 4 | push:
|
4 |
| - branches: [master] |
| 5 | + branches: |
| 6 | + - master |
5 | 7 | pull_request:
|
6 |
| - branches: [master] |
| 8 | + branches: |
| 9 | + - master |
7 | 10 |
|
8 | 11 | jobs:
|
9 | 12 | formatting:
|
10 |
| - name: "🔧 Formatting & Lint" |
| 13 | + name: 🔧 Install, Lint & Format |
11 | 14 | runs-on: ubuntu-latest
|
12 | 15 | steps:
|
13 | 16 | - name: Checkout code
|
14 | 17 | uses: actions/checkout@v3
|
15 |
| - continue-on-error: true |
16 | 18 |
|
17 |
| - - name: Setup Node.js |
| 19 | + - name: Use Node.js 18 |
18 | 20 | uses: actions/setup-node@v3
|
19 | 21 | with:
|
20 | 22 | node-version: 18
|
21 |
| - continue-on-error: true |
22 | 23 |
|
23 | 24 | - name: Install dependencies
|
24 | 25 | run: npm ci
|
25 |
| - continue-on-error: true |
26 | 26 |
|
27 |
| - - name: Prettier format |
| 27 | + - name: Run Prettier |
28 | 28 | run: npm run format
|
29 |
| - continue-on-error: true |
30 |
| - |
31 |
| - - name: ESLint lint |
32 |
| - run: npm run lint |
33 |
| - continue-on-error: true |
34 | 29 |
|
35 |
| - backend: |
36 |
| - name: "✅ Backend Build & Test" |
| 30 | + test: |
| 31 | + name: ✅ Run Jest Tests |
37 | 32 | runs-on: ubuntu-latest
|
38 |
| - needs: [formatting] |
39 |
| - if: ${{ always() }} |
| 33 | + needs: formatting |
40 | 34 | steps:
|
41 | 35 | - name: Checkout code
|
42 | 36 | uses: actions/checkout@v3
|
43 |
| - continue-on-error: true |
44 | 37 |
|
45 |
| - - name: Setup Node.js |
| 38 | + - name: Use Node.js 18 |
46 | 39 | uses: actions/setup-node@v3
|
47 | 40 | with:
|
48 | 41 | node-version: 18
|
49 |
| - continue-on-error: true |
50 | 42 |
|
51 |
| - - name: Install backend deps |
52 |
| - run: npm --workspace backend ci |
53 |
| - continue-on-error: true |
| 43 | + - name: Install dependencies |
| 44 | + run: npm ci |
54 | 45 |
|
55 |
| - - name: Backend format |
56 |
| - run: npm --workspace backend run format |
57 |
| - continue-on-error: true |
| 46 | + - name: Run Jest tests |
| 47 | + run: npm test |
58 | 48 |
|
59 |
| - - name: Backend lint |
60 |
| - run: npm --workspace backend run lint |
61 |
| - continue-on-error: true |
| 49 | + mocha: |
| 50 | + name: 🧪 Run Mocha & Chai Tests |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: test |
| 53 | + steps: |
| 54 | + - name: Checkout code |
| 55 | + uses: actions/checkout@v3 |
62 | 56 |
|
63 |
| - - name: Build backend |
64 |
| - run: npm --workspace backend run build |
65 |
| - continue-on-error: true |
| 57 | + - name: Use Node.js 18 |
| 58 | + uses: actions/setup-node@v3 |
| 59 | + with: |
| 60 | + node-version: 18 |
66 | 61 |
|
67 |
| - - name: Backend tests |
68 |
| - run: npm --workspace backend run test |
69 |
| - continue-on-error: true |
| 62 | + - name: Install dependencies |
| 63 | + run: npm ci |
| 64 | + |
| 65 | + - name: Run Mocha & Chai tests |
| 66 | + run: npm run test:mocha |
70 | 67 |
|
71 | 68 | frontend:
|
72 |
| - name: "🌐 Frontend Build & Test" |
| 69 | + name: 🌐 Frontend Test, Build & Artifact |
73 | 70 | runs-on: ubuntu-latest
|
74 |
| - needs: [backend] |
75 |
| - if: ${{ always() }} |
| 71 | + needs: mocha |
76 | 72 | steps:
|
77 | 73 | - name: Checkout code
|
78 | 74 | uses: actions/checkout@v3
|
79 |
| - continue-on-error: true |
80 | 75 |
|
81 |
| - - name: Setup Node.js |
| 76 | + - name: Use Node.js 18 |
82 | 77 | uses: actions/setup-node@v3
|
83 | 78 | with:
|
84 | 79 | node-version: 18
|
85 |
| - continue-on-error: true |
86 | 80 |
|
87 |
| - - name: Install frontend deps |
88 |
| - run: npm --workspace frontend ci |
89 |
| - continue-on-error: true |
| 81 | + - name: Install frontend dependencies |
| 82 | + working-directory: frontend |
| 83 | + run: npm ci |
90 | 84 |
|
91 |
| - - name: Frontend format |
92 |
| - run: npm --workspace frontend run format |
93 |
| - continue-on-error: true |
| 85 | + - name: Build Frontend |
| 86 | + working-directory: frontend |
| 87 | + run: npm run build |
94 | 88 |
|
95 |
| - - name: Frontend lint |
96 |
| - run: npm --workspace frontend run lint |
97 |
| - continue-on-error: true |
| 89 | + - name: Upload Frontend Build Artifact |
| 90 | + uses: actions/upload-artifact@v4 |
| 91 | + with: |
| 92 | + name: frontend-build |
| 93 | + path: frontend/build |
98 | 94 |
|
99 |
| - - name: Build frontend |
100 |
| - run: npm --workspace frontend run build |
101 |
| - continue-on-error: true |
| 95 | + coverage: |
| 96 | + name: 📊 Generate Coverage |
| 97 | + runs-on: ubuntu-latest |
| 98 | + needs: |
| 99 | + - test |
| 100 | + - mocha |
| 101 | + - frontend |
| 102 | + steps: |
| 103 | + - name: Checkout code |
| 104 | + uses: actions/checkout@v3 |
102 | 105 |
|
103 |
| - - name: Frontend tests |
104 |
| - run: npm --workspace frontend run test:unit |
105 |
| - continue-on-error: true |
| 106 | + - name: Use Node.js 18 |
| 107 | + uses: actions/setup-node@v3 |
| 108 | + with: |
| 109 | + node-version: 18 |
| 110 | + |
| 111 | + - name: Install dependencies |
| 112 | + run: npm ci |
| 113 | + |
| 114 | + - name: Run coverage |
| 115 | + run: npm run coverage |
| 116 | + |
| 117 | + - name: Archive coverage report |
| 118 | + if: always() |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: coverage-report |
| 122 | + path: coverage |
| 123 | + |
| 124 | + docker: |
| 125 | + name: 🐳 Build & Push Docker Images |
| 126 | + runs-on: ubuntu-latest |
| 127 | + needs: |
| 128 | + - coverage |
| 129 | + permissions: |
| 130 | + contents: read |
| 131 | + packages: write |
| 132 | + steps: |
| 133 | + - name: Checkout code |
| 134 | + uses: actions/checkout@v3 |
| 135 | + |
| 136 | + - name: Log in to GitHub Container Registry |
| 137 | + uses: docker/login-action@v2 |
| 138 | + with: |
| 139 | + registry: ghcr.io |
| 140 | + username: ${{ github.actor }} |
| 141 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + |
| 143 | + - name: Build & push backend image |
| 144 | + uses: docker/build-push-action@v3 |
| 145 | + with: |
| 146 | + context: . |
| 147 | + file: ./Dockerfile |
| 148 | + push: true |
| 149 | + tags: | |
| 150 | + ghcr.io/${{ github.repository_owner }}/budget-management-backend:${{ github.sha }} |
| 151 | + ghcr.io/${{ github.repository_owner }}/budget-management-backend:latest |
| 152 | +
|
| 153 | + - name: Build & push frontend image |
| 154 | + uses: docker/build-push-action@v3 |
| 155 | + with: |
| 156 | + context: ./frontend |
| 157 | + file: ./frontend/Dockerfile |
| 158 | + push: true |
| 159 | + tags: | |
| 160 | + ghcr.io/${{ github.repository_owner }}/budget-management-frontend:${{ github.sha }} |
| 161 | + ghcr.io/${{ github.repository_owner }}/budget-management-frontend:latest |
| 162 | +
|
| 163 | + deploy: |
| 164 | + name: 🚀 Deploying |
| 165 | + runs-on: ubuntu-latest |
| 166 | + needs: docker |
| 167 | + steps: |
| 168 | + - name: Simulate deployment to Render |
| 169 | + run: | |
| 170 | + echo "✅ Backend deployed to Render" |
| 171 | + - name: Simulate deployment to Vercel |
| 172 | + run: | |
| 173 | + echo "✅ Frontend deployed to Vercel" |
106 | 174 |
|
107 | 175 | complete:
|
108 |
| - name: "🎉 Pipeline Complete" |
| 176 | + name: 🎉 All Done |
109 | 177 | runs-on: ubuntu-latest
|
110 |
| - needs: [formatting, backend, frontend] |
111 |
| - if: ${{ always() }} |
| 178 | + needs: deploy |
112 | 179 | steps:
|
113 | 180 | - name: Final status
|
114 | 181 | run: echo "✅ CI/CD pipeline finished successfully."
|
0 commit comments