|
| 1 | +name: Test Python Library |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + python-version: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + description: 'Python version to use, e.g., "3.9"' |
| 10 | + use-uv: |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | + description: 'Use `uv` for minimum version resolution' |
| 14 | + coverage: |
| 15 | + type: boolean |
| 16 | + default: false |
| 17 | + description: 'Generate coverage report' |
| 18 | + |
| 19 | +jobs: |
| 20 | + check: |
| 21 | + runs-on: ubuntu-22.04 |
| 22 | + |
| 23 | + services: |
| 24 | + postgres: |
| 25 | + image: postgis/postgis |
| 26 | + env: |
| 27 | + POSTGRES_USER: geoengine |
| 28 | + POSTGRES_PASSWORD: geoengine |
| 29 | + POSTGRES_DB: geoengine |
| 30 | + ports: |
| 31 | + - 5432:5432 |
| 32 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 |
| 33 | + |
| 34 | + defaults: |
| 35 | + run: |
| 36 | + working-directory: library |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout library code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + path: library |
| 43 | + - name: Setup variables |
| 44 | + id: vars |
| 45 | + run: | |
| 46 | + echo "GEOENGINE_VERSION=$(cat .github/.backend_git_ref)" >> $GITHUB_OUTPUT |
| 47 | + if ${{ inputs.use-uv }}; then |
| 48 | + echo "PIP_INSTALL=uv pip install --resolution=lowest-direct" >> $GITHUB_OUTPUT |
| 49 | + echo "VENV_CALL=source .venv/bin/activate" >> $GITHUB_OUTPUT |
| 50 | + else |
| 51 | + echo "PIP_INSTALL=pip install" >> $GITHUB_OUTPUT |
| 52 | + echo "VENV_CALL=" >> $GITHUB_OUTPUT |
| 53 | + fi |
| 54 | + if ${{ inputs.coverage }}; then |
| 55 | + echo "COVERAGE_COMMAND=--cov=geoengine --cov-report=lcov" >> $GITHUB_OUTPUT |
| 56 | + else |
| 57 | + echo "COVERAGE_COMMAND=" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | + - name: Checkout Geo Engine code |
| 60 | + uses: actions/checkout@v4 |
| 61 | + with: |
| 62 | + repository: geo-engine/geoengine |
| 63 | + ref: ${{ steps.vars.outputs.GEOENGINE_VERSION }} |
| 64 | + path: backend |
| 65 | + - name: Free Disk Space (Ubuntu) |
| 66 | + uses: jlumbroso/free-disk-space@main |
| 67 | + with: |
| 68 | + tool-cache: true |
| 69 | + android: true |
| 70 | + dotnet: true |
| 71 | + haskell: true |
| 72 | + large-packages: true |
| 73 | + docker-images: true |
| 74 | + swap-storage: true |
| 75 | + - name: Install lld & GDAL & Protobuf |
| 76 | + run: | |
| 77 | + sudo apt-get update |
| 78 | + sudo apt-get install lld libgdal-dev gdal-bin build-essential clang curl protobuf-compiler libgeos-dev libproj-dev |
| 79 | + sudo apt-get clean |
| 80 | + export C_INCLUDE_PATH=/usr/include/gdal:$C_INCLUDE_PATH |
| 81 | + export CPLUS_INCLUDE_PATH=/usr/include/gdal:$CPLUS_INCLUDE_PATH |
| 82 | + sudo ldconfig |
| 83 | + - name: Install Rustup |
| 84 | + run: | |
| 85 | + curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y |
| 86 | + echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH |
| 87 | + - name: Set up Python ${{ inputs.python-version }} |
| 88 | + uses: actions/setup-python@v4 |
| 89 | + with: |
| 90 | + python-version: ${{ inputs.python-version }} |
| 91 | + - name: Upgrade PIP |
| 92 | + run: python -m pip install --upgrade pip |
| 93 | + - name: Setup UV and create venv |
| 94 | + if: ${{ inputs.use-uv }} |
| 95 | + run: | |
| 96 | + pip install uv |
| 97 | + uv venv |
| 98 | + - name: Install build dependencies |
| 99 | + run: | |
| 100 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 101 | + ${{ steps.vars.outputs.PIP_INSTALL }} -e .[dev] |
| 102 | + - name: Check Formatting |
| 103 | + run: | |
| 104 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 105 | + python -m pycodestyle |
| 106 | + - name: Lint code |
| 107 | + run: | |
| 108 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 109 | + python -m pylint geoengine |
| 110 | + - name: Type-check code |
| 111 | + # mypy seems buggy with uv |
| 112 | + if: ${{ !inputs.use-uv }} |
| 113 | + run: | |
| 114 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 115 | + python -m mypy geoengine |
| 116 | + - name: Build |
| 117 | + run: | |
| 118 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 119 | + python -m build . |
| 120 | + - name: Install test dependencies |
| 121 | + run: | |
| 122 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 123 | + ${{ steps.vars.outputs.PIP_INSTALL }} -e .[test] |
| 124 | + - name: Lint tests |
| 125 | + run: | |
| 126 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 127 | + python -m pylint tests |
| 128 | + - name: Type-check tests |
| 129 | + # mypy seems buggy with uv |
| 130 | + if: ${{ !inputs.use-uv }} |
| 131 | + run: | |
| 132 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 133 | + python -m mypy tests |
| 134 | + - name: Test |
| 135 | + run: | |
| 136 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 137 | + pytest ${{ steps.vars.outputs.COVERAGE_COMMAND }} |
| 138 | + env: |
| 139 | + GEOENGINE_TEST_CODE_PATH: ${{ github.workspace }}/backend |
| 140 | + GEOENGINE_TEST_BUILD_TYPE: "release" |
| 141 | + - name: Upload coverage to Coveralls |
| 142 | + if: ${{ inputs.coverage }} |
| 143 | + uses: coverallsapp/github-action@v2 |
| 144 | + with: |
| 145 | + base-path: library |
| 146 | + - name: Examples |
| 147 | + run: | |
| 148 | + ${{ steps.vars.outputs.VENV_CALL }} |
| 149 | + ${{ steps.vars.outputs.PIP_INSTALL }} -e .[examples] |
| 150 | + python test_all_notebooks.py |
| 151 | + env: |
| 152 | + GEOENGINE_TEST_CODE_PATH: ${{ github.workspace }}/backend |
| 153 | + GEOENGINE_TEST_BUILD_TYPE: "release" |
0 commit comments