[MNT] homogenize CI workflows with GC.OS repositories (#702) #572
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: Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| code-quality: | |
| name: code-quality | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: repository checkout step | |
| uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| python-version: "3.14" | |
| - name: Create virtual environment | |
| run: uv venv | |
| - name: install pre-commit | |
| run: uv pip install pre-commit | |
| - name: Get changed files | |
| id: changed-files | |
| run: | | |
| CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr '\n' ' ') | |
| echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV | |
| - name: Print changed files | |
| run: | | |
| echo "Changed files:" && echo "$CHANGED_FILES" | tr ' ' '\n' | |
| - name: Run pre-commit on changed files | |
| run: | | |
| if [ -n "$CHANGED_FILES" ]; then | |
| pre-commit run --color always --files $CHANGED_FILES --show-diff-on-failure | |
| else | |
| echo "No changed files to check." | |
| fi | |
| test-nosoftdeps: | |
| needs: code-quality | |
| name: nosoftdeps (${{ matrix.python-version }}, ${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| python-version: ${{ matrix.python-version }} | |
| - name: Create virtual environment | |
| run: uv venv | |
| - name: Display Python version | |
| run: python -c "import sys; print(sys.version)" | |
| - name: Force non-GUI Matplotlib backend (Windows) | |
| if: ${{ matrix.os == 'windows-latest' }} | |
| shell: pwsh | |
| run: echo "MPLBACKEND=Agg" >> $env:GITHUB_ENV | |
| - name: Install dependencies | |
| shell: bash | |
| run: uv pip install ".[dev]" --no-cache | |
| - name: Show dependencies | |
| run: uv pip list | |
| - name: Run tests | |
| run: uv run pytest ./tests | |
| test-full: | |
| needs: test-nosoftdeps | |
| name: allsoftdeps (${{ matrix.python-version }}, ${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| python-version: ${{ matrix.python-version }} | |
| - name: Create virtual environment | |
| run: uv venv | |
| - name: Display Python version | |
| run: python -c "import sys; print(sys.version)" | |
| - name: Force non-GUI Matplotlib backend (Windows) | |
| if: ${{ matrix.os == 'windows-latest' }} | |
| shell: pwsh | |
| run: echo "MPLBACKEND=Agg" >> $env:GITHUB_ENV | |
| - name: Install dependencies | |
| shell: bash | |
| run: uv pip install -e ".[all_extras, dev]" --no-cache | |
| - name: Show dependencies | |
| run: uv pip list | |
| - name: Run tests | |
| run: uv run pytest ./tests | |
| # TODO: should we run this as a substep of test-no-deps and only upload for a specific version? | |
| codecov: | |
| name: coverage | |
| needs: code-quality | |
| runs-on: "ubuntu-latest" | |
| env: | |
| MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| python-version: 3.12 | |
| - name: Create virtual environment | |
| run: uv venv | |
| - name: Display Python version | |
| run: python -c "import sys; print(sys.version)" | |
| - name: Force non-GUI Matplotlib backend (Windows) | |
| if: ${{ matrix.os == 'windows-latest' }} | |
| shell: pwsh | |
| run: echo "MPLBACKEND=Agg" >> $env:GITHUB_ENV | |
| - name: Install dependencies | |
| shell: bash | |
| run: uv pip install ".[dev,cov]" | |
| - name: Show dependencies | |
| run: uv pip list | |
| - name: Generate coverage report | |
| run: | | |
| uv run pytest --cov=./ --cov-report=xml | |
| - name: Upload coverage to Codecov | |
| # if false in order to skip for now | |
| if: false | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| files: ./coverage.xml | |
| fail_ci_if_error: true | |
| detect-notebooks-change: | |
| needs: code-quality | |
| name: detect change affecting notebooks | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: read | |
| outputs: | |
| notebooks: ${{ steps.check.outputs.notebooks }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch main branch | |
| run: git fetch origin main | |
| - name: Check if cookbook, pypfopt or pyproject.toml changed | |
| id: check | |
| run: | | |
| if git diff --quiet origin/main -- cookbook/ pypfopt/ pyproject.toml; then | |
| echo "No notebook related changes" | |
| echo "notebooks=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Detected changes in notebooks or pypfopt" | |
| echo "notebooks=true" >> $GITHUB_OUTPUT | |
| fi | |
| run-notebook-examples: | |
| needs: detect-notebooks-change | |
| if: ${{ needs.detect-notebooks-change.outputs.notebooks == 'true' }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| python-version: ${{ matrix.python-version }} | |
| - name: Display Python version | |
| run: python -c "import sys; print(sys.version)" | |
| - name: Create virtual environment | |
| run: uv venv | |
| - name: Install dependencies | |
| shell: bash | |
| run: uv pip install ".[dev,all_extras,notebook_test]" --no-cache | |
| - name: Show dependencies | |
| run: uv pip list | |
| - name: Collect notebooks | |
| id: notebooks | |
| shell: bash | |
| run: | | |
| NOTEBOOKS=$(find cookbook -name '*.ipynb' -print0 | xargs -0 echo) | |
| echo "notebooks=$NOTEBOOKS" >> $GITHUB_OUTPUT | |
| - name: Run notebooks | |
| shell: bash | |
| run: | | |
| uv run pytest --reruns 3 --nbmake --nbmake-timeout=3600 -vv ${{ steps.notebooks.outputs.notebooks }} |