Skip to content

feat: add postgres option for ci-python-library#41

Open
danipran wants to merge 2 commits into
mainfrom
RATY-348/add-postgres-in-python-library
Open

feat: add postgres option for ci-python-library#41
danipran wants to merge 2 commits into
mainfrom
RATY-348/add-postgres-in-python-library

Conversation

@danipran

@danipran danipran commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Refs: RATY-348

Summary by CodeRabbit

  • Documentation

    • Added CI docs for optional PostgreSQL database testing: supported major versions (13, 14, 17), a PostGIS toggle, configuration examples, and a note that DATABASE_URL is exposed to the test runner when enabled.
  • Chores

    • CI extended to optionally provision PostgreSQL and enable PostGIS for database-backed tests, with version validation and readiness checks.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0c54cea-2d23-4cc4-aae4-1f34b6aa9572

📥 Commits

Reviewing files that changed from the base of the PR and between ff74b34 and a6f2474.

📒 Files selected for processing (1)
  • .github/workflows/ci-python-library.yml

📝 Walkthrough

Walkthrough

This 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.

Changes

PostgreSQL Optional Testing

Layer / File(s) Summary
PostgreSQL feature and inputs documentation
.github/workflows/ci-python-library-README.md, .github/workflows/ci-python-library.yml
Introduces optional PostgreSQL database testing as a feature and adds postgres-major-version (supports 13, 14, 17) and use-postgis (boolean, default false) workflow inputs with documented purpose.
Service provisioning and version validation
.github/workflows/ci-python-library.yml
Adds a Docker-started services.postgres container with conditional image selection for PostgreSQL vs PostGIS, a pg_isready health check loop, and a validation step rejecting unsupported postgres-major-version values.
Environment setup and usage examples
.github/workflows/ci-python-library.yml, .github/workflows/ci-python-library-README.md
Conditionally installs libpq-dev and gdal-bin (when PostGIS enabled), exports DATABASE_URL to GITHUB_ENV, and documents example usage showing postgres-major-version and DATABASE_URL exposure.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 In CI burrows I hop and test,
I start Postgres when you request.
Versions chosen, PostGIS in sight,
DATABASE_URL gleams in the night.
Docs and jobs snug — carrots for CI delight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add postgres option for ci-python-library' accurately describes the main change: adding PostgreSQL as an optional feature to the CI workflow with new configuration inputs (postgres-major-version and use-postgis).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch RATY-348/add-postgres-in-python-library

Comment @coderabbitai help to get the list of available commands and usage tips.

@danipran danipran requested a review from a team June 5, 2026 10:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
.github/workflows/ci-python-library.yml (1)

121-131: 💤 Low value

Consider consolidating apt-get operations.

Running apt-get update separately from apt-get install creates 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4de6bb1 and bb1a08c.

📒 Files selected for processing (2)
  • .github/workflows/ci-python-library-README.md
  • .github/workflows/ci-python-library.yml

Comment thread .github/workflows/ci-python-library-README.md
Comment thread .github/workflows/ci-python-library.yml Outdated
Comment thread .github/workflows/ci-python-library.yml
Comment thread .github/workflows/ci-python-library.yml Outdated
Comment thread .github/workflows/ci-python-library.yml
@danipran danipran force-pushed the RATY-348/add-postgres-in-python-library branch from bb1a08c to ff74b34 Compare June 5, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant