-
Notifications
You must be signed in to change notification settings - Fork 2
208 lines (178 loc) · 6.69 KB
/
ci.yml
File metadata and controls
208 lines (178 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: 🧪 CI
on:
pull_request:
branches: [master, dev]
push:
branches: [dev]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }}
cancel-in-progress: true
env:
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/effectify"
jobs:
# Lint and format check
lint:
name: 🔍 Lint & Format
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🔍 Run oxlint on affected projects
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE="origin/${{ github.base_ref }}"
else
BASE="HEAD~1"
fi
pnpm nx affected --target=lint --base=$BASE --head=HEAD --parallel=3
- name: 🎨 Check code formatting with dprint
run: pnpm exec dprint check || (echo "❌ Some files are not formatted. Run 'pnpm exec dprint fmt' to fix formatting." && exit 1)
# Type checking
typecheck:
name: 🔍 Type Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🔍 Type check affected projects
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE="origin/${{ github.base_ref }}"
else
BASE="HEAD~1"
fi
pnpm nx affected --target=typecheck --base=$BASE --head=HEAD --parallel=3 --verbose
# Build affected projects
build:
name: 🏗️ Build
runs-on: ubuntu-latest
outputs:
has-build-artifacts: ${{ steps.build.outputs.has-artifacts }}
steps:
- name: 📥 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🏗️ Build affected projects
id: build
run: |
BASE=$(git merge-base HEAD origin/dev)
# Build affected projects with caching
pnpm nx affected --target=build --base=$BASE --head=HEAD --parallel=3 --verbose
# Check if any projects were built
AFFECTED_PROJECTS=$(pnpm nx show projects --affected --base=$BASE --head=HEAD --json | jq -r '.[]' | tr '\n' ' ')
if [ -n "$AFFECTED_PROJECTS" ]; then
echo "has-artifacts=true" >> $GITHUB_OUTPUT
echo "📦 Built projects: $AFFECTED_PROJECTS"
# Create build manifest for artifact upload
echo "BUILT_PROJECTS=$AFFECTED_PROJECTS" >> $GITHUB_ENV
else
echo "has-artifacts=false" >> $GITHUB_OUTPUT
echo "ℹ️ No projects to build"
fi
- name: 📦 Upload build artifacts
if: steps.build.outputs.has-artifacts == 'true'
uses: actions/upload-artifact@v4
with:
name: build-artifacts-${{ github.sha }}
path: |
packages/*/dist/
apps/*/dist/
apps/*/build/
retention-days: 7
- run: pnpm nx fix-ci
if: always() # IMPORTANT: Always run
# Test affected projects
test:
name: 🧪 Test
runs-on: ubuntu-latest
needs: [build]
steps:
- name: 📥 Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 📦 Download build artifacts
if: needs.build.outputs.has-build-artifacts == 'true'
uses: actions/download-artifact@v4
with:
name: build-artifacts-${{ github.sha }}
- name: 🧪 Test affected projects
run: |
BASE=$(git merge-base HEAD origin/dev)
pnpm nx affected --target=test --base=$BASE --head=HEAD --parallel=3 --verbose --passWithNoTests
# Summary job
ci-summary:
name: 📊 CI Summary
runs-on: ubuntu-latest
needs: [lint, typecheck, build, test]
if: always()
steps:
- name: 📊 CI Summary
run: |
echo "## 🧪 CI Results Summary" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status | Details |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|---------|" >> $GITHUB_STEP_SUMMARY
echo "| 🔍 Lint & Format | ${{ needs.lint.result == 'success' && '✅ Success' || '❌ Failed' }} | Uses oxlint + dprint |" >> $GITHUB_STEP_SUMMARY
echo "| 🔍 Type Check | ${{ needs.typecheck.result == 'success' && '✅ Success' || '❌ Failed' }} | TypeScript compiler checks |" >> $GITHUB_STEP_SUMMARY
echo "| 🏗️ Build | ${{ needs.build.result == 'success' && '✅ Success' || '❌ Failed' }} | Nx affected build |" >> $GITHUB_STEP_SUMMARY
echo "| 🧪 Test | ${{ needs.test.result == 'success' && '✅ Success' || '❌ Failed' }} | Unit tests with Vitest |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📈 Performance Metrics" >> $GITHUB_STEP_SUMMARY
echo "- 🔄 Parallel execution: 3x for lint/typecheck/build/test" >> $GITHUB_STEP_SUMMARY
echo "- 📦 Caching: Nx computation caching enabled" >> $GITHUB_STEP_SUMMARY
echo "- 🎯 Affected projects only: Runs only on changed code" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.lint.result }}" != "success" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "### ❌ Linting Issues" >> $GITHUB_STEP_SUMMARY
echo "Please run 'pnpm exec dprint fmt' to fix formatting issues" >> $GITHUB_STEP_SUMMARY
fi
# NEW: Add this step at the end of your job