Skip to content

Commit

Permalink
chore: build/test normally with just Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Oct 21, 2023
1 parent e75840c commit 171a53b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push]
on: [push, pull_request]

jobs:
test:
Expand All @@ -15,5 +15,7 @@ jobs:
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests pg_${{ matrix.postgres-version }}
- name: Run tests
run: nix-shell --run "with-pg-${{ matrix.pg-version }} make installcheck"
- if: ${{ failure() }}
run: cat regression.diffs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ results/
*.control
*.so
sql/postgrest_openapi.sql
test/fixtures_ran
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ EXTVERSION = 0.0.1

DATA = $(wildcard sql/*--*.sql)

TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --use-existing --inputdir=test

all: sql/$(EXTENSION)--$(EXTVERSION).sql $(EXTENSION).control

sql/$(EXTENSION).sql:
Expand All @@ -18,6 +14,22 @@ sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
$(EXTENSION).control:
sed "s/@EXTVERSION@/$(EXTVERSION)/g" $(EXTENSION).control.in > $(EXTENSION).control

.PHONY: fixtures
fixtures:
createdb contrib_regression
psql -v ON_ERROR_STOP=1 -f test/fixtures.sql -d contrib_regression

.PHONY: clean_fixtures
clean_fixtures:
dropdb --if-exists contrib_regression

# extra dep for PostgreSQL targets in pgxs.mk
clean: clean_fixtures

TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --use-existing --inputdir=test

EXTRA_CLEAN = sql/$(EXTENSION).sql sql/$(EXTENSION)--$(EXTVERSION).sql $(EXTENSION).control

PG_CONFIG = pg_config
Expand Down
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,45 @@ SQL functions to build the OpenAPI output of a PostgREST instance.
- The first step in the roadmap is to migrate the OpenAPI spec from the PostgREST core repository (version 2.0 to 3.1):
- [x] Info object
- [x] Server object (replaces host, basePath and schemes from OAS 2.0)
- [] Components object
- [ ] Components object
- [x] Schemas (definitions in OAS 2.0)
- [ ] Security scheme (security definitions in OAS 2.0)
- [ ] Parameters
- [ ] Responses (produces in OAS 2.0 - simple implementation)
- [ ] Request bodies (consumes in OAS 2.0 - simple implementation)
- [] Paths object
- [ ] Paths object
- The next step is to fix the issues tagged with `OpenAPI` in the core repo.

## Installation

```bash
make && sudo make install
```

## Development

- Execute the script to build the PostgreSQL extension file:
For testing on your local database:

```bash
# this will load fixtures in a contrib_regression db on your local postgres
make fixtures

# run the tests, they can be run repeatedly
make installcheck

# to clean the fixtures you can use
make clean
```

```
sh scripts/build.sh
```
For an isolated and reproducible enviroment you can use [Nix](https://nixos.org/download.html).

- Run tests using [Nix](https://nixos.org/download.html):
```bash
# to run tests
nix-shell --run "with-pg-15 make installcheck"

```
nix-shell --run "with-pg-15 make installcheck"
```
# to interact with the local database with fixtures loaded
nix-shell --run "with-pg-15 psql contrib_regression"
```

## References

Expand Down
4 changes: 1 addition & 3 deletions nix/pgScript.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ let
pg_ctl start -o "$default_options" -o "${options}"
createdb contrib_regression
psql -v ON_ERROR_STOP=1 -f test/fixtures/main.sql -d contrib_regression
make fixtures
"$@"
'';
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/main.sql → test/fixtures.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
create extension postgrest_openapi;

drop schema if exists types, test cascade;
drop schema if exists types, test, private cascade;

-- Custom types
create schema types;
Expand Down

0 comments on commit 171a53b

Please sign in to comment.