-
Notifications
You must be signed in to change notification settings - Fork 3
223 lines (188 loc) · 7.02 KB
/
ci.yml
File metadata and controls
223 lines (188 loc) · 7.02 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
---
name: CI
on: # yamllint disable-line rule:truthy
pull_request:
push:
branches:
- main
- develop
- v*
jobs:
unit-tests:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest, macos-latest]
python:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
exclude:
# Python 3.10 has issues on macOS M1 runners (missing gettext/libintl)
- runs-on: macos-latest
python: '3.10'
name: "Unit tests • ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
runs-on: ${{ matrix.runs-on }}
if: >-
(github.event_name != 'pull_request'
|| (github.event_name == 'pull_request' && github.event.pull_request.merged != true))
steps:
- uses: actions/checkout@v4
- name: Get history and tags for SCM versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
architecture: 'x64'
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Prepare env
run: python -m pip install -U pytest-github-actions-annotate-failures wheel build
- name: Build and install package
run: python -m pip install -e .[test]
- name: Run Python tests
run: python -m pytest -v --cov=cmake_pc_hooks --cov-report=xml --cov-report=term-missing --cov-branch
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Save coverage report
if: matrix.python == '3.11' && runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.xml
retention-days: 1
system-tests:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest, macos-latest]
python:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
exclude:
# Python 3.10 has issues on macOS M1 runners (missing gettext/libintl)
- runs-on: macos-latest
python: '3.10'
name: "System tests ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
runs-on: ${{ matrix.runs-on }}
needs: unit-tests
if: >-
(github.event_name != 'pull_request'
|| (github.event_name == 'pull_request' && github.event.pull_request.merged != true))
steps:
- uses: actions/checkout@v4
- name: Get history and tags for SCM versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
architecture: 'x64'
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Prepare env
run: python -m pip install -U pytest-github-actions-annotate-failures wheel build
- name: Prepare env (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y clang clang-tidy cppcheck iwyu
python -m pip install pytest-github-actions-annotate-failures pre-commit cpplint lizard
- name: Prepare env (Mac OS)
if: runner.os == 'macOS'
run: |
brew install llvm cppcheck cpplint include-what-you-use pre-commit gnu-sed lizard-analyzer
ln -s "$(brew --prefix llvm)/bin/clang-tidy" /usr/local/bin/clang-tidy
# yamllint disable rule:line-length
- name: Prepare env (Windows)
if: runner.os == 'Windows'
run: |
choco install -y llvm ninja
Import-Module "${ENV:ChocolateyInstall}\helpers\chocolateyProfile.psm1"
Update-SessionEnvironment
# Restore Python to PATH after Update-SessionEnvironment (it resets PATH from system)
$env:PATH = "$env:pythonLocation;$env:pythonLocation\Scripts;$env:PATH"
# Install cppcheck via pip (choco package is broken, pip wheel works correctly)
python -m pip install pre-commit cpplint lizard cppcheck
Get-Command @("python", "clang-format", "clang-tidy", "cppcheck", "cpplint", "lizard", "pre-commit")
# Enable MSVC dev command AFTER chocolatey packages are installed to avoid
# Update-SessionEnvironment overwriting MSVC environment variables
- name: Enable Developer Command Prompt
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1.13.0
# Restore Python to front of PATH after MSVC setup
# (MSVC's vcvarsall.bat prepends paths including VS's bundled Python 3.9,
# which conflicts with our Python 3.10+ requirement)
- name: Restore Python PATH
if: runner.os == 'Windows'
run: |
"$env:pythonLocation" >> $env:GITHUB_PATH
"$env:pythonLocation\Scripts" >> $env:GITHUB_PATH
# Ensure python3 also points to the correct Python (pre-commit looks for python3)
if (-not (Test-Path "$env:pythonLocation\python3.exe")) {
Copy-Item "$env:pythonLocation\python.exe" "$env:pythonLocation\python3.exe"
}
- name: Build and install package
run: python -m pip install -e .[test]
- name: Run test (Unix)
if: runner.os != 'Windows'
env:
LOGLEVEL: DEBUG
run: ./tests/run_tests.sh
- name: Run test (Windows)
if: runner.os == 'Windows'
env:
CC: cl
CXX: cl
LOGLEVEL: DEBUG
# Use a fresh pre-commit cache to avoid Python version mismatch
PRE_COMMIT_HOME: ${{ runner.temp }}/pre-commit-cache
run: ./tests/run_tests.ps1
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
needs: unit-tests
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch coverage report
uses: actions/download-artifact@v4
with:
name: coverage
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
codacy:
name: Codacy coverage
runs-on: ubuntu-latest
needs: unit-tests
steps:
- name: Fetch coverage report
uses: actions/download-artifact@v4
with:
name: coverage
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.xml
finish:
needs: [unit-tests, system-tests, sonarcloud, codacy]
runs-on: ubuntu-latest
name: Finish CI checks
steps:
- name: All tests pass
run: echo 'OK'