Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 66 additions & 8 deletions .github/actions/setup-postgres/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ runs:
echo "Extension directory: $(pg_config --sharedir)/extension"
echo "Library directory: $(pg_config --pkglibdir)"

# Clone and build plpgsql_check
# Clone and build plpgsql_check (clone to /tmp to avoid workspace conflicts)
cd /tmp
git clone https://github.com/okbob/plpgsql_check.git
cd plpgsql_check

Expand All @@ -53,30 +54,77 @@ runs:
echo "Extension library files:"
ls -la "$(pg_config --pkglibdir)/" | grep plpgsql || echo "No plpgsql_check library found"

# Install the pglpgsql_check extension on macOS (Part 2)
- name: Create extension in database
# Install the pglinter extension on macOS (pgrx-based Rust extension)
- name: Install and compile pglinter
if: runner.os == 'macOS'
shell: bash
run: |
# First, ensure we're using the same PostgreSQL that the action installed
export PATH="$(pg_config --bindir):$PATH"

# Install cargo-pgrx (version must match pglinter's pgrx dependency)
cargo install cargo-pgrx --version 0.16.1 --locked

# Determine postgres version for pgrx init
PG_VERSION=$(pg_config --version | grep -oE '[0-9]+' | head -1)
echo "PostgreSQL version: $PG_VERSION"

# Initialize pgrx for the installed PostgreSQL version
cargo pgrx init --pg${PG_VERSION} $(which pg_config)

# Clone and build pglinter (clone to /tmp to avoid workspace conflicts)
cd /tmp
git clone https://github.com/pmpetit/pglinter.git
cd pglinter

# Install using pgrx
cargo pgrx install --pg-config $(which pg_config) --release

# Verify installation
echo "Extension control files:"
ls -la "$(pg_config --sharedir)/extension/" | grep pglinter || echo "No pglinter found"

echo "Extension library files:"
ls -la "$(pg_config --pkglibdir)/" | grep pglinter || echo "No pglinter library found"

# Create extensions in database on macOS
- name: Create extensions in database
if: runner.os == 'macOS'
shell: bash
env:
PGSERVICE: ${{ steps.postgres.outputs.service-name }}
run: |
psql -c "CREATE EXTENSION plpgsql_check;"
psql -c "CREATE EXTENSION pglinter;"

# Verify installation
psql -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'plpgsql_check';"
psql -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('plpgsql_check', 'pglinter');"

# For Linux, use custom Docker image with plpgsql_check and pglinter
- name: Set up Docker Buildx
if: runner.os == 'Linux'
uses: docker/setup-buildx-action@v3

# For Linux, use custom Docker image with plpgsql_check
- name: Build and start PostgreSQL with plpgsql_check
- name: Build PostgreSQL image with cache
if: runner.os == 'Linux'
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: postgres-language-server-dev:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Start PostgreSQL container
if: runner.os == 'Linux'
shell: bash
run: |
docker build -t postgres-plpgsql-check:latest .
docker run -d --name postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-p 5432:5432 \
postgres-plpgsql-check:latest
postgres-language-server-dev:latest
# Wait for postgres to be ready
for _ in {1..30}; do
if docker exec postgres pg_isready -U postgres; then
Expand All @@ -85,3 +133,13 @@ runs:
sleep 1
done

# Create extensions in postgres database only (NOT template1)
# This avoids polluting test databases - tests that need extensions can create them explicitly
echo "Creating extensions in postgres database..."
docker exec postgres psql -U postgres -c "CREATE SCHEMA IF NOT EXISTS extensions;"
docker exec postgres psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS plpgsql_check SCHEMA extensions;"
docker exec postgres psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS pglinter SCHEMA extensions;"

# Show extension status
docker exec postgres psql -U postgres -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('plpgsql_check', 'pglinter');"

