Skip to content

Updated workflow

Updated workflow #27

# .github/workflows/python-package.yml
name: CI
on:
push:
# run tests on every branch and publish only when a tag is created
branches: ['*']
tags: ['*'] # trigger on any tag push (e.g. v0.1.5)
pull_request:
branches: ['*']
workflow_dispatch:
inputs:
publish_to:
description: 'Where to publish package'
required: true
default: 'pypi'
type: choice
options:
- pypi
- testpypi
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run pytest
run: python -m pytest -q
publish:
name: Build & publish
needs: test
runs-on: ubuntu-latest
# only run automatically when a tag is pushed, or when manually dispatched
if: >
startsWith(github.ref, 'refs/tags/') ||
github.event_name == 'workflow_dispatch'
environment:
# optional: use a production environment for real releases
name: ${{ startsWith(github.ref, 'refs/tags/') && 'production' || 'dev' }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Build wheel/sdist
run: |
python -m pip install --upgrade build
python -m build
- name: Publish to PyPI/TestPyPI
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && \
[ "${{ github.event.inputs.publish_to }}" = "testpypi" ]; then
repo="https://test.pypi.org/legacy/"
token="${{ secrets.TEST_PYPI_API_TOKEN }}"
else
repo="https://upload.pypi.org/legacy/"
token="${{ secrets.PYPI_API_TOKEN }}"
fi
python -m pip install --upgrade twine
python -m twine upload --repository-url "$repo" -u __token__ -p "$token" dist/*