Skip to content

Upload Python Package #2

Upload Python Package

Upload Python Package #2

# This workflow will upload a Python Package to PyPI when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Upload Python Package
on:
release:
types: [released]
workflow_dispatch:
inputs:
publish_test:
description: 'Publish to TestPyPI'
required: true
type: boolean
default: false
publish_to_pypi:
description: 'Publish to PyPI'
required: true
type: boolean
default: false
permissions:
contents: read
jobs:
release-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Build release distributions
run: |
# NOTE: put your own distribution build steps here.
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
pypi-publish-test:
runs-on: ubuntu-latest
needs:
- release-build
if: github.event_name == 'workflow_dispatch' && inputs.publish_test == true
permissions:
id-token: write
environment:
name: testpypi
url: https://test.pypi.org/project/pangbank/
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
pypi-publish:
runs-on: ubuntu-latest
needs:
- release-build
if: (github.event_name == 'release' && github.event.action == 'released') || (github.event_name == 'workflow_dispatch' && inputs.publish_to_pypi == true)
permissions:
id-token: write
environment:
name: pypi
url: https://pypi.org/project/pangbank/
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1