17 changes: 14 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,26 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# we need to use the same database as we do locally for sqlx prepare to output the same hashes
- name: Build and start PostgreSQL with plpgsql_check
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build PostgreSQL image with cache
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: postgres-language-server-dev:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Start PostgreSQL
run: |
docker build -t postgres-plpgsql-check:latest .
docker run -d --name postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-p 5432:5432 \
postgres-plpgsql-check:latest
postgres-language-server-dev:latest
# Wait for postgres to be ready
for _ in {1..30}; do
if docker exec postgres pg_isready -U postgres; then
Expand Down
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pgls_lexer = { path = "./crates/pgls_lexer", version = "0.0.0"
pgls_lexer_codegen = { path = "./crates/pgls_lexer_codegen", version = "0.0.0" }
pgls_lsp = { path = "./crates/pgls_lsp", version = "0.0.0" }
pgls_markup = { path = "./crates/pgls_markup", version = "0.0.0" }
pgls_pglinter = { path = "./crates/pgls_pglinter", version = "0.0.0" }
pgls_plpgsql_check = { path = "./crates/pgls_plpgsql_check", version = "0.0.0" }
pgls_query = { path = "./crates/pgls_query", version = "0.0.0" }
pgls_query_ext = { path = "./crates/pgls_query_ext", version = "0.0.0" }
Expand Down
33 changes: 28 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,38 @@ FROM postgres:15

# Install build dependencies
RUN apt-get update && \
apt-get install -y postgresql-server-dev-15 gcc make git && \
apt-get install -y postgresql-server-dev-15 gcc make git curl pkg-config libssl-dev libclang-dev clang && \
# Install plpgsql_check (C extension - simple make install)
cd /tmp && \
git clone https://github.com/okbob/plpgsql_check.git && \
cd plpgsql_check && \
make && \
make install && \
apt-get remove -y postgresql-server-dev-15 gcc make git && \
cd /tmp && \
rm -rf /tmp/plpgsql_check && \
# Install Rust for pglinter (pgrx-based extension)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
. $HOME/.cargo/env && \
# Install cargo-pgrx (version must match pglinter's pgrx dependency)
cargo install cargo-pgrx --version 0.16.1 --locked && \
# Initialize pgrx for PostgreSQL 15
cargo pgrx init --pg15 $(which pg_config) && \
# Clone and build pglinter
cd /tmp && \
git clone https://github.com/pmpetit/pglinter.git && \
cd pglinter && \
cargo pgrx install --pg-config $(which pg_config) --release && \
# Cleanup Rust and build dependencies
rm -rf /tmp/pglinter $HOME/.cargo $HOME/.rustup && \
apt-get remove -y gcc make git curl pkg-config libssl-dev libclang-dev clang && \
apt-get autoremove -y && \
rm -rf /tmp/plpgsql_check /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/*

# Add initialization script directly
RUN echo "CREATE EXTENSION IF NOT EXISTS plpgsql_check;" > /docker-entrypoint-initdb.d/01-create-extension.sql
# Add initialization script for extensions
# Only create in postgres database (NOT template1) to avoid polluting test databases
# Tests that need extensions can create them explicitly
RUN printf '%s\n' \
"CREATE SCHEMA IF NOT EXISTS extensions;" \
"CREATE EXTENSION IF NOT EXISTS plpgsql_check SCHEMA extensions;" \
"CREATE EXTENSION IF NOT EXISTS pglinter SCHEMA extensions;" \
> /docker-entrypoint-initdb.d/01-create-extension.sql
6 changes: 4 additions & 2 deletions crates/pgls_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ mimalloc = "0.1.43"
tikv-jemallocator = "0.6.0"

[dev-dependencies]
assert_cmd = "2.0.16"
insta = { workspace = true, features = ["yaml"] }
assert_cmd = "2.0.16"
insta = { workspace = true, features = ["yaml"] }
pgls_test_utils = { workspace = true }
sqlx = { workspace = true }

[lib]
doctest = false
Expand Down
10 changes: 9 additions & 1 deletion crates/pgls_cli/src/commands/dblint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Instant;
use crate::cli_options::CliOptions;
use crate::reporter::Report;
use crate::{CliDiagnostic, CliSession, VcsIntegration};
use pgls_analyse::RuleCategoriesBuilder;
use pgls_configuration::PartialConfiguration;
use pgls_diagnostics::Error;
use pgls_workspace::features::diagnostics::{PullDatabaseDiagnosticsParams, PullDiagnosticsResult};
Expand All @@ -24,10 +25,17 @@ pub fn dblint(

let start = Instant::now();

let params = PullDatabaseDiagnosticsParams {
categories: RuleCategoriesBuilder::default().all().build(),
max_diagnostics,
only: Vec::new(), // Uses configuration settings
skip: Vec::new(), // Uses configuration settings
};

let PullDiagnosticsResult {
diagnostics,
skipped_diagnostics,
} = workspace.pull_db_diagnostics(PullDatabaseDiagnosticsParams { max_diagnostics })?;
} = workspace.pull_db_diagnostics(params)?;

let report = Report::new(
diagnostics.into_iter().map(Error::from).collect(),
Expand Down
2 changes: 1 addition & 1 deletion crates/pgls_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum PgLSCommand {
#[bpaf(command)]
Version(#[bpaf(external(cli_options), hide_usage)] CliOptions),

/// Runs everything to the requested files.
/// Lints your database schema.
#[bpaf(command)]
Dblint {
#[bpaf(external(partial_configuration), hide_usage, optional)]
Expand Down
Loading