-
Notifications
You must be signed in to change notification settings - Fork 10
289 lines (257 loc) · 9.5 KB
/
Copy pathci-quality.yml
File metadata and controls
289 lines (257 loc) · 9.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
name: Quality Checks
on:
push:
branches: [ main, develop ]
paths:
- 'src/**'
- 'tests/**'
- 'pyproject.toml'
- 'requirements*.txt'
- 'uv.lock'
- '.ruff.toml'
- '.github/workflows/ci-quality.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'src/**'
- 'tests/**'
- 'pyproject.toml'
- 'requirements*.txt'
- 'uv.lock'
- '.ruff.toml'
- '.github/workflows/ci-quality.yml'
# pull_request_target is needed only for the auto-format-suggest job to call
# the PR Reviews API on fork PRs. All other jobs gate on event_name to avoid
# double execution.
pull_request_target:
branches: [ main, develop ]
paths:
- 'src/**'
- 'tests/**'
- 'pyproject.toml'
- 'requirements*.txt'
- 'uv.lock'
- '.ruff.toml'
- '.github/workflows/ci-quality.yml'
# Cancel in-progress runs when a new push arrives on the same branch/ref.
# The auto-format job is exempted via its own job-level concurrency block
# (cancel-in-progress: false) because it pushes a commit back to the branch —
# cancelling it mid-push could leave the branch in a partially formatted state.
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
config:
name: Configuration
uses: ./.github/workflows/shared-config.yml
quality-check:
name: Quality Standards
# Skip on pull_request_target — only auto-format-suggest needs that event.
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
needs: config
permissions:
contents: read
env:
AWS_DEFAULT_REGION: ${{ needs.config.outputs.aws-region }}
AWS_ACCESS_KEY_ID: ${{ needs.config.outputs.aws-access-key }}
AWS_SECRET_ACCESS_KEY: ${{ needs.config.outputs.aws-secret-key }}
ENVIRONMENT: ${{ needs.config.outputs.environment }}
TESTING: ${{ needs.config.outputs.testing-flag }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- name: Setup Python and UV
uses: ./.github/actions/setup-uv-fresh
with:
python-version: ${{ needs.config.outputs.default-python-version }}
cache-key-suffix: quality
- name: Run quality checks
run: |
if [ "${{ github.event_name }}" = "schedule" ]; then
make quality-check-all
else
make quality-check
fi
setup-cache:
name: Setup Cache
# Runs on both pull_request and pull_request_target — auto-format-suggest
# depends on it and needs to run on pull_request_target for fork PRs.
needs: config
uses: ./.github/workflows/cache-management.yml
with:
cache-type: dependencies
cache-key-base: quality-deps
python-version: ${{ needs.config.outputs.default-python-version }}
auto-format:
name: Auto-Format Code
# Same-repo PRs only. Fork PRs handled by auto-format-suggest below.
# Bot-actor guard prevents the job re-triggering on its own push.
if: |
github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.full_name == github.repository
&& github.actor != 'open-resource-broker-cicd[bot]'
runs-on: ubuntu-latest
needs: [config, setup-cache]
# Override the workflow-level concurrency so this job is never cancelled
# mid-run. If it were interrupted after `ruff` rewrites files but before
# `git push`, the PR branch would be left in a half-formatted state.
concurrency:
group: ci-auto-format-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.head_ref }}
# See semantic-release.yml for the rationale - the App-token URL
# set by the composite below must be the only credential source
# so the auto-format push lands as the ORB CICD App rather than
# falling back to github-actions[bot] via the persisted extraheader.
persist-credentials: false
- name: ORB CICD App token
id: cicd
uses: ./.github/actions/orb-cicd-app-token
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Setup UV with cache
uses: ./.github/actions/setup-uv-cached
with:
cache-key: ${{ needs.setup-cache.outputs.cache-key }}
fail-on-cache-miss: false
- name: Auto-format code
run: make format-fix
- name: Commit formatting changes
env:
GIT_AUTHOR_NAME: ${{ steps.cicd.outputs.committer-name }}
GIT_AUTHOR_EMAIL: ${{ steps.cicd.outputs.committer-email }}
GIT_COMMITTER_NAME: ${{ steps.cicd.outputs.committer-name }}
GIT_COMMITTER_EMAIL: ${{ steps.cicd.outputs.committer-email }}
run: |
git add .
if ! git diff --staged --quiet; then
git commit -m "style: auto-format code with ruff"
git push
fi
auto-format-suggest:
name: Auto-Format Suggestions
# Fork PRs: post formatted changes as PR review suggestions for the
# contributor to apply via the GitHub UI's "Commit suggestion" button.
# Uses pull_request_target so the GITHUB_TOKEN can call the PR Reviews API
# (POST /pulls/{id}/reviews) — pull_request fork-PR tokens cannot.
# The workflow file is evaluated at the base ref (safe); only the PR head
# code is checked out into a non-elevated working tree for formatting.
if: github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
needs: [config, setup-cache]
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout PR head
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.head.sha }}
# No token here — formatter does not need write access; this prevents
# untrusted PR code from authenticating with elevated permissions.
persist-credentials: false
- name: Setup UV with cache
uses: ./.github/actions/setup-uv-cached
with:
cache-key: ${{ needs.setup-cache.outputs.cache-key }}
fail-on-cache-miss: false
- name: Run formatter
run: make format-fix
- name: Post review suggestions
uses: reviewdog/action-suggester@2558ba17e65a9039e73764a73009fc05fef28a46 # v1.24.3
with:
tool_name: ruff
level: warning
fail_on_error: false
lint-ruff:
name: Ruff (Code Quality)
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
needs: [config, setup-cache]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Setup UV with cache
uses: ./.github/actions/setup-uv-cached
with:
cache-key: ${{ needs.setup-cache.outputs.cache-key }}
fail-on-cache-miss: false
- name: Check code quality
run: make ci-quality-ruff
lint-ruff-optional:
name: Ruff (Extended Checks)
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
needs: [config, setup-cache, lint-ruff]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Setup UV with cache
uses: ./.github/actions/setup-uv-cached
with:
cache-key: ${{ needs.setup-cache.outputs.cache-key }}
fail-on-cache-miss: false
- name: Extended linting (warnings)
run: make ci-quality-ruff-optional
continue-on-error: true
lint-pyright:
name: Type Checking (pyright)
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
needs: [config, setup-cache, lint-ruff]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Setup UV with cache
uses: ./.github/actions/setup-uv-cached
with:
cache-key: ${{ needs.setup-cache.outputs.cache-key }}
fail-on-cache-miss: false
- name: Run pyright type check
run: make ci-quality-pyright
arch-validation:
name: Architecture Validation
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
needs: [config, setup-cache, lint-ruff]
permissions:
contents: read
strategy:
matrix:
check: [cqrs, clean, imports, file-sizes]
include:
- check: cqrs
description: "CQRS Pattern Validation"
- check: clean
description: "Clean Architecture Dependencies"
- check: imports
description: "Import Validation"
- check: file-sizes
description: "File Size Compliance"
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Setup UV with cache
uses: ./.github/actions/setup-uv-cached
with:
cache-key: ${{ needs.setup-cache.outputs.cache-key }}
fail-on-cache-miss: false
- name: Run architecture validation (${{ matrix.description }})
run: make ci-arch-${{ matrix.check }}