Skip to content

Commit ae28d50

Browse files
authored
Set version from git tag (#13)
* update version from tag * let pre-commit show the diff on failure
1 parent f5c3d5d commit ae28d50

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

.github/workflows/build-package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
python -m pip install --upgrade pip
2424
pip install build
2525
26+
- name: Update version from git tag
27+
run: python buildtools/update_version.py
28+
2629
- name: Build package
2730
run: python -m build
2831

.github/workflows/pre-commit-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
2525
- name: Run pre-commit
2626
id: pre-commit
27-
run: pre-commit run --all-files
27+
run: pre-commit run --all-files --show-diff-on-failure
2828
continue-on-error: true
2929

3030
- name: Check pre-commit result

buildtools/update_version.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
import subprocess
5+
import sys
6+
7+
8+
def get_latest_version():
9+
try:
10+
# Get the latest tag
11+
result = subprocess.run(
12+
["git", "describe", "--tags", "--abbrev=0"],
13+
capture_output=True,
14+
text=True,
15+
check=True,
16+
)
17+
tag = result.stdout.strip()
18+
19+
# Extract version number from tag (remove 'v' prefix)
20+
version = tag.lstrip("v")
21+
return version
22+
except subprocess.CalledProcessError:
23+
print("Error: No git tags found", file=sys.stderr)
24+
sys.exit(1)
25+
26+
27+
def update_setup_py(version):
28+
setup_py_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "setup.py")
29+
with open(setup_py_path, "r") as f:
30+
content = f.read()
31+
32+
# Replace version string
33+
new_content = re.sub(r'version="[^"]*"', f'version="{version}"', content)
34+
35+
with open(setup_py_path, "w") as f:
36+
f.write(new_content)
37+
38+
39+
def main():
40+
version = get_latest_version()
41+
update_setup_py(version)
42+
print(f"Updated setup.py with version {version}")
43+
44+
45+
if __name__ == "__main__":
46+
main()

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
setup(
44
name="lipomerge",
5-
version="0.1.0",
5+
version="0.0.0",
66
author="Falko Axmann",
77
description="A tool to merge directories containing static libraries or other binaries into universal binaries.",
88
long_description=open("README.md").read(),
99
long_description_content_type="text/markdown",
1010
url="https://github.com/faaxm/lipomerge",
11+
license_file="License.txt",
1112
packages=find_packages(),
1213
py_modules=["lipomerge"],
1314
classifiers=[

0 commit comments

Comments
 (0)