-
Notifications
You must be signed in to change notification settings - Fork 1
341 lines (301 loc) · 13.2 KB
/
Copy pathci.yml
File metadata and controls
341 lines (301 loc) · 13.2 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
name: 🧪 CI
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
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"
NODE_OPTIONS: "--max-old-space-size=4096"
jobs:
release-policy:
name: 🛡️ Release Policy Contract
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: 📥 Checkout stable release PR head
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/stable-')
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: 🛡️ Require one stable release source commit
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/stable-')
shell: bash
env:
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
set -euo pipefail
[[ "$PR_HEAD_REF" == release/stable-* ]] || { echo '::error::invalid stable release head branch'; exit 1; }
[[ "$PR_HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo '::error::stable release PR head SHA must be full lowercase hexadecimal'; exit 1; }
[[ "$PR_BASE_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo '::error::stable release PR base SHA must be full lowercase hexadecimal'; exit 1; }
test "$(git rev-parse HEAD)" = "$PR_HEAD_SHA" || { echo '::error::stable release PR checkout does not match the GitHub head SHA'; exit 1; }
git fetch --no-tags --no-write-fetch-head origin "$PR_BASE_SHA"
git cat-file -e "${PR_HEAD_SHA}^{commit}"
git cat-file -e "${PR_BASE_SHA}^{commit}"
SOURCE_COMMIT_COUNT=$(git rev-list --count "$PR_BASE_SHA..$PR_HEAD_SHA")
if [ "$SOURCE_COMMIT_COUNT" != 1 ]; then
echo "::error::stable release PR must contain exactly one source commit; found $SOURCE_COMMIT_COUNT"
exit 1
fi
echo "Stable release PR contains exactly one source commit."
- name: 📥 Checkout
uses: actions/checkout@v5
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "24.19.0"
package-manager-cache: false
- name: 🛡️ Verify release policy contract
run: node --test scripts/release-policy-contract.test.mjs
- name: 🧪 Verify stable FINALIZE harness
run: node --test scripts/release-finalize-stable.test.mjs
# Lint and format check
lint:
name: 🔍 Lint & Format
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "24.19.0"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🎯 Resolve affected base
id: affected-base
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE="origin/${{ github.base_ref }}"
else
BEFORE="${{ github.event.before }}"
DEFAULT_BASE="origin/${{ github.event.repository.default_branch }}"
ZERO_SHA="0000000000000000000000000000000000000000"
if [[ -n "$BEFORE" && "$BEFORE" != "$ZERO_SHA" ]] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
BASE="$BEFORE"
elif git cat-file -e "${DEFAULT_BASE}^{commit}" 2>/dev/null; then
BASE="$DEFAULT_BASE"
elif git rev-parse --verify HEAD^ >/dev/null 2>&1; then
BASE="HEAD^"
else
BASE="HEAD"
fi
fi
echo "sha=$BASE" >> "$GITHUB_OUTPUT"
- name: 🔍 Run oxlint on affected projects
run: pnpm nx affected --target=lint --base="${{ steps.affected-base.outputs.sha }}" --head=HEAD --parallel=1
- name: 🎨 Check changed files with oxfmt
run: pnpm nx run @effectify/repo:format:check --args="--base=${{ steps.affected-base.outputs.sha }} --head=HEAD" || (echo "❌ Some changed files are not formatted. Run 'pnpm format' to fix formatting." && exit 1)
# Type checking
typecheck:
name: 🔍 Type Check
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "24.19.0"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🎯 Resolve affected base
id: affected-base
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE="origin/${{ github.base_ref }}"
else
BEFORE="${{ github.event.before }}"
DEFAULT_BASE="origin/${{ github.event.repository.default_branch }}"
ZERO_SHA="0000000000000000000000000000000000000000"
if [[ -n "$BEFORE" && "$BEFORE" != "$ZERO_SHA" ]] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
BASE="$BEFORE"
elif git cat-file -e "${DEFAULT_BASE}^{commit}" 2>/dev/null; then
BASE="$DEFAULT_BASE"
elif git rev-parse --verify HEAD^ >/dev/null 2>&1; then
BASE="HEAD^"
else
BASE="HEAD"
fi
fi
echo "sha=$BASE" >> "$GITHUB_OUTPUT"
- name: 🔍 Type check affected projects
run: pnpm nx affected --target=typecheck --base="${{ steps.affected-base.outputs.sha }}" --head=HEAD --parallel=1 --verbose
# Build affected projects
build:
name: 🏗️ Build
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
outputs:
has-build-artifacts: ${{ steps.build.outputs.has-artifacts }}
steps:
- name: 📥 Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "24.19.0"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🎯 Resolve affected base
id: affected-base
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE="origin/${{ github.base_ref }}"
else
BEFORE="${{ github.event.before }}"
DEFAULT_BASE="origin/${{ github.event.repository.default_branch }}"
ZERO_SHA="0000000000000000000000000000000000000000"
if [[ -n "$BEFORE" && "$BEFORE" != "$ZERO_SHA" ]] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
BASE="$BEFORE"
elif git cat-file -e "${DEFAULT_BASE}^{commit}" 2>/dev/null; then
BASE="$DEFAULT_BASE"
elif git rev-parse --verify HEAD^ >/dev/null 2>&1; then
BASE="HEAD^"
else
BASE="HEAD"
fi
fi
echo "sha=$BASE" >> "$GITHUB_OUTPUT"
- name: 🏗️ Build affected projects
id: build
run: |
BASE="${{ steps.affected-base.outputs.sha }}"
# Build affected projects with caching
pnpm nx affected --target=build --base="$BASE" --head=HEAD --parallel=1 --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
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
needs: [build]
steps:
- name: 📥 Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: 📦 Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10.14.0
- name: 🏗️ Setup Node.js
uses: actions/setup-node@v5
with:
node-version: "24.19.0"
cache: "pnpm"
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
- name: 🎯 Resolve affected base
id: affected-base
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE="origin/${{ github.base_ref }}"
else
BEFORE="${{ github.event.before }}"
DEFAULT_BASE="origin/${{ github.event.repository.default_branch }}"
ZERO_SHA="0000000000000000000000000000000000000000"
if [[ -n "$BEFORE" && "$BEFORE" != "$ZERO_SHA" ]] && git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
BASE="$BEFORE"
elif git cat-file -e "${DEFAULT_BASE}^{commit}" 2>/dev/null; then
BASE="$DEFAULT_BASE"
elif git rev-parse --verify HEAD^ >/dev/null 2>&1; then
BASE="HEAD^"
else
BASE="HEAD"
fi
fi
echo "sha=$BASE" >> "$GITHUB_OUTPUT"
- 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: pnpm nx affected --target=test --base="${{ steps.affected-base.outputs.sha }}" --head=HEAD --parallel=1 --verbose --passWithNoTests
# Summary job
ci-summary:
name: 📊 CI Summary
runs-on: ubuntu-latest
needs: [release-policy, lint, typecheck, build, test]
if: always() && (github.event_name != 'pull_request' || github.event.pull_request.draft == false)
steps:
- name: 📊 CI Summary
run: |
echo "## 🧪 CI Results Summary" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status | Details |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|---------|" >> $GITHUB_STEP_SUMMARY
echo "| 🛡️ Release Policy | ${{ needs.release-policy.result == 'success' && '✅ Success' || '❌ Failed' }} | Enforces alpha, beta, and stable separation |" >> $GITHUB_STEP_SUMMARY
echo "| 🔍 Lint & Format | ${{ needs.lint.result == 'success' && '✅ Success' || '❌ Failed' }} | Uses oxlint + oxfmt |" >> $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: 1x 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 format' to fix formatting issues" >> $GITHUB_STEP_SUMMARY
fi
# NEW: Add this step at the end of your job