Skip to content

Automated deployment to PyPI on release #6

Automated deployment to PyPI on release

Automated deployment to PyPI on release #6

Workflow file for this run

name: Build and upload to PyPI
on:
push:
tags:
- "*"
release:
types:
- published
pull_request:
branches: [main]
jobs:
# Build the packacge and upload the resulting distribution
# as an artifact to later be used during deployment to
# PyPI
build:
name: Build ${{ vars.PACKAGE_NAME }}
if: github.repository == ${{ vars.REPO_OWNER}}/${{ vars.REPO_NAME }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build wheel and source
run: python3 -m build
- name: Upload distribution artifact
if: |
((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/' )) ||
(github.event_name == 'release' && github.event.action == 'published')) &&
github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
# Publish the resulting artifact from the above job to
# the main PyPI repository.
publish-to-pypi:
name: Publish ${{ vars.PACKAGE_NAME }} to PyPI
if: |
github.event_name == 'release' &&
github.event.action == 'published' &&
github.repository == ${{ vars.REPO_OWNER }}/${{ vars.REPO_NAME }} &&
github.event_name != 'pull_request'
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: "https://pypi.org/p/$PACKAGE_NAME"
permissions:
id-token: write
steps:
- name: Downlaod build artifacts
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish ${{ vars.PACKAGE_NAME }} to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-to-testpypi:
name: Publish ${{ vars.PACKAGE_NAME }} to TestPyPI
if: |
github.repository == ${{ vars.REPO_OWNER }}/${{ vars.REPO_NAME }} &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/') &&
github.event_name != 'pull_request'
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
url: "https://test.pypi.org/p/$PACKAGE_NAME"
permissions:
id-token: write
steps:
- name: Downlaod build artifacts
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish ${{ vars.PACKAGE_NAME }} to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip_existing: true