forked from openai/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
311 lines (291 loc) · 11.5 KB
/
Copy pathci.yml
File metadata and controls
311 lines (291 loc) · 11.5 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
# =============================================================================
# Phenotype CI — Unified multi-language pipeline (smart-discover)
# =============================================================================
# Detects languages from repo structure, only runs what applies.
# All steps are fail-tolerant: missing config → step skipped, not build broken.
# Optimized for: Rust, Python, Go, TypeScript
# Runners: Blacksmith (fast) → GitHub-hosted fallback
# =============================================================================
name: CI
on:
push:
branches: [main, master, develop, "release/**"]
pull_request:
branches: [main, master, develop]
merge_group:
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
PYTHONIOENCODING: utf-8
# ===========================================================================
# STAGE 1: Detect languages (file presence, fast)
# ===========================================================================
jobs:
detect:
name: Detect Languages
runs-on: ubuntu-latest
outputs:
rust: ${{ steps.detect.outputs.rust }}
python: ${{ steps.detect.outputs.python }}
go: ${{ steps.detect.outputs.go }}
typescript: ${{ steps.detect.outputs.typescript }}
has_ci_lint: ${{ steps.detect.outputs.rust_ci || steps.detect.outputs.python_ci || steps.detect.outputs.go_ci || steps.detect.outputs.ts_ci }}
steps:
- uses: actions/checkout@v4
- id: detect
run: |
# Smart-discover: only set true if relevant tooling files exist
if [ -f "Cargo.toml" ] || compgen -G "**/Cargo.toml" > /dev/null; then
echo "rust=true" >> "$GITHUB_OUTPUT"
else
echo "rust=false" >> "$GITHUB_OUTPUT"
fi
if [ -f "pyproject.toml" ] || [ -f "setup.py" ] || [ -f "setup.cfg" ] || compgen -G "requirements*.txt" > /dev/null || compgen -G "**/pyproject.toml" > /dev/null; then
echo "python=true" >> "$GITHUB_OUTPUT"
else
echo "python=false" >> "$GITHUB_OUTPUT"
fi
if [ -f "go.mod" ] || compgen -G "**/go.mod" > /dev/null; then
echo "go=true" >> "$GITHUB_OUTPUT"
else
echo "go=false" >> "$GITHUB_OUTPUT"
fi
if [ -f "package.json" ] || compgen -G "**/package.json" > /dev/null; then
echo "typescript=true" >> "$GITHUB_OUTPUT"
else
echo "typescript=false" >> "$GITHUB_OUTPUT"
fi
# Has any CI-runnable language?
if [ -f "Cargo.toml" ] || [ -f "pyproject.toml" ] || [ -f "setup.py" ] || [ -f "go.mod" ] || [ -f "package.json" ]; then
echo "has_ci_lint=true" >> "$GITHUB_OUTPUT"
else
echo "has_ci_lint=false" >> "$GITHUB_OUTPUT"
fi
# ===========================================================================
# STAGE 2: Per-language gates (run in parallel; fail-tolerant)
# ===========================================================================
rust:
name: Rust
needs: detect
if: needs.detect.outputs.rust == 'true'
runs-on: blacksmith-2vcpu-ubuntu-2204
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
with:
shared-key: phen-ci-rust
- name: fmt check
run: |
if cargo fmt --all -- --check 2>&1 | tee /tmp/fmt.log; then
echo "fmt_ok=true" >> "$GITHUB_OUTPUT"
else
echo "fmt_ok=false" >> "$GITHUB_OUTPUT"
fi
id: fmt
- name: clippy
run: cargo clippy --all-targets --no-deps -- -D warnings 2>&1 || echo "::warning::clippy failed (non-blocking)"
- name: build
run: cargo build --workspace 2>&1 || cargo build 2>&1 || echo "::warning::build failed (non-blocking)"
- name: test
run: |
if [ -f "Cargo.lock" ]; then
cargo test --workspace --no-fail-fast 2>&1 || cargo test --no-fail-fast 2>&1 || echo "::warning::tests failed (non-blocking)"
else
echo "No Cargo.lock — skipping tests"
fi
python:
name: Python
needs: detect
if: needs.detect.outputs.python == 'true'
runs-on: blacksmith-2vcpu-ubuntu-2204
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install ruff
run: pip install --quiet ruff 2>&1 || echo "::warning::ruff install failed"
- name: ruff check
run: ruff check --output-format=github . 2>&1 || echo "::warning::ruff check found issues (non-blocking)"
- name: ruff format
run: ruff format --check . 2>&1 || echo "::warning::format check found issues (non-blocking)"
- name: install deps
run: |
if [ -f "uv.lock" ]; then
pip install --quiet uv && uv sync --all-extras 2>&1 || echo "::warning::uv sync failed"
elif [ -f "pyproject.toml" ]; then
pip install --quiet -e . 2>&1 || echo "::warning::pip install -e failed"
elif compgen -G "requirements*.txt" > /dev/null; then
pip install --quiet -r requirements.txt 2>&1 || pip install --quiet -r requirements-dev.txt 2>&1 || echo "::warning::pip install failed"
fi
- name: pytest
run: |
if compgen -G "**/test_*.py" > /dev/null || compgen -G "tests/**/*.py" > /dev/null; then
python -m pytest --no-header -q 2>&1 || echo "::warning::pytest failed (non-blocking)"
else
echo "No tests found"
fi
go:
name: Go
needs: detect
if: needs.detect.outputs.go == 'true'
runs-on: blacksmith-2vcpu-ubuntu-2204
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "stable"
- name: go vet
run: go vet ./... 2>&1 || echo "::warning::go vet found issues (non-blocking)"
- name: go build
run: go build ./... 2>&1 || echo "::warning::go build failed (non-blocking)"
- name: go test
run: go test -race ./... 2>&1 || echo "::warning::go test failed (non-blocking)"
typescript:
name: TS/JS
needs: detect
if: needs.detect.outputs.typescript == 'true'
runs-on: blacksmith-2vcpu-ubuntu-2204
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- name: detect package manager
id: pm
run: |
if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> "$GITHUB_OUTPUT"
elif [ -f "yarn.lock" ]; then
echo "manager=yarn" >> "$GITHUB_OUTPUT"
elif [ -f "bun.lockb" ] || [ -f "bun.lock" ]; then
echo "manager=bun" >> "$GITHUB_OUTPUT"
else
echo "manager=npm" >> "$GITHUB_OUTPUT"
fi
- name: install
run: |
case "${{ steps.pm.outputs.manager }}" in
pnpm) npm install -g pnpm && pnpm install --frozen-lockfile 2>&1 || echo "::warning::install failed" ;;
yarn) npm install -g yarn && yarn install --frozen-lockfile 2>&1 || echo "::warning::install failed" ;;
bun) npm install -g bun && bun install --frozen-lockfile 2>&1 || echo "::warning::install failed" ;;
*) npm ci 2>&1 || npm install 2>&1 || echo "::warning::install failed" ;;
esac
- name: lint
run: |
if [ -f "biome.json" ] || [ -f "biome.jsonc" ]; then
npx @biomejs/biome lint . 2>&1 || echo "::warning::biome lint failed"
npx @biomejs/biome format --check . 2>&1 || echo "::warning::biome format failed"
elif grep -q '"lint"' package.json 2>/dev/null; then
npm run lint 2>&1 || echo "::warning::lint failed"
else
echo "No linter configured"
fi
- name: test
run: |
if grep -q '"test"' package.json 2>/dev/null && [ "$(node -e "console.log(require('./package.json').scripts?.test || '')")" != "" ]; then
npm test 2>&1 || echo "::warning::test failed"
else
echo "No tests configured"
fi
# ===========================================================================
# STAGE 3: Security & quality (always run, fail-tolerant)
# ===========================================================================
security:
name: Security Scan
needs: detect
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Trivy scan
uses: aquasecurity/trivy-action@master
with:
scan-type: "fs"
scan-ref: "."
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"
continue-on-error: true
- name: Upload Trivy results
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
continue-on-error: true
dependency-review:
name: Dependency Review
needs: detect
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v4
with:
fail-on-severity: moderate
# ===========================================================================
# STAGE 4: Trunk.io (only if repo has trunk config)
# ===========================================================================
trunk-check:
name: Trunk Check
needs: detect
if: needs.detect.outputs.has_ci_lint == 'true'
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Run trunk only if configured
run: |
if [ -f "trunk.yaml" ] && [ -d ".trunk" ]; then
echo "Trunk configured — running"
# trunk install requires the CLI; pull action handles that
else
echo "Trunk not configured (no trunk.yaml + .trunk/) — skipping"
exit 0
fi
- uses: trunk-io/trunk-action@v1
if: hashFiles('trunk.yaml', '.trunk/trunk.yaml') != ''
# ===========================================================================
# STAGE 5: Aggregation gate for branch protection
# ===========================================================================
ci:
name: CI
if: always()
needs:
- detect
- rust
- python
- go
- typescript
- security
- dependency-review
- trunk-check
runs-on: ubuntu-latest
steps:
- name: Aggregate
run: |
# All jobs are continue-on-error; this gate just confirms CI ran
# without crashing the runner. Lint/test results are advisory.
echo "✅ CI pipeline completed"
echo ""
echo "Per-language results (advisory, non-blocking):"
echo " Rust: ${{ needs.rust.result }}"
echo " Python: ${{ needs.python.result }}"
echo " Go: ${{ needs.go.result }}"
echo " TS/JS: ${{ needs.typescript.result }}"
echo " Security: ${{ needs.security.result }}"
echo " Dep review: ${{ needs.dependency-review.result }}"
echo " Trunk: ${{ needs.trunk-check.result }}"