chore(deps): sync uv and conda #122
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: Python package test | |
| on: | |
| schedule: | |
| - cron: '0 8 * * 1,4' | |
| push: | |
| branches: [main] | |
| tags: ['*'] | |
| pull_request: | |
| branches: ['**'] | |
| workflow_call: | |
| inputs: | |
| override-deps-artifact: | |
| description: "Name of artifact containing updated lockfiles" | |
| required: false | |
| type: string | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint: | |
| name: "π Pre-commit / Code Quality" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: β‘ Install uv | |
| run: curl -LsSf https://astral.sh/uv/install.sh | sh | |
| - name: π Run Pre-commit | |
| run: | | |
| uv tool install pre-commit | |
| uv tool run pre-commit run --show-diff-on-failure --all-files | |
| setup: | |
| name: "ποΈ Build Py${{ matrix.python-version }}" | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: π₯ Apply Dependency Overrides | |
| if: "${{ inputs.override-deps-artifact != '' && inputs.override-deps-artifact != 'null' }}" | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ inputs.override-deps-artifact }} | |
| - name: β‘ Install uv | |
| run: | | |
| apt-get update && apt-get install -y curl | |
| curl -LsSf https://astral.sh/uv/install.sh | BINDIR=/usr/local/bin sh | |
| - name: π Export Locked Requirements | |
| run: | | |
| uv export --frozen --all-extras --format requirements-txt > requirements.txt | |
| - name: π€ Upload Requirements | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frozen-reqs-${{ matrix.python-version }} | |
| path: requirements.txt | |
| retention-days: 1 | |
| test: | |
| needs: setup | |
| name: "π§ͺ py${{ matrix.python-version }}" | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: π₯ Download Requirements | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: frozen-reqs-${{ matrix.python-version }} | |
| - name: β‘ Install uv & git | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y curl git gpg | |
| curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="/usr/local/bin" sh | |
| docker compose --version | |
| uv --version | |
| - name: ποΈ Restore Native Env | |
| run: | | |
| uv venv --python ${{ matrix.python-version }} | |
| uv pip install -r requirements.txt | |
| uv pip install -e ".[test]" --no-deps | |
| - name: π³ Start containers | |
| run: | | |
| docker compose -f "docker-compose.yml" up -d | |
| timeout 60s bash -c 'until curl -s localhost:5000 > /dev/null; do sleep 2; done' || (docker compose logs && exit 1) | |
| - name: π§ͺ Run Tests | |
| env: | |
| MHUB_ENV: testing | |
| CURL_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt | |
| COVERAGE_FILE: .coverage.python.${{ matrix.python-version }} | |
| run: | | |
| uv run pytest -v \ | |
| --cov=mapchete_hub_cli \ | |
| --cov-report=xml:coverage.xml \ | |
| --junitxml="pytest-${{ matrix.python-version }}.xml" | |
| - name: π Upload to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage.xml | |
| flags: py${{ matrix.python-version }} | |
| fail_ci_if_error: true | |
| - name: π€ Upload Coverage Chunk (Latest Only) | |
| if: matrix.python-version == '3.13' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-all | |
| path: .coverage.python.${{ matrix.python-version }} | |
| include-hidden-files: true | |
| retention-days: 1 | |
| - name: π€ Archive JUnit Results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: results-${{ matrix.python-version }} | |
| path: pytest-${{ matrix.python-version }}.xml | |
| retention-days: 1 | |
| summary: | |
| name: "π Final Summary & Coverage" | |
| needs: [test] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 # Needed for coverage to see source files | |
| - name: β‘ Install uv | |
| run: curl -LsSf https://astral.sh/uv/install.sh | sh | |
| - name: π₯ Download Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: all-results | |
| pattern: "*-*" | |
| merge-multiple: true | |
| - name: π Check Tests & Coverage | |
| run: | | |
| echo "### π§ͺ Test & Coverage Summary" >> $GITHUB_STEP_SUMMARY | |
| # 1. CHECK OVERALL TEST STATUS | |
| if [[ "${{ needs.test.result }}" != "success" ]]; then | |
| echo "β **Test Suite Failed**" >> $GITHUB_STEP_SUMMARY | |
| echo "Coverage check skipped because tests failed." >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi | |
| echo "β **Test Suite Passed**" >> $GITHUB_STEP_SUMMARY | |
| # 2. PREPARE COVERAGE DATA | |
| uv tool install coverage | |
| # Move the specific 3.13 files to root | |
| # The pattern matches .coverage.python.3.13 | |
| if ls all-results/.coverage* 1> /dev/null 2>&1; then | |
| mv all-results/.coverage* . | |
| fi | |
| echo "Merging/Preparing coverage data..." | |
| # combine will merge .coverage.* into .coverage | |
| uv tool run coverage combine --append || echo "No extra coverage files to combine." | |
| # 3. ENFORCE 97% | |
| # We run report and capture output. We use '|| true' to prevent 'set -e' from killing the script | |
| # so we can actually print the results to the summary. | |
| REPORT_OUTPUT=$(uv tool run coverage report --show-missing --fail-under=97 2>&1) | |
| EXIT_CODE=$? | |
| echo "$REPORT_OUTPUT" | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| echo "$REPORT_OUTPUT" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| if [ $EXIT_CODE -ne 0 ]; then | |
| echo "β **Coverage Failed:** Python 3.13 coverage is below 97%." >> $GITHUB_STEP_SUMMARY | |
| exit $EXIT_CODE | |
| else | |
| echo "β **Coverage Passed:** 97% coverage achieved (Py3.13)." >> $GITHUB_STEP_SUMMARY | |
| fi |