-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (187 loc) · 6.31 KB
/
ci.yml
File metadata and controls
226 lines (187 loc) · 6.31 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
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
paths:
- 'Cyrano/**'
- 'Labs/Potemkin/**'
- 'apps/lexfiat/**'
- 'apps/arkiver/**'
- 'docs/**'
- '.github/workflows/ci.yml'
- 'package.json'
- 'package-lock.json'
pull_request:
branches: [main, develop]
paths:
- 'Cyrano/**'
- 'Labs/Potemkin/**'
- 'apps/lexfiat/**'
- 'apps/arkiver/**'
- 'docs/**'
- '.github/workflows/ci.yml'
- 'package.json'
- 'package-lock.json'
permissions:
contents: read
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
defaults:
run:
working-directory: ./Cyrano
steps:
- uses: actions/checkout@v4
- name: Debug environment
run: |
echo "Working directory: $(pwd)"
echo "Node version: $(node -v)"
echo "NPM version: $(npm -v)"
echo "Directory contents:"
ls -la
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: Cyrano/package-lock.json
- name: Validate lockfile platform compatibility
run: python3 ${{ github.workspace }}/.github/scripts/validate-lockfile.py package-lock.json
- name: Install dependencies
run: npm ci
- name: Clear Playwright cache
run: rm -rf ~/.cache/ms-playwright/
continue-on-error: true
- name: Install Playwright browsers
run: |
npx playwright install --with-deps chromium || {
echo "::error::Playwright browser installation failed"
exit 1
}
- name: Run linter
run: npm run lint
continue-on-error: true
- name: Type check
run: npm run build
- name: Run unit tests
run: npm run test:unit
continue-on-error: true
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Generate coverage report
run: npm run test:unit -- --coverage || true
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./Cyrano/coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
continue-on-error: true
- name: Upload test artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-artifacts
path: |
./Cyrano/coverage/
./Cyrano/test-output.txt
retention-days: 5
continue-on-error: true
quality-gates:
name: Quality Gates
runs-on: ubuntu-latest
needs: test
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
defaults:
run:
working-directory: ./Cyrano
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: Cyrano/package-lock.json
- name: Validate lockfile platform compatibility
run: python3 ${{ github.workspace }}/.github/scripts/validate-lockfile.py package-lock.json
- name: Install dependencies
run: npm ci
- name: Run tests with coverage
id: test-results
run: |
npm run test:coverage 2>&1 | tee test-output.txt || true
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Extract test results
run: |
# Extract test pass rate from vitest output
# Vitest format: "Tests N passed | M failed (T)"
PASSED_TESTS=$(grep -oE '[0-9]+ passed' test-output.txt | grep -oE '[0-9]+' | head -1 || echo "0")
FAILED_TESTS=$(grep -oE '[0-9]+ failed' test-output.txt | grep -oE '[0-9]+' | head -1 || echo "0")
# Total = passed + failed (skipped tests are not counted against pass rate)
TOTAL_TESTS=$(( PASSED_TESTS + FAILED_TESTS ))
if [ "$TOTAL_TESTS" = "0" ]; then
echo "⚠️ Could not extract test counts from output - skipping quality gate"
cat test-output.txt
exit 0
fi
# Calculate pass rate (using awk for better precision)
PASS_RATE=$(awk "BEGIN {printf \"%.2f\", ($PASSED_TESTS * 100) / $TOTAL_TESTS}")
PASS_RATE_INT=$(echo "$PASS_RATE" | cut -d. -f1)
echo "Total tests (pass+fail): $TOTAL_TESTS"
echo "Passed: $PASSED_TESTS"
echo "Failed: $FAILED_TESTS"
echo "Pass rate: $PASS_RATE%"
# Check quality gates
if [ "$PASS_RATE_INT" -lt 85 ]; then
echo "❌ Quality gate failed: Pass rate $PASS_RATE% is below 85%"
exit 1
fi
echo "✅ Quality gate passed: Pass rate $PASS_RATE% meets 85% requirement"
- name: Check coverage
run: |
if [ -f coverage/coverage-summary.json ]; then
COVERAGE=$(node -e "const cov = require('./coverage/coverage-summary.json'); console.log(cov.total.lines.pct || 0)")
COVERAGE_INT=$(echo "$COVERAGE" | cut -d. -f1)
echo "Code coverage: $COVERAGE%"
if [ "$COVERAGE_INT" -lt 70 ]; then
echo "❌ Quality gate failed: Coverage $COVERAGE% is below 70%"
exit 1
fi
echo "✅ Quality gate passed: Coverage $COVERAGE% meets 70% requirement"
else
echo "⚠️ Coverage file not found, skipping coverage check"
fi
security-scan:
name: Security Scan
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Snyk CLI
run: npm install -g snyk
continue-on-error: true
- name: Snyk Code test
run: snyk code test --sarif > snyk-code.sarif || true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
continue-on-error: true
- name: Upload Snyk results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk-code.sarif
continue-on-error: true