77 - ' pyproject.toml'
88
99jobs :
10- publish-to-pypi :
10+ publish :
1111 runs-on : ubuntu-latest
1212 steps :
1313 - name : Checkout code
@@ -16,45 +16,49 @@ jobs:
1616 - name : Set up Python
1717 uses : actions/setup-python@v5
1818 with :
19- python-version : ' 3.11 '
19+ python-version : ' 3.13 '
2020
2121 - name : Install uv
2222 run : |
2323 pip install uv
2424
25- - name : Install build dependencies with uv
25+ - name : Install dependencies
2626 run : |
27- uv pip install build toml requests packaging
27+ uv sync
2828
2929 - name : Get current version from pyproject.toml
3030 id : get_version
3131 run : |
32- python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])" > version.txt
32+ uv run python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])" > version.txt
3333 echo "version=$(cat version.txt)" >> $GITHUB_OUTPUT
3434
3535 - name : Get latest version from PyPI
3636 id : get_latest
3737 run : |
38- PKG_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
39- curl -s https://pypi.org/pypi/$PKG_NAME/json | \
40- python -c "import sys, json; print(json.load(sys.stdin)['info']['version']) if sys.stdin.read() else print('0.0.0')" > latest.txt
41- echo "latest=$(cat latest.txt)" >> $GITHUB_OUTPUT
38+ PKG_NAME=$(uv run python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
39+ LATEST_VERSION=$(curl -s https://pypi.org/pypi/$PKG_NAME/json | uv run python -c "import sys, json; data = json.load(sys.stdin); print(data['info']['version']) if 'info' in data else print('0.0.0')" 2>/dev/null || echo "0.0.0")
40+ echo "latest=$LATEST_VERSION" >> $GITHUB_OUTPUT
4241
4342 - name : Compare versions and set publish flag
4443 id : check_version
4544 run : |
46- python -c "from packaging.version import parse; import os; v1 = parse(os.environ['VERSION']); v2 = parse(os.environ['LATEST']); print('::set-output name=publish::' + str(v1 > v2))" \
47- VERSION=${{ steps.get_version.outputs.version }} LATEST=${{ steps.get_latest.outputs.latest }} > publish.txt
48- echo "publish=$(cat publish.txt | tail -n1 | cut -d'=' -f2)" >> $GITHUB_OUTPUT
45+ SHOULD_PUBLISH=$(uv run python -c "
46+ from packaging.version import parse
47+ import os
48+ current = parse('${{ steps.get_version.outputs.version }}')
49+ latest = parse('${{ steps.get_latest.outputs.latest }}')
50+ print('true' if current > latest else 'false')
51+ ")
52+ echo "publish=$SHOULD_PUBLISH" >> $GITHUB_OUTPUT
4953
5054 - name : Build package
51- if : steps.check_version.outputs.publish == 'True'
52- run : uv pip run -m build
55+ if : steps.check_version.outputs.publish == 'true'
56+ run : |
57+ uv build --sdist --wheel
5358
5459 - name : Publish to PyPI
55- if : steps.check_version.outputs.publish == 'True'
56- uses : pypa/gh-action-pypi-publish@release/v1
57- with :
58- user : ${{ secrets.PYPI_USERNAME }}
59- password : ${{ secrets.PYPI_PASSWORD }}
60- # Alternatively, use 'password: ${{ secrets.PYPI_API_TOKEN }}' if using an API token
60+ if : steps.check_version.outputs.publish == 'true'
61+ env :
62+ PYPI_TOKEN : ${{ secrets.PYPI_TOKEN }}
63+ run : |
64+ uv publish --token $PYPI_TOKEN
0 commit comments