-
Notifications
You must be signed in to change notification settings - Fork 0
218 lines (194 loc) · 8.34 KB
/
ci.yml
File metadata and controls
218 lines (194 loc) · 8.34 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
name: CI
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
env:
PYTHON_VERSION: ${{ vars.CI_PYTHON_VERSION || '3.12' }}
PYTHON_TEST_VERSIONS: ${{ vars.CI_PYTHON_TEST_VERSIONS || '["3.11","3.12","3.13"]' }}
PYTHON_INSTALL_SPEC: ${{ vars.CI_PYTHON_INSTALL_SPEC || '.[dev]' }}
PYTHON_COMPILE_FILES: ${{ vars.CI_PYTHON_COMPILE_FILES || '' }}
PYTHON_COVERAGE_TARGET: ${{ vars.CI_PYTHON_COVERAGE_TARGET || '' }}
PYTHON_COVERAGE_THRESHOLD: ${{ vars.CI_PYTHON_COVERAGE_THRESHOLD || '85' }}
FRONTEND_NODE_VERSION: ${{ vars.CI_FRONTEND_NODE_VERSION || '22' }}
FRONTEND_WORKDIR: ${{ vars.CI_FRONTEND_WORKDIR || 'frontend' }}
jobs:
# ── Detect project layout ──────────────────────────────────────────
detect-stack:
name: Detect stack
runs-on: ubuntu-latest
outputs:
has-python: ${{ steps.detect.outputs.has-python }}
has-frontend: ${{ steps.detect.outputs.has-frontend }}
has-e2e: ${{ steps.detect.outputs.has-e2e }}
has-docker: ${{ steps.detect.outputs.has-docker }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Detect components
id: detect
run: |
has_python=false
has_frontend=false
has_e2e=false
has_docker=false
if [ -f pyproject.toml ] || [ -f setup.py ] || [ -f requirements.txt ]; then
has_python=true
fi
if [ -f "${FRONTEND_WORKDIR}/package.json" ]; then
has_frontend=true
fi
if [ -f "${FRONTEND_WORKDIR}/playwright.config.ts" ] || [ -f "${FRONTEND_WORKDIR}/playwright.config.js" ] || [ -f "${FRONTEND_WORKDIR}/playwright.config.mjs" ] || [ -f "${FRONTEND_WORKDIR}/playwright.config.cjs" ]; then
has_e2e=true
fi
if [ -f Dockerfile ]; then
has_docker=true
fi
echo "has-python=${has_python}" >> "$GITHUB_OUTPUT"
echo "has-frontend=${has_frontend}" >> "$GITHUB_OUTPUT"
echo "has-e2e=${has_e2e}" >> "$GITHUB_OUTPUT"
echo "has-docker=${has_docker}" >> "$GITHUB_OUTPUT"
# ── Python ────────────────────────────────────────────────────────
py-lint:
name: Python Lint
if: needs.detect-stack.outputs.has-python == 'true'
needs: [detect-stack]
uses: ./.github/workflows/python-lint.yml
with:
python-version: ${{ vars.CI_PYTHON_VERSION || '3.12' }}
install-spec: ${{ vars.CI_PYTHON_INSTALL_SPEC || '.[dev]' }}
py-build:
name: Python Build
if: needs.detect-stack.outputs.has-python == 'true'
needs: [detect-stack]
uses: ./.github/workflows/python-ci.yml
with:
python-version: ${{ vars.CI_PYTHON_VERSION || '3.12' }}
install-spec: ${{ vars.CI_PYTHON_INSTALL_SPEC || '.[dev]' }}
compile-files: ${{ vars.CI_PYTHON_COMPILE_FILES || '' }}
py-test:
name: Python Test
if: needs.detect-stack.outputs.has-python == 'true'
needs: [detect-stack]
uses: ./.github/workflows/python-tests.yml
with:
python-versions: ${{ vars.CI_PYTHON_TEST_VERSIONS || '["3.11","3.12","3.13"]' }}
install-spec: ${{ vars.CI_PYTHON_INSTALL_SPEC || '.[dev]' }}
coverage-target: ${{ vars.CI_PYTHON_COVERAGE_TARGET || '' }}
coverage-threshold: ${{ fromJSON(vars.CI_PYTHON_COVERAGE_THRESHOLD || '85') }}
# ── Frontend ──────────────────────────────────────────────────────
fe-lint:
name: Frontend Lint
if: needs.detect-stack.outputs.has-frontend == 'true'
needs: [detect-stack]
uses: ./.github/workflows/frontend-lint.yml
with:
node-version: ${{ vars.CI_FRONTEND_NODE_VERSION || '22' }}
working-directory: ${{ vars.CI_FRONTEND_WORKDIR || 'frontend' }}
fe-build:
name: Frontend Build
if: needs.detect-stack.outputs.has-frontend == 'true'
needs: [detect-stack]
uses: ./.github/workflows/frontend-build.yml
with:
node-version: ${{ vars.CI_FRONTEND_NODE_VERSION || '22' }}
working-directory: ${{ vars.CI_FRONTEND_WORKDIR || 'frontend' }}
fe-unit:
name: Frontend Unit
if: needs.detect-stack.outputs.has-frontend == 'true'
needs: [detect-stack]
uses: ./.github/workflows/frontend-unit.yml
with:
node-version: ${{ vars.CI_FRONTEND_NODE_VERSION || '22' }}
working-directory: ${{ vars.CI_FRONTEND_WORKDIR || 'frontend' }}
fe-e2e:
name: Frontend E2E
if: needs.detect-stack.outputs.has-frontend == 'true' && needs.detect-stack.outputs.has-e2e == 'true' && needs.detect-stack.outputs.has-python == 'true'
needs: [detect-stack]
uses: ./.github/workflows/frontend-e2e.yml
with:
python-version: ${{ vars.CI_PYTHON_VERSION || '3.12' }}
node-version: ${{ vars.CI_FRONTEND_NODE_VERSION || '22' }}
install-spec: ${{ vars.CI_PYTHON_INSTALL_SPEC || '.[dev]' }}
working-directory: ${{ vars.CI_FRONTEND_WORKDIR || 'frontend' }}
# ── Security ──────────────────────────────────────────────────────
secrets-scan:
name: Secrets
needs: [detect-stack]
uses: ./.github/workflows/python-gitleaks.yml
secrets:
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
quality-gate:
name: Quality gate
if: always()
needs: [detect-stack, py-lint, py-build, py-test, fe-lint, fe-build, fe-unit, fe-e2e, secrets-scan]
runs-on: ubuntu-latest
steps:
- name: Check required job results
env:
PY_LINT: ${{ needs.py-lint.result }}
PY_BUILD: ${{ needs.py-build.result }}
PY_TEST: ${{ needs.py-test.result }}
FE_LINT: ${{ needs.fe-lint.result }}
FE_BUILD: ${{ needs.fe-build.result }}
FE_UNIT: ${{ needs.fe-unit.result }}
FE_E2E: ${{ needs.fe-e2e.result }}
SECRETS_SCAN: ${{ needs.secrets-scan.result }}
run: |
results=("$PY_LINT" "$PY_BUILD" "$PY_TEST" "$FE_LINT" "$FE_BUILD" "$FE_UNIT" "$FE_E2E" "$SECRETS_SCAN")
for result in "${results[@]}"; do
if [ "$result" = "failure" ] || [ "$result" = "cancelled" ]; then
exit 1
fi
done
docker-build:
name: Docker Build
if: github.event_name == 'pull_request' && needs.detect-stack.outputs.has-docker == 'true'
needs: [detect-stack, quality-gate]
uses: ./.github/workflows/build-and-push.yml
with:
push-image: false
permissions:
contents: read
docker-push:
name: Docker Push
if: |
needs.detect-stack.outputs.has-docker == 'true' &&
github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
needs: [detect-stack, quality-gate]
uses: ./.github/workflows/build-and-push.yml
with:
push-image: true
environment: ${{ github.ref == 'refs/heads/main' && 'staging' || 'production' }}
permissions:
contents: read
packages: write
deploy-staging:
name: Deploy Staging
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.docker-push.result == 'success'
needs: [detect-stack, quality-gate, docker-push]
uses: ./.github/workflows/deploy-staging.yml
with:
source-commit-sha: ${{ github.sha }}
secrets: inherit
# ── Release ───────────────────────────────────────────────────────
release:
name: Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && (needs.docker-push.result == 'success' || needs.docker-push.result == 'skipped')
needs: [detect-stack, quality-gate, docker-push]
uses: ./.github/workflows/python-release.yml
permissions:
contents: write
deploy-production:
name: Deploy Production
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && needs.docker-push.result == 'success'
needs: [detect-stack, quality-gate, docker-push]
uses: ./.github/workflows/deploy-production.yml
with:
image-tag: ${{ github.ref_name }}
secrets: inherit