-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (72 loc) · 2.7 KB
/
check-version.yml
File metadata and controls
84 lines (72 loc) · 2.7 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
name: Check version
on:
push:
branches:
- master
paths-ignore:
- README.md
- CHANGELOG.md
- .gitignore
- 'CITATION.cff'
pull_request:
branches:
- master
paths-ignore:
- README.md
- CHANGELOG.md
- .gitignore
- 'CITATION.cff'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Parse versions from pyproject.toml and CITATION.cff
id: versions
run: |
PYPROJECT_VER=$(grep -m1 '^version' pyproject.toml | sed 's/version\s*=\s*"\(.*\)"/\1/')
CITATION_VER=$(grep -m1 '^version:' CITATION.cff | sed 's/version:\s*//')
echo "pyproject=$PYPROJECT_VER" >> $GITHUB_OUTPUT
echo "citation=$CITATION_VER" >> $GITHUB_OUTPUT
echo "pyproject.toml version : $PYPROJECT_VER"
echo "CITATION.cff version : $CITATION_VER"
- name: Get latest git tag
id: tag
run: |
LATEST=$(git tag --sort=-version:refname | head -n1)
echo "tag=$LATEST" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST"
- name: Check versions
run: |
python3 - <<'EOF'
from packaging.version import Version
import sys
pyproject_ver = "${{ steps.versions.outputs.pyproject }}"
citation_ver = "${{ steps.versions.outputs.citation }}"
latest_tag = "${{ steps.tag.outputs.tag }}".lstrip("v")
ok = True
# --- 1. version in pyproject.toml be strictly greater than latest tag ---
if not latest_tag:
print("No existing tags found, skipping tag comparison.")
else:
current = Version(pyproject_ver)
latest = Version(latest_tag)
print(f"Latest tag: {latest}")
if current <= latest:
print(f"::error::Version in pyproject.toml (ground truth) {current} is not strictly greater than latest tag {latest}. Please bump the version in pyrpoject.toml.")
ok = False
else:
print(f"OK: pyproject.toml (ground truth): {current} > {latest}")
# --- 2. pyproject.toml and CITATION.cff must agree ---
if pyproject_ver != citation_ver:
print(f"::error::Version mismatch: pyproject.toml (ground truth) has {pyproject_ver} but CITATION.cff has {citation_ver}. Please make them match.")
ok = False
else:
print(f"OK: pyproject.toml and CITATION.cff both at {pyproject_ver}")
sys.exit(0 if ok else 1)
EOF