|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + publish: |
| 12 | + name: Build and publish |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v4 |
| 23 | + with: |
| 24 | + python-version: '3.11' |
| 25 | + |
| 26 | + - name: Ensure PYPI token is available |
| 27 | + env: |
| 28 | + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
| 29 | + run: | |
| 30 | + if [ -z "$PYPI_API_TOKEN" ]; then |
| 31 | + echo "Missing secret: PYPI_API_TOKEN" >&2 |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +
|
| 35 | + - name: Install build tools |
| 36 | + run: python -m pip install --upgrade pip hatch twine |
| 37 | + |
| 38 | + - name: Build distributions |
| 39 | + run: hatch build |
| 40 | + |
| 41 | + - name: Create and push tag |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + version=$(python -c "import re,io;print(re.search(r'__version__\s*=\s*[\'\"]([^\'\"]+)[\'\"]', open('src/dander/__about__.py').read()).group(1))") |
| 46 | + echo "Version: $version" |
| 47 | + git config user.name "github-actions[bot]" |
| 48 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 49 | + git tag -a "v$version" -m "Release $version" || echo "tag exists" |
| 50 | + git push origin "refs/tags/v$version" || echo "push tag failed" |
| 51 | +
|
| 52 | + - name: List built artifacts |
| 53 | + run: ls -la dist || true |
| 54 | + |
| 55 | + - name: Publish to PyPI with hatch |
| 56 | + env: |
| 57 | + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
| 58 | + run: | |
| 59 | + export HATCH_INDEX_AUTH="__token__:$PYPI_API_TOKEN" |
| 60 | + echo "Publishing with hatch..." |
| 61 | + hatch publish dist/* --yes |
0 commit comments