Skip to content

Commit a23ab52

Browse files
authored
Merge pull request #56 from PalamaraLab/55-check-version-consistent
feat: check versioned files consistency (#55)
2 parents 6ea8c33 + 5d31c14 commit a23ab52

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/check-version.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Check that all files used in building project have consistent version number
3+
"""
4+
5+
import re
6+
7+
def _read_version_triplet(filename, regex):
8+
with open(filename) as file:
9+
for line in file:
10+
regex = re.compile(regex)
11+
match = re.search(regex, line)
12+
if match:
13+
major = int(match[1])
14+
minor = int(match[2])
15+
patch = int(match[3])
16+
triplet = (major, minor, patch)
17+
print(f" - {filename}: {triplet}")
18+
return triplet
19+
20+
raise ValueError(f"Cannot find valid version triplet in {filename}")
21+
22+
23+
if __name__ == "__main__":
24+
print("Checking project version files are consistent...")
25+
26+
cmake_version = _read_version_triplet("CMakeLists.txt", "project\(.* (\d+)\.(\d+)\.(\d+)\)")
27+
docs_version = _read_version_triplet("docs/conf.py", "release.*v(\d+)\.(\d+)\.(\d+)")
28+
pyproject_version = _read_version_triplet("pyproject.toml", "version.*\"(\d+)\.(\d+)\.(\d+)")
29+
30+
if cmake_version != docs_version:
31+
raise ValueError(f"CMake/docs mismatch: {cmake_version}/{docs_version}")
32+
33+
if cmake_version != pyproject_version:
34+
raise ValueError(f"CMake/pyproject mismatch: {cmake_version}/{pyproject_version}")
35+
36+
print(f"All versioned files match.")
37+
print("Done!")

.github/workflows/qa-checks.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Code quality checks"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
qa-checks:
13+
name: Python tests
14+
runs-on: ubuntu-22.04
15+
if: ${{ github.event_name == 'pull_request' || github.repository == 'PalamaraLab/arg-needle-lib' }}
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v5
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version: 3.13
24+
25+
- name: Run version consistency check
26+
run: |
27+
python .github/workflows/check-version.py

0 commit comments

Comments
 (0)