feat: add postgres option for ci-python-library#41
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR extends a reusable Python library CI workflow to optionally provision PostgreSQL (versions 13, 14, or 17) and PostGIS for database-backed tests. It adds parameterized inputs, conditional service container setup with version validation, system dependency installation, environment export, and corresponding documentation and examples. ChangesPostgreSQL Optional Testing
Sequence DiagramsequenceDiagram
actor Caller
participant ReusableWorkflow
participant Validator
participant DockerRunner
participant PostgresContainer
participant TestJob
Caller->>ReusableWorkflow: call workflow with inputs (postgres-major-version, use-postgis)
ReusableWorkflow->>Validator: validate postgres-major-version (allowlist 13,14,17)
Validator-->>ReusableWorkflow: validation result
ReusableWorkflow->>DockerRunner: start selected postgres/postgis image
DockerRunner->>PostgresContainer: run container + health check (pg_isready)
PostgresContainer-->>ReusableWorkflow: healthy
ReusableWorkflow->>TestJob: write DATABASE_URL to GITHUB_ENV and install deps
TestJob->>PostgresContainer: run database-backed tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
.github/workflows/ci-python-library.yml (1)
121-131: 💤 Low valueConsider consolidating apt-get operations.
Running
apt-get updateseparately fromapt-get installcreates a minor inefficiency and potential inconsistency window. Consider combining them into a single step.♻️ Proposed consolidation
- - name: Install database system packages + - name: Install system packages for PostgreSQL if: ${{ inputs.postgres-major-version != '' }} run: | - sudo apt-get update - sudo apt-get install libpq-dev - - - name: Install PostGIS system packages - if: ${{ inputs.use-postgis }} - run: | - sudo apt-get install gdal-bin + sudo apt-get update + packages="libpq-dev" + if [[ "${{ inputs.use-postgis }}" == "true" ]]; then + packages="$packages gdal-bin" + fi + sudo apt-get install -y $packages🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/ci-python-library.yml around lines 121 - 131, Combine the separate apt-get update/install steps into a single "Install system packages" step (replacing the "Install database system packages" and "Install PostGIS system packages" steps) so update runs once; in that step run apt-get update && apt-get install -y and include libpq-dev and gdal-bin only when their respective inputs are set (use shell conditionals on inputs.postgres-major-version and inputs.use-postgis to append packages), and keep the step gated with a combined if (inputs.postgres-major-version != '' || inputs.use-postgis) to avoid unnecessary runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/ci-python-library-README.md:
- Line 93: The README's example `DATABASE_URL` uses the postgres scheme but the
workflow builds `DATABASE_URL` as `postgis://...` when `use-postgis` is true;
update the workflow (the `run:` step that constructs DATABASE_URL) to always use
the standard PostgreSQL URI scheme (`postgres://` or `postgresql://`) even when
enabling PostGIS, and adjust any logic that switches to `postgis://` so it
instead toggles PostGIS enablement without changing the scheme; ensure the
`DATABASE_URL` variable name and the `use-postgis`/`postgres-major-version`
inputs remain the same.
In @.github/workflows/ci-python-library.yml:
- Around line 72-90: The postgres service is always started because of the
fallback image 'postgres:alpine' in the services: postgres image expression;
change the workflow to avoid starting the container when no DB is requested by
moving the database requirement to a job-level conditional (e.g., add if: ${{
inputs.postgres-major-version != '' }} to the job that currently defines
services: postgres) or remove the fallback image and document the limitation;
update the job that uses the services: postgres block (referencing the services:
postgres stanza and the image expression using inputs.postgres-major-version and
inputs.use-postgis) so the entire job is skipped when postgres-major-version is
empty.
- Around line 127-131: The "Install PostGIS system packages" step currently only
checks inputs.use-postgis and should also verify inputs.postgres-major-version
is set; update the step's if condition to require both inputs.use-postgis and a
non-empty inputs.postgres-major-version (i.e., ensure
inputs.postgres-major-version is provided) so the PostGIS packages only install
when a Postgres major version is configured.
- Around line 93-100: The workflow step interpolates `${{
inputs.postgres-major-version }}` directly into the shell, risking code
injection; instead, assign the input to a safe environment variable (e.g.
POSTGRES_MAJOR_VERSION) and reference that variable in the validation logic
(keep the supported_versions array and the membership check using
supported_versions and POSTGRES_MAJOR_VERSION), ensuring the variable is
quoted/treated as data rather than injected into the script; update the step
that uses inputs.postgres-major-version to export/declare POSTGRES_MAJOR_VERSION
from the input and then use that variable in the if check and error message.
- Around line 132-135: The "Set database URL" step currently writes a
DATABASE_URL using a non-standard "postgis://" scheme based on
inputs.use-postgis; change this to always emit a standard postgres:// URI (e.g.,
"postgres://test_user:test_password@localhost/test_db") and remove the
conditional that switches to 'postgis' so the run echo always uses postgres://;
apply the same change to the "Set database URL" steps in the other workflows
that use the use-postgis conditional (ci-django-api and ci-uv-django-api) so all
workflows consistently set DATABASE_URL to the standard postgres:// scheme while
PostGIS remains provided by the service image.
---
Nitpick comments:
In @.github/workflows/ci-python-library.yml:
- Around line 121-131: Combine the separate apt-get update/install steps into a
single "Install system packages" step (replacing the "Install database system
packages" and "Install PostGIS system packages" steps) so update runs once; in
that step run apt-get update && apt-get install -y and include libpq-dev and
gdal-bin only when their respective inputs are set (use shell conditionals on
inputs.postgres-major-version and inputs.use-postgis to append packages), and
keep the step gated with a combined if (inputs.postgres-major-version != '' ||
inputs.use-postgis) to avoid unnecessary runs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6156a0f9-596b-4c63-90f0-63db3991d560
📒 Files selected for processing (2)
.github/workflows/ci-python-library-README.md.github/workflows/ci-python-library.yml
Refs: RATY-348
bb1a08c to
ff74b34
Compare
Refs: RATY-348
Summary by CodeRabbit
Documentation
Chores