Skip to content

Publish to PyPI

Publish to PyPI #64

Workflow file for this run

name: Publish to PyPI
on:
workflow_dispatch:
jobs:
build-package:
name: Build distribution 📦
runs-on: ubuntu-latest
steps:
- id: check_ref
run: echo "::set-output name=match::$(echo '${{ github.ref }}' | grep -Pq '^refs/tags/v\d+\.\d+\.\d+$' && echo true || echo false)"
shell: bash
- name: Check if tag is valid
if: steps.check_ref.outputs.match != 'true'
run: exit 1
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install hatch
run: |
pip install hatch --user
- name: Run tests
run: |
python3 -m hatch run test
- name: Run linting
run: |
python3 -m hatch run lint:all
- name: Build a wheel and a source tarball
run: |
python3 -m hatch build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: package
path: |
dist/*
github-release:
name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs:
- build-package
steps:
- uses: actions/checkout@v4
- name: Generate changelog
run: |
cat > CHANGELOG.md <<EOT
# CHANGELOG
**Release**: dt-cli (${GITHUB_REF#refs/tags/})
# Changes
EOT
git log --format=format:"%ad: %s" --date=short >> CHANGELOG.md
- name: Download cached built package
uses: actions/download-artifact@v4
with:
name: package
path: dist
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
files: |
dist/*
LICENSE
body_path: CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-pypi:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs:
- build-package
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install hatch
run: |
pip install hatch --user
- name: Download cached built package
uses: actions/download-artifact@v4
with:
name: package
path: dist
- name: Publish to PyPI
env:
PYPI_PUBLISH_TOKEN: ${{ secrets.PYPI_PUBLISH_TOKEN }}
run: |
hatch publish --user __token__ --auth $PYPI_PUBLISH_TOKEN --no-prompt