Skip to content

pypi-publish

pypi-publish #33

Workflow file for this run

# A workflow to publish releases to PyPi and TestPyPi.
name: pypi-publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
run_tests:
description: 'Test sdist before upload'
type: boolean
default: true
upload_to_test_pypi:
description: 'Upload to Test PyPi'
type: boolean
default: false
upload_to_pypi:
description: 'Upload to PyPi'
type: boolean
default: false
permissions: read-all
jobs:
build:
name: Build
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout Concordia
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Show Python setup
run: |
python --version
pip list
- name: Build distribution
run: |
python setup.py sdist bdist_wheel
# Workaround old setuptools not normalizing name in sdist.
for OLD in ./dist/gdm-concordia-*; do
NEW="$(echo "$OLD" | sed s/gdm-concordia/gdm_concordia/)"
mv "$OLD" "$NEW"
done
ls dist/*
- name: Save artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: dist
path: ./dist
retention-days: 1
test:
name: Test
needs: build
if: github.event_name == 'release' || inputs.run_tests
runs-on: ${{ matrix.os }}
env:
SYSTEM_VERSION_COMPAT: 0 # See https://github.com/actions/setup-python/issues/279.
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
os:
- macos-13
- macos-14
- ubuntu-20.04
- ubuntu-22.04
- ubuntu-24.04
python-version:
- '3.11'
- '3.12'
- '3.13'
steps:
- name: Load artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: dist
path: ./dist
- name: Set up Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install --upgrade setuptools
pip install pytest-xdist
- name: Install source distribution
run: |
pip install dist/*.tar.gz
pip list
- name: Test source distribution
run: |
pytest -n auto --pyargs concordia
publish:
name: Publish
needs: [build, test]
if: always() && needs.build.result == 'success' && needs.test.result != 'failure'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/gdm-concordia
permissions:
id-token: write
timeout-minutes: 10
steps:
- name: Load artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: dist
path: ./dist
- name: Publish to TestPyPI
if: github.event_name == 'release' || inputs.upload_to_test_pypi
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
- name: Publish to PyPI
if: github.event_name == 'release' || inputs.upload_to_pypi
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70
with:
verbose: true