Repository navigation
266 lines (245 loc) · 8.77 KB
/
Copy pathpr.yaml
File metadata and controls
266 lines (245 loc) · 8.77 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
# Pull Request Workflow
#
# This workflow orchestrates quality checks, tests, and security scans for
# pull requests using reusable workflows.
#
# Key Features:
# - PR title validation (conventional commits)
# - Code quality validation
# - Test suite execution
# - Security scanning
# - Concurrent execution handling
# - Automated feedback
#
# Process Stages:
# Jobs are grouped by scope and always-run vs path-gated:
#
# [Always run on every non-draft PR]
# 1. PR Title Validation:
# - Conventional commit format verification
# - Ensures proper changelog generation
#
# 2. Quality Checks:
# - Covers library (src/) and application/ via prek workspace mode
# - Code style, type checking, pre-commit hooks
#
# 3. Security:
# - Changed files scanning
# - Vulnerability detection
# - Security report generation
#
# [Library path-gated: src/, tests/, examples/, tools/, pyproject.toml, ...]
# 4. Testing:
# - Unit test execution
# - Integration testing
# - Coverage reporting
#
# [Application path-gated: application/**, .github/**]
# 5. Docker Image Build:
# - Determines if docker images need to be built based on event type and changed paths
# - Builds and uploads docker images as artifacts
#
# Required Secrets:
# - CODECOV_TOKEN: Coverage reporting token
#
# Example Usage:
# Automatically triggered on:
# 1. Pull requests to main branch
# 2. Pull requests to feature/* branches
# 3. Merge group events
#
# Note:
# - PR title validation only runs on actual pull requests
# - Individual commit messages are not validated (since PRs are squash merged)
# - Other checks run in parallel with PR title validation for faster feedback
# - PR title can be fixed later while tests are already running
# - Configured to cancel outdated runs when new commits are pushed
name: PR Checks
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: ["main", "feature/**", "release/**"]
merge_group:
branches: [main]
permissions: {} # No permissions by default on workflow level
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# PR title validation - only runs on actual pull requests, not merge groups
pr-title-check:
if: github.event_name == 'pull_request'
uses: $/.github/workflows/_reusable-pr-title-check.yaml
permissions:
contents: read # Required by the called workflow to checkout the repository
with:
python-version: "3.10"
# Code quality - covers both library (src/) and application/ via prek workspace mode
quality:
if: github.event.pull_request.draft != true
uses: $/.github/workflows/_reusable-code-quality.yaml
permissions:
contents: read # Required by the called workflow to checkout the repository
with:
python-version: "3.10"
# Security scanning
security:
if: github.event.pull_request.draft != true
uses: $/.github/workflows/_reusable-security-scan.yaml
permissions:
security-events: write # needed to upload results
contents: read
packages: read # needed to pull images for scanning
with:
tools: "semgrep,bandit,zizmor" # Security tools to run
scan-scope: "changed" # Only scan changed files
severity-level: "LOW" # Minimum severity to report
confidence-level: "HIGH" # High confidence to report
fail-on-findings: true # explicitly set
# Determines if test suite should run based on changed paths
check-library-paths:
name: Check if tests should run
runs-on: ubuntu-latest
outputs:
run_library: ${{ steps.check-library-paths.outputs.run }}
permissions:
contents: read # Required to checkout the repository
steps:
- name: Harden the runner (audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check paths
id: check-library-paths
uses: open-edge-platform/geti-ci/actions/check-paths@2ed3ce382d1dbd6db52c7c6b93ffdae280a1c06f # check-paths/v0.1.0
with:
files_yaml: |
test:
- src/**
- tests/**
- examples/**
- tools/**
- pyproject.toml
- uv.lock
- .pre-commit-config.yaml
- tox.ini
- .github/actions/pytest/**
- .github/workflows/pr.yaml
- .github/workflows/_reusable-code-quality.yaml
- .github/workflows/_reusable-test-suite.yaml
unit-tests:
needs: check-library-paths
if: needs.check-library-paths.outputs.run_library == 'true' && github.event.pull_request.draft != true
uses: $/.github/workflows/_reusable-test-suite.yaml
permissions:
contents: read # Required by the called workflow to checkout the repository
with:
test-type: "unit"
runner: "ubuntu-latest"
timeout: 30
enable-cache: "true"
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
integration-tests:
needs: check-library-paths
if: needs.check-library-paths.outputs.run_library == 'true' && github.event.pull_request.draft != true
uses: $/.github/workflows/_reusable-test-suite.yaml
permissions:
contents: read # Required by the called workflow to checkout the repository
with:
test-type: "integration"
runner: "self-hosted"
timeout: 60
enable-cache: "false"
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
# NOTE: When we have e2e or other tests, we can add them here.
library-checks-status:
name: Library checks status
needs:
- check-library-paths
- quality
- unit-tests
- integration-tests
runs-on: ubuntu-latest
env:
CHECKS: ${{ join(needs.*.result, ' ') }}
if: always() && !cancelled()
steps:
- name: Harden the runner (audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- name: Check jobs results
run: |
for check in ${CHECKS}; do
echo "::notice::check=${check}"
if [[ "$check" != "success" && "$check" != "skipped" ]]; then
echo "::error::Library checks failed. They must succeed before this pull request can be merged."
exit 1
fi
done
# Determines if docker images must be built based on event type and changed paths
# If push or workflow_dispatch -> always run
# If PR or merge_group -> run only if files in specified paths changed
check-paths:
name: Check if docker build job should run
runs-on: ubuntu-latest
outputs:
run_build: ${{ steps.check-paths.outputs.run }}
permissions:
contents: read # Required to checkout the repository
steps:
- name: Harden the runner (audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check paths
id: check-paths
uses: open-edge-platform/geti-ci/actions/check-paths@2ed3ce382d1dbd6db52c7c6b93ffdae280a1c06f # check-paths/v0.1.0
with:
files_yaml: |
test:
- application/**
- .github/**
# Docker image build job using reusable workflow
docker-build:
name: Build and upload docker image
needs: check-paths
if: needs.check-paths.outputs.run_build == 'true' && github.event.pull_request.draft != true
uses: $/.github/workflows/_reusable-docker-build.yaml
permissions:
contents: read
# write permissions are required to update PR comments with image sizes
pull-requests: write
docker-build-status:
name: Docker build status check
needs:
- check-paths
- docker-build
runs-on: ubuntu-latest
env:
CHECKS: ${{ join(needs.*.result, ' ') }}
if: always() && !cancelled()
steps:
- name: Harden the runner (audit all outbound calls)
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
with:
egress-policy: audit
- name: Check jobs results
run: |
for check in ${CHECKS}; do
echo "::notice::check=${check}"
if [[ "$check" != "success" && "$check" != "skipped" ]]; then
echo "::error::Build docker image status checks failed. They must succeed before this pull request can be merged."
exit 1
fi
done