-
Notifications
You must be signed in to change notification settings - Fork 3
235 lines (194 loc) · 6.96 KB
/
ci.yml
File metadata and controls
235 lines (194 loc) · 6.96 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
name: CI
on:
push:
branches: [ main, develop, "feat/**" ]
pull_request:
branches: [ main, develop, "feat/**" ]
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
security-events: write
actions: read
env:
UV_PYTHON: python
jobs:
lint:
name: Lint & Static Analysis (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
uses: astral-sh/setup-uv@v1
with:
enable-cache: true
cache-dependency-glob: |
uv.lock
pyproject.toml
- name: Sync dependencies
run: uv sync --dev --frozen
- name: Apply patched dependencies
run: |
uv pip install -p .venv/bin/python --no-deps "starlette==0.47.2"
- name: Ruff lint
run: uv run ruff check --output-format=github .
- name: Ruff format check
run: uv run ruff format --check .
- name: Mypy strict type checking
run: uv run mypy dlsite_classification/ --strict --show-error-codes
- name: Security check with Bandit
run: |
set -euo pipefail
TARGET="dlsite_classification"
EXCLUDES="tests,dlsite_classification_web,node_modules,.venv,venv,.env"
echo "🔍 Running Bandit security scan..."
# Generate JSON artifact
uv run bandit -r "$TARGET" -x "$EXCLUDES" -f json -o bandit-report.json --skip B101,B601 || true
# Generate human-readable summary
uv run bandit -r "$TARGET" -x "$EXCLUDES" --severity-level low --confidence-level medium \
--skip B101,B601 -f txt -o bandit-summary.txt || true
echo "=== Bandit Security Scan Summary ==="
exit_code=0
uv run bandit -r "$TARGET" -x "$EXCLUDES" --severity-level high --confidence-level medium --skip B101,B601 || exit_code=$?
if [ "$exit_code" -eq 1 ]; then
echo "❌ High severity security issues found. Please review and fix."
exit 1
elif [ "$exit_code" -eq 0 ]; then
echo "✅ No high severity security issues found."
else
echo "⚠️ Low/Medium severity issues detected. Review recommended but not blocking."
fi
- name: Upload Bandit reports
if: always()
uses: actions/upload-artifact@v4
with:
name: bandit-reports-${{ matrix.python-version }}
path: |
bandit-report.json
bandit-summary.txt
test:
name: Tests & Coverage (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
needs: lint
strategy:
fail-fast: false
matrix:
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
uses: astral-sh/setup-uv@v1
with:
enable-cache: true
cache-dependency-glob: |
uv.lock
pyproject.toml
- name: Sync dependencies
run: uv sync --dev --frozen
- name: Apply patched dependencies
run: |
uv pip install -p .venv/bin/python --no-deps "starlette==0.47.2"
- name: Run standardized tests
run: ./run_tests.sh --html
- name: Generate coverage XML report
run: uv run coverage xml
- name: Generate coverage summary
run: uv run coverage report --show-missing
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: coverage.xml
flags: python-${{ matrix.python-version }}
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
- name: Upload coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.python-version }}
path: |
coverage.xml
htmlcov
security:
name: Bandit Deep Scan
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Set up uv
uses: astral-sh/setup-uv@v1
with:
enable-cache: true
cache-dependency-glob: |
uv.lock
pyproject.toml
- name: Sync dependencies
run: uv sync --dev --frozen
- name: Apply patched dependencies
run: |
uv pip install -p .venv/bin/python --no-deps "starlette==0.47.2"
- name: Comprehensive Bandit scan
run: |
set -euo pipefail
TARGET="dlsite_classification"
EXCLUDES="tests,dlsite_classification_web,node_modules,.venv,venv,.env"
echo "🔐 Running comprehensive security analysis..."
uv run bandit -r "$TARGET" -x "$EXCLUDES" -f json -o bandit-detailed.json -v --skip B101,B601 || true
uv run bandit -r "$TARGET" -x "$EXCLUDES" -f txt -o bandit-detailed.txt --skip B101,B601 || true
uv run bandit -r "$TARGET" -x "$EXCLUDES" -f xml -o bandit-detailed.xml --skip B101,B601 || true
echo "=== High Confidence Issues ==="
uv run bandit -r "$TARGET" -x "$EXCLUDES" --confidence-level high --severity-level medium --skip B101,B601 || true
echo "=== Full Issue Summary ==="
uv run bandit -r "$TARGET" -x "$EXCLUDES" --confidence-level low --severity-level low --skip B101,B601 || true
echo "📈 Security scan artifacts generated"
- name: Upload comprehensive Bandit reports
if: always()
uses: actions/upload-artifact@v4
with:
name: bandit-detailed-reports
path: |
bandit-detailed.json
bandit-detailed.txt
bandit-detailed.xml
summary:
name: Pipeline Summary
runs-on: ubuntu-latest
needs: [ lint, test, security ]
if: always()
steps:
- name: Aggregate results
run: |
echo "=== CI Results Summary ==="
echo "Lint: ${{ needs.lint.result }}"
echo "Test: ${{ needs.test.result }}"
echo "Security: ${{ needs.security.result }}"
if [ "${{ needs.lint.result }}" = "success" ] && \
[ "${{ needs.test.result }}" = "success" ] && \
[ "${{ needs.security.result }}" = "success" ]; then
echo "✅ All checks passed!"
exit 0
else
echo "❌ Some checks failed. Please review the errors above."
exit 1
fi