Skip to content

feat: plpgsql check #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 1, 2025
Merged
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
59 changes: 46 additions & 13 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ jobs:
lint:
name: Lint Project
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- name: Checkout PR Branch
uses: actions/checkout@v4
Expand All @@ -103,6 +94,24 @@ jobs:
env:
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
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
# Wait for postgres to be ready
for _ in {1..30}; do
if docker exec postgres pg_isready -U postgres; then
break
fi
sleep 1
done

- name: Setup sqlx-cli
run: cargo install sqlx-cli

Expand Down Expand Up @@ -154,13 +163,37 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# running containers via `services` only works on linux
# https://github.com/actions/runner/issues/1866
- name: Setup postgres
# For Linux, use custom Docker image with plpgsql_check
- name: Build and start PostgreSQL with plpgsql_check
if: runner.os == 'Linux'
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
# Wait for postgres to be ready
for _ in {1..30}; do
if docker exec postgres pg_isready -U postgres; then
break
fi
sleep 1
done
# For Windows, use the action since PostgreSQL Docker image doesn't support Windows containers
- name: Setup postgres (Windows)
if: runner.os == 'Windows'
id: postgres
uses: ikalnytskyi/action-setup-postgres@v7
- name: Print Roles
run: psql ${{ steps.postgres.outputs.connection-uri }} -c "select rolname from pg_roles;"
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
docker exec postgres psql -U postgres -c "select rolname from pg_roles;"
else
psql ${{ steps.postgres.outputs.connection-uri }} -c "select rolname from pg_roles;"
fi
shell: bash
- name: Run tests
run: cargo test --workspace

Expand Down

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

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

This file was deleted.

19 changes: 19 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 @@ -76,6 +76,7 @@ pgt_lexer = { path = "./crates/pgt_lexer", version = "0.0.0" }
pgt_lexer_codegen = { path = "./crates/pgt_lexer_codegen", version = "0.0.0" }
pgt_lsp = { path = "./crates/pgt_lsp", version = "0.0.0" }
pgt_markup = { path = "./crates/pgt_markup", version = "0.0.0" }
pgt_plpgsql_check = { path = "./crates/pgt_plpgsql_check", version = "0.0.0" }
pgt_query = { path = "./crates/pgt_query", version = "0.0.0" }
pgt_query_ext = { path = "./crates/pgt_query_ext", version = "0.0.0" }
pgt_query_macros = { path = "./crates/pgt_query_macros", version = "0.0.0" }
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM postgres:15

# Install build dependencies
RUN apt-get update && \
apt-get install -y postgresql-server-dev-15 gcc make git && \
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 && \
apt-get autoremove -y && \
rm -rf /tmp/plpgsql_check /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
1 change: 1 addition & 0 deletions crates/pgt_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define_categories! {
"flags/invalid",
"project",
"typecheck",
"plpgsql_check",
"internalError/panic",
"syntax",
"dummy",
Expand Down
30 changes: 30 additions & 0 deletions crates/pgt_plpgsql_check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
authors.workspace = true
categories.workspace = true
description = "<DESCRIPTION>"
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
name = "pgt_plpgsql_check"
repository.workspace = true
version = "0.0.0"


[dependencies]
pgt_console = { workspace = true }
pgt_diagnostics = { workspace = true }
pgt_query = { workspace = true }
pgt_query_ext = { workspace = true }
pgt_schema_cache = { workspace = true }
pgt_text_size = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
tree-sitter = { workspace = true }

[dev-dependencies]
pgt_test_utils = { workspace = true }

[lib]
Loading