Skip to content

Publish to PyPI

Publish to PyPI #19

name: Publish to PyPI
on:
workflow_dispatch:
inputs:
version:
description: Version (tag)
required: true
test:
description: testpypi
required: false
default: false
type: boolean
debug:
description: verbose logging
required: false
default: false
type: boolean
# Change to this once workflow has been tested
# on:
# release:
# types: [released]
jobs:
build_artifacts:
runs-on: ubuntu-latest
steps:
- name: Get tag name
id: get_tag_name
env:
tagname: ${{ github.event.inputs.version }}
run: echo "VERSION=refs/tags/${env.tagname}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
env:
VERSION: ${{ steps.get_tag_name.outputs.VERSION }}
with:
ref: ${{ env.VERSION }}
fetch-depth: 0
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.11'
- name: Install build tools
shell: 'bash'
run: python -m pip install build
- name: Build sdist
shell: 'bash'
run: python -m build --sdist --wheel .
- uses: actions/upload-artifact@v4
with:
path: dist/*
publish_pypi:
needs: [ build_artifacts ]
runs-on: ubuntu-latest
env:
url: https://pypi.org/p/spacekit
test_url: https://test.pypi.org/legacy/
verbose_debug: true
environment:
name: pypi_release
url: ${{ ( github.event.inputs.test == 'true' && env.test_url) || env.url }}
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v4
with:
name: artifact
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
name: pypi
repository-url: ${{ (github.event.inputs.test == 'true' && env.test_url) || env.url }}
verify-metadata: true
skip-existing: false
verbose: ${{ github.event.inputs.debug == 'true' && env.verbose_debug }}