Publish to PyPI #101
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to PyPI | |
on: | |
workflow_dispatch: | |
jobs: | |
check-tag: | |
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 | |
build-package: | |
needs: | |
- check-tag | |
uses: ./.github/workflows/build-package.yml | |
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 |