Reorganize and modernize package #40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [master, main] | |
| pull_request: | |
| branches: [master, main] | |
| jobs: | |
| get-python-versions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| python-versions: ${{ steps.get-versions.outputs.python-versions }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Extract Python versions from pyproject.toml | |
| id: get-versions | |
| run: | | |
| # Extract Python versions from classifiers in pyproject.toml | |
| # This looks for lines like "Programming Language :: Python :: 3.8" | |
| python_versions=$(grep -o 'Programming Language :: Python :: 3\.[0-9]\+' pyproject.toml | grep -o '3\.[0-9]\+' | sort -V | jq -R -s -c 'split("\n")[:-1]') | |
| echo "python-versions=$python_versions" >> $GITHUB_OUTPUT | |
| echo "Detected Python versions: $python_versions" | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e .[dev] | |
| - name: Lint with flake8 | |
| run: | | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 src/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # run full linting | |
| flake8 src/ tests/ | |
| test: | |
| needs: [get-python-versions, lint] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ${{ fromJson(needs.get-python-versions.outputs.python-versions) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e .[test] | |
| - name: Test with pytest | |
| run: pytest | |
| build: | |
| needs: [test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Build package | |
| run: python -m build | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: dist | |
| path: dist/ | |
| publish: | |
| if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Publish package to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |