Skip to content

Python application

Python application #22

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python application
on:
push:
pull_request:
branches: [ "main" ]
schedule:
- cron: '0 2 * * 3'
permissions:
contents: read
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
lint:
name: Lint with ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install ruff
run: |
pip install ruff
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff check .
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
cache-dependency-path: '**/pyproject.toml'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -e .
- name: Run tests
run: python -m pytest tests
- name: Test Commandline Script
run: |
fetch_orcid_pubs --help
fetch_orcid_pubs --orcid-id 0000-0001-8833-7617 --lastname Webel --output-file test.md
build_source_dist:
name: Build source distribution
if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build
run: python -m pip install build
- name: Run build
run: python -m build --sdist
- uses: actions/upload-artifact@v4
with:
path: ./dist/*.tar.gz
- name: install package from build
run: |
python -m pip install dist/*.tar.gz
- name: Test Commandline Script
run: |
fetch_orcid_pubs --help
fetch_orcid_pubs --orcid-id 0000-0001-8833-7617 --lastname Webel --output-file test.md
publish:
name: Publish package
if: startsWith(github.ref, 'refs/tags')
needs:
- format
- lint
- test
- build_source_dist
# - build_wheels
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/project/list-publications/
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:
repository-url: https://test.pypi.org/legacy/