Skip to content

Commit d3696fc

Browse files
committed
fix: resolve Windows encoding and git metadata issues
- Replace Unicode checkmarks with ASCII [OK] for Windows cp1252 compatibility - Add explicit git tag fetching in all workflows (fetch-tags: true) - Add git fetch --force --tags step to ensure tags are available - Improve version detection fallback logic in update_versions.py - Add support for GITHUB_REF_NAME in publish workflows for release tags - Handle edge cases where setuptools-scm can't detect version Fixes: - UnicodeEncodeError on Windows when running update_versions.py - setuptools-scm 'not a git repository' errors in CI - Missing git tags during checkout in workflows
1 parent e5cbe7b commit d3696fc

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

.github/workflows/build_jar.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ jobs:
1717
- uses: actions/checkout@v3
1818
with:
1919
fetch-depth: 0 # Fetch all history for version detection
20+
fetch-tags: true # Explicitly fetch tags
21+
22+
- name: Fetch git tags
23+
run: git fetch --force --tags
2024

2125
- name: Set up Python (for version script)
2226
uses: actions/setup-python@v5

.github/workflows/build_wheels.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
name: Check out
2626
with:
2727
fetch-depth: 0 # Fetch all history for setuptools-scm
28+
fetch-tags: true # Explicitly fetch tags
29+
30+
- name: Fetch git tags
31+
run: git fetch --force --tags
32+
shell: bash
2833

2934
- uses: ilammy/msvc-dev-cmd@v1
3035
name: Add MSVS Path
@@ -92,6 +97,11 @@ jobs:
9297
name: Check out
9398
with:
9499
fetch-depth: 0 # Fetch all history for setuptools-scm
100+
fetch-tags: true # Explicitly fetch tags
101+
102+
- name: Fetch git tags
103+
run: git fetch --force --tags
104+
shell: bash
95105

96106
- uses: ilammy/msvc-dev-cmd@v1
97107
name: Add MSVS Path

.github/workflows/publish_pypi.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ jobs:
2323
name: Check out
2424
with:
2525
fetch-depth: 0 # Fetch all history for setuptools-scm
26+
fetch-tags: true # Explicitly fetch tags
27+
28+
- name: Fetch git tags
29+
run: git fetch --force --tags
30+
shell: bash
2631

2732
- uses: ilammy/msvc-dev-cmd@v1
2833
name: Add MSVS Path
@@ -35,7 +40,14 @@ jobs:
3540
- name: Update version files
3641
run: |
3742
python -m pip install setuptools-scm
38-
python scripts/update_versions.py
43+
# Extract version from tag name if this is a release
44+
if [ -n "$GITHUB_REF_NAME" ] && [[ "$GITHUB_REF_NAME" == v* ]]; then
45+
VERSION="${GITHUB_REF_NAME#v}"
46+
echo "Using release version: $VERSION"
47+
python scripts/update_versions.py --version "$VERSION"
48+
else
49+
python scripts/update_versions.py
50+
fi
3951
shell: bash
4052

4153
- name: Install cibuildwheel
@@ -93,6 +105,11 @@ jobs:
93105
name: Check out
94106
with:
95107
fetch-depth: 0 # Fetch all history for setuptools-scm
108+
fetch-tags: true # Explicitly fetch tags
109+
110+
- name: Fetch git tags
111+
run: git fetch --force --tags
112+
shell: bash
96113

97114
- uses: ilammy/msvc-dev-cmd@v1
98115
name: Add MSVS Path
@@ -105,7 +122,14 @@ jobs:
105122
- name: Update version files
106123
run: |
107124
python -m pip install setuptools-scm
108-
python scripts/update_versions.py
125+
# Extract version from tag name if this is a release
126+
if [ -n "$GITHUB_REF_NAME" ] && [[ "$GITHUB_REF_NAME" == v* ]]; then
127+
VERSION="${GITHUB_REF_NAME#v}"
128+
echo "Using release version: $VERSION"
129+
python scripts/update_versions.py --version "$VERSION"
130+
else
131+
python scripts/update_versions.py
132+
fi
109133
shell: bash
110134

111135
- name: Install cibuildwheel

scripts/update_versions.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ def get_version_from_scm():
2222
"""Get version from setuptools-scm."""
2323
try:
2424
from setuptools_scm import get_version
25-
version = get_version(root='..')
25+
version = get_version(root='..', fallback_version='0.0.0')
2626
# Extract base version (remove dev/local version identifiers)
2727
base_version = version.split('+')[0].split('.dev')[0]
28+
# Don't return if it's the fallback version
29+
if base_version == '0.0.0':
30+
print("Warning: setuptools-scm returned fallback version, trying git directly", file=sys.stderr)
31+
return None
2832
return base_version
2933
except ImportError:
3034
print("Warning: setuptools-scm not installed, trying git directly", file=sys.stderr)
@@ -37,28 +41,50 @@ def get_version_from_scm():
3741
def get_version_from_git():
3842
"""Get version from git tags as fallback."""
3943
import subprocess
44+
45+
# Try to get the latest tag
4046
try:
4147
result = subprocess.run(
4248
['git', 'describe', '--tags', '--abbrev=0'],
4349
capture_output=True,
4450
text=True,
45-
check=True
51+
check=True,
52+
cwd=Path(__file__).parent.parent
4653
)
4754
version = result.stdout.strip()
4855
# Remove 'v' prefix if present
4956
if version.startswith('v'):
5057
version = version[1:]
5158
return version
59+
except subprocess.CalledProcessError:
60+
# If no tags, try to get from git tag list
61+
try:
62+
result = subprocess.run(
63+
['git', 'tag', '--sort=-version:refname'],
64+
capture_output=True,
65+
text=True,
66+
check=True,
67+
cwd=Path(__file__).parent.parent
68+
)
69+
tags = result.stdout.strip().split('\n')
70+
if tags and tags[0]:
71+
version = tags[0]
72+
if version.startswith('v'):
73+
version = version[1:]
74+
return version
75+
except Exception:
76+
pass
5277
except Exception as e:
53-
print(f"Error: Could not get version from git: {e}", file=sys.stderr)
54-
return None
78+
print(f"Warning: Could not get version from git: {e}", file=sys.stderr)
79+
80+
return None
5581

5682

5783
def write_version_file(version, root_dir):
5884
"""Write VERSION file for CMake."""
5985
version_file = root_dir / 'VERSION'
6086
version_file.write_text(version + '\n')
61-
print(f" Updated {version_file} to {version}")
87+
print(f"[OK] Updated {version_file} to {version}")
6288

6389

6490
def update_pom_xml(version, root_dir):
@@ -81,7 +107,7 @@ def update_pom_xml(version, root_dir):
81107
return
82108

83109
pom_file.write_text(new_content)
84-
print(f" Updated {pom_file} to {version}")
110+
print(f"[OK] Updated {pom_file} to {version}")
85111

86112

87113
def main():
@@ -116,7 +142,7 @@ def main():
116142
write_version_file(version, root_dir)
117143
update_pom_xml(version, root_dir)
118144

119-
print(f"\n All version files updated to {version}")
145+
print(f"\n[OK] All version files updated to {version}")
120146

121147

122148
if __name__ == '__main__':

0 commit comments

Comments
 (0)