fepegar/torchio

View on GitHub
.github/workflows/publish.yml

Summary

Maintainability
Test Coverage
# Adapted from https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/

name: Publish

on: push

# https://github.com/fepegar/torchio/actions/runs/6076955855/job/17283217522?pr=1103
permissions:
  id-token: write

jobs:
  Build-and-publish:
    name: Build and publish if needed
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python 3.11
      uses: actions/setup-python@v5
      with:
        python-version: "3.11"

    - name: Install pypa/build
      run: >-
        python -m
        pip install
        build
        --user

    - name: Build a binary wheel and a source tarball
      run: >-
        python -m
        build
        --sdist
        --wheel
        --outdir dist/
        .

    - name: Publish package to TestPyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: __token__
        password: ${{ secrets.TEST_PYPI_API_TOKEN }}
        repository-url: https://test.pypi.org/legacy/
        verbose: true
        skip-existing: true

    # Publish only tagged commits
    - name: Publish package to PyPI, if tagged
      if: startsWith(github.ref, 'refs/tags')
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        password: ${{ secrets.PYPI_API_TOKEN }}
        verbose: true