Skip to content

Commit c0b1b6b

Browse files
committed
Fixing pr-release for hatch logic
1 parent 1097255 commit c0b1b6b

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

.github/workflows/pr-preview.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
python -m pip install --upgrade pip
1919
pip install -e .
2020
pip install hatchling==1.27.0 hatch==1.14.0 hatch-vcs==0.4.0
21+
22+
- name: Inject full dynamic version
23+
run: python .hooks/sync_version.py --dev
24+
2125
- name: Get Hatch version
2226
id: version
2327
run: |
@@ -41,6 +45,9 @@ jobs:
4145
if: steps.version_check.outputs.exists != 'true'
4246
run: |
4347
hatch build
48+
- name: Reset __version__ to base version
49+
if: always()
50+
run: python .hooks/sync_version.py
4451

4552
- name: Publish to Test PyPI
4653
if: steps.version_check.outputs.exists != 'true'

.hooks/sync_versions.py renamed to .hooks/sync_version.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
PACKAGE_FILE = pathlib.Path("socketsecurity/__init__.py")
88
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
99

10-
def get_hatch_version():
11-
return subprocess.check_output(["hatch", "version"], text=True).strip()
10+
def get_hatch_version(full=False):
11+
raw = subprocess.check_output(["hatch", "version"], text=True).strip()
12+
if full:
13+
return raw
14+
return raw.split(".dev")[0].split("+")[0] # Just base version
1215

1316
def get_current_version():
1417
content = PACKAGE_FILE.read_text()
@@ -21,17 +24,18 @@ def update_version(new_version):
2124
PACKAGE_FILE.write_text(new_content)
2225

2326
def main():
24-
hatch_version = get_hatch_version()
27+
full_mode = "--dev" in sys.argv
28+
hatch_version = get_hatch_version(full=full_mode)
2529
current_version = get_current_version()
2630

2731
if not current_version:
28-
print("❌ Couldn't find __version__ in", PACKAGE_FILE)
32+
print(f"❌ Couldn't find __version__ in {PACKAGE_FILE}")
2933
return 1
3034

3135
if hatch_version != current_version:
32-
print(f"🔁 Syncing version: {current_version}{hatch_version}")
36+
print(f"🔁 Updating version: {current_version}{hatch_version}")
3337
update_version(hatch_version)
34-
return 1 # Exit 1 so pre-commit fails and shows diff
38+
return 1 if not full_mode else 0 # Fail locally to force re-add, but not in CI
3539

3640
print(f"✅ Version is in sync: {hatch_version}")
3741
return 0

docs/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 1. Clone the repo and create a virtualenv (Python 3.12+)
2+
python3.12 -m venv .venv
3+
source .venv/bin/activate
4+
5+
# 2. Install dependencies
6+
pip install --upgrade pip
7+
pip install .[dev]
8+
9+
# 3. Set up pre-commit hooks
10+
pre-commit install

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ dev = [
4646
"ruff>=0.3.0",
4747
"twine", # for building
4848
"pip-tools>=7.4.0", # for pip-compile
49+
"pre-commit",
50+
"hatch",
51+
"hatch-vcs"
4952
]
5053

5154
[project.scripts]

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.0.15'
2+
__version__ = '2.0.17.dev2+g1097255.d20250401'

0 commit comments

Comments
 (0)