CI #938
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: | |
| - main | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "23 4 * * 0" | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| DOCKER_BUILDKIT: 1 | |
| PIP_BREAK_SYSTEM_PACKAGES: 1 | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: read | |
| outputs: | |
| pgtagprefix: ${{ steps.check.outputs.pgtagprefix }} | |
| buildpgdocker: ${{ steps.check.outputs.buildpg }} | |
| pyrustdocker: ${{ steps.check.outputs.pytag }} | |
| buildpyrustdocker: ${{ steps.check.outputs.buildpy }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 | |
| id: filter | |
| with: | |
| filters: | | |
| pgstac: | |
| - 'docker/pgstac/**' | |
| pypgstac: | |
| - 'docker/pypgstac/**' | |
| - id: check | |
| run: | | |
| buildpg=false; | |
| ref=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | tr / _); | |
| pgref=$ref; | |
| [[ "${{ steps.filter.outputs.pgstac }}" == "true" ]] && buildpg=true || pgref=main; | |
| if [[ "${{ github.event_name }}" == "schedule" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| buildpg=true; | |
| pgref=main; | |
| fi | |
| echo "pgtagprefix=${{ env.REGISTRY }}/${GITHUB_REPOSITORY_OWNER}/pgstac-postgres:$pgref" >>$GITHUB_OUTPUT; | |
| echo "buildpg=$buildpg" >>$GITHUB_OUTPUT; | |
| buildpy=false; | |
| pyref=$ref; | |
| [[ "${{ steps.filter.outputs.pypgstac }}" == "true" ]] && buildpy=true || pyref=main; | |
| if [[ "${{ github.event_name }}" == "schedule" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| buildpy=true; | |
| pyref=main; | |
| fi | |
| echo "pytag=${{ env.REGISTRY }}/${GITHUB_REPOSITORY_OWNER}/pgstac-pyrust:$pyref" >>$GITHUB_OUTPUT; | |
| echo "buildpy=$buildpy" >>$GITHUB_OUTPUT; | |
| # This builds a base postgres image that has everything installed to be able to run pgstac. This image does not have pgstac itself installed. | |
| buildpg: | |
| name: Build and push base postgres image | |
| runs-on: ubuntu-latest | |
| needs: [changes] | |
| strategy: | |
| matrix: | |
| pg_major: [16, 17, 18] | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push Base Postgres | |
| if: ${{ needs.changes.outputs.buildpgdocker == 'true' }} | |
| uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| context: . | |
| target: pgstacbase | |
| file: docker/pgstac/Dockerfile | |
| build-args: | | |
| PG_MAJOR=${{ matrix.pg_major }} | |
| tags: ${{ needs.changes.outputs.pgtagprefix }}-pg${{ matrix.pg_major }} | |
| push: true | |
| cache-from: type=gha | |
| cache-to: type=gha, mode=max | |
| buildpyrust: | |
| name: Build and push base pyrust | |
| runs-on: ubuntu-latest | |
| needs: [changes] | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push Base pyrust | |
| if: ${{ needs.changes.outputs.buildpyrustdocker == 'true' }} | |
| uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| context: . | |
| target: pyrustbase | |
| file: docker/pypgstac/Dockerfile | |
| tags: ${{ needs.changes.outputs.pyrustdocker }} | |
| push: true | |
| cache-from: type=gha | |
| cache-to: type=gha, mode=max | |
| test: | |
| name: test | |
| needs: [changes, buildpg, buildpyrust] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| pg_major: [16, 17, 18] | |
| flags: | |
| - "" | |
| - "--resolution lowest-direct" | |
| container: | |
| image: ${{ needs.changes.outputs.pyrustdocker }} | |
| options: --user root | |
| env: | |
| PGPASSWORD: postgres | |
| PGHOST: postgres | |
| PGDATABASE: postgres | |
| PGUSER: postgres | |
| UV_CACHE_DIR: /tmp/.uv-cache | |
| services: | |
| postgres: | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| image: ${{ needs.changes.outputs.pgtagprefix }}-pg${{ matrix.pg_major }} | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Ensure PostgreSQL client tools | |
| run: | | |
| set -euo pipefail | |
| apt-get update | |
| apt-get install -y --no-install-recommends gnupg ca-certificates curl | |
| install -d -m 0755 /etc/apt/keyrings | |
| curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg | |
| . /etc/os-release | |
| echo "deb [signed-by=/etc/apt/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list | |
| apt-get update | |
| apt-get install -y --no-install-recommends "postgresql-client-${{ matrix.pg_major }}" | |
| client_major="$(pg_dump --version | sed -E 's/.* ([0-9]+)\..*/\1/')" | |
| server_major="$(psql -X -tA -h postgres -d postgres -c 'show server_version' | sed -E 's/^([0-9]+).*/\1/')" | |
| if [[ "$client_major" != "${{ matrix.pg_major }}" ]]; then | |
| echo "Expected pg_dump major ${{ matrix.pg_major }}, got ${client_major}" >&2 | |
| exit 1 | |
| fi | |
| if [[ "$client_major" != "$server_major" ]]; then | |
| echo "pg_dump major (${client_major}) does not match postgres major (${server_major})" >&2 | |
| exit 1 | |
| fi | |
| - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 | |
| - name: Install pypgstac | |
| working-directory: /__w/pgstac/pgstac/src/pypgstac | |
| run: | | |
| export UV_CACHE_DIR=/tmp/.uv-cache | |
| export XDG_CACHE_HOME=/tmp/.cache | |
| mkdir -p "$UV_CACHE_DIR" "$XDG_CACHE_HOME" | |
| uv --cache-dir "$UV_CACHE_DIR" venv /tmp/ci-venv | |
| uv --cache-dir "$UV_CACHE_DIR" pip install --python /tmp/ci-venv/bin/python ${{ matrix.flags }} .[dev,test,psycopg] | |
| echo "/tmp/ci-venv/bin" >> "$GITHUB_PATH" | |
| - name: Run tests | |
| working-directory: /__w/pgstac/pgstac | |
| run: scripts/container-scripts/test | |
| rust-crate: | |
| name: Test rust crate | |
| if: ${{ false }} # FIXME: turn back on before v0.10 release | |
| runs-on: ubuntu-latest | |
| needs: | |
| - changes | |
| - buildpg | |
| services: | |
| postgres: | |
| env: | |
| POSTGRES_USER: username | |
| POSTGRES_PASSWORD: password | |
| POSTGRES_DB: postgis | |
| image: ${{ needs.changes.outputs.pgtagprefix }}-pg18 | |
| ports: | |
| - 5439:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| env: | |
| PGHOST: localhost | |
| PGPORT: 5439 | |
| PGUSER: username | |
| PGPASSWORD: password | |
| PGDATABASE: postgis | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| persist-credentials: false | |
| - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 | |
| - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 | |
| - name: Install pypgstac | |
| working-directory: src/pypgstac | |
| run: | | |
| uv venv /tmp/ci-venv | |
| uv pip install --python /tmp/ci-venv/bin/python .[psycopg] | |
| echo "/tmp/ci-venv/bin" >> "$GITHUB_PATH" | |
| - name: Migrate pgstac | |
| run: pypgstac migrate | |
| - name: Set search_path | |
| run: psql -c "ALTER ROLE username SET search_path TO pgstac, public;" | |
| - name: Test | |
| run: cargo test -p pgstac --all-features --manifest-path src/pgstac-rs/Cargo.toml |