ci-bump-version #7
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
| # .github/workflows/ci.yml | |
| name: CI and Publish | |
| # Trigger on pushes/PRs to main AND pushes of tags starting with 'v' | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: | |
| - 'v*' # Trigger on tags like v0.1.0, v1.2.3, etc. | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| # Job 1: Run linters, type checks, and tests | |
| test_and_lint: # Renamed for clarity | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11"] # Test on relevant Python versions | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: 'pip' | |
| - name: Install dependencies (including test extras) | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install .[test] # Installs package + ruff, mypy, pytest etc. | |
| - name: Lint and Format Check with Ruff | |
| run: | | |
| ruff format --check . | |
| ruff check . | |
| - name: Analyse code with Mypy | |
| run: | | |
| mypy codeconcat tests # Adjust paths if needed | |
| # Optional: Uncomment if you have pytest tests | |
| # - name: Run tests with Pytest | |
| # run: | | |
| # pytest | |
| # Job 2: Publish package to PyPI on tagged commits | |
| publish: | |
| # Only run this job if the trigger was a tag push starting with 'v' | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| # Only run this job if the 'test_and_lint' job succeeded | |
| needs: test_and_lint | |
| runs-on: ubuntu-latest | |
| # Grant permissions for GitHub's OIDC token to be used for PyPI Trusted Publishing | |
| permissions: | |
| id-token: write # Essential for Trusted Publishing | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python for publishing | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' # Use a specific Python version for building/publishing | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine # Tools needed to build and upload the package | |
| - name: Build package | |
| run: python -m build # Creates wheel and sdist in dist/ directory | |
| - name: Publish package to PyPI | |
| # Twine will automatically use the OIDC token provided by the runner environment | |
| # when run in a job with 'id-token: write' permissions. | |
| # Ensure you have configured Trusted Publishing on PyPI for this repo/workflow. | |
| run: twine upload dist/* |