Skip to content

Commit 74712ea

Browse files
committed
Updated release workflows for hatchling build
1 parent 44298a2 commit 74712ea

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

.github/workflows/pr-preview.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,11 @@ jobs:
1818
python -m pip install --upgrade pip
1919
pip install -e .
2020
21-
- name: Set preview version
21+
- name: Get Hatch version
22+
id: version
2223
run: |
23-
BASE_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)")
24-
PREVIEW_VERSION="${BASE_VERSION}.dev${{ github.event.pull_request.number }}${{ github.event.pull_request.commits }}"
25-
echo "VERSION=${PREVIEW_VERSION}" >> $GITHUB_ENV
26-
27-
# Update version in __init__.py
28-
echo "__version__ = \"${PREVIEW_VERSION}\"" > socketsecurity/__init__.py.tmp
29-
cat socketsecurity/__init__.py | grep -v "__version__" >> socketsecurity/__init__.py.tmp
30-
mv socketsecurity/__init__.py.tmp socketsecurity/__init__.py
31-
32-
# Verify the change
33-
echo "Updated version in __init__.py:"
34-
python -c "from socketsecurity import __version__; print(__version__)"
24+
VERSION=$(hatch version)
25+
echo "VERSION=$VERSION" >> $GITHUB_ENV
3526
3627
- name: Check if version exists on Test PyPI
3728
id: version_check
@@ -49,23 +40,14 @@ jobs:
4940
- name: Build package
5041
if: steps.version_check.outputs.exists != 'true'
5142
run: |
52-
pip install build
53-
python -m build
54-
55-
- name: Restore original version
56-
if: always()
57-
run: |
58-
BASE_VERSION=$(echo $VERSION | cut -d'.' -f1-3)
59-
echo "__version__ = \"${BASE_VERSION}\"" > socketsecurity/__init__.py.tmp
60-
cat socketsecurity/__init__.py | grep -v "__version__" >> socketsecurity/__init__.py.tmp
61-
mv socketsecurity/__init__.py.tmp socketsecurity/__init__.py
43+
pip install hatchling
44+
hatch build
6245
6346
- name: Publish to Test PyPI
6447
if: steps.version_check.outputs.exists != 'true'
6548
uses: pypa/[email protected]
6649
with:
6750
repository-url: https://test.pypi.org/legacy/
68-
password: ${{ secrets.TEST_PYPI_TOKEN }}
6951
verbose: true
7052

7153
- name: Comment on PR

.github/workflows/release.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Release
22
on:
3-
push:
4-
tags:
5-
- 'v*'
3+
release:
4+
types: [published]
65

76
jobs:
87
release:
@@ -22,10 +21,10 @@ jobs:
2221
- name: Get Version
2322
id: version
2423
run: |
25-
RAW_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)")
24+
RAW_VERSION=$(hatch version)
2625
echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV
2726
if [ "v$RAW_VERSION" != "${{ github.ref_name }}" ]; then
28-
echo "Error: Git tag (${{ github.ref_name }}) does not match package version (v$RAW_VERSION)"
27+
echo "Error: Git tag (${{ github.ref_name }}) does not match hatch version (v$RAW_VERSION)"
2928
exit 1
3029
fi
3130
@@ -57,14 +56,12 @@ jobs:
5756
- name: Build package
5857
if: steps.version_check.outputs.pypi_exists != 'true'
5958
run: |
60-
pip install build
61-
python -m build
59+
pip install hatchling
60+
hatch build
6261
6362
- name: Publish to PyPI
6463
if: steps.version_check.outputs.pypi_exists != 'true'
6564
uses: pypa/[email protected]
66-
with:
67-
password: ${{ secrets.PYPI_TOKEN }}
6865

6966
- name: Login to Docker Hub
7067
uses: docker/login-action@v3

0 commit comments

Comments
 (0)