Skip to content

Commit 2a0d20b

Browse files
committed
chore: speed up CI
Before each pg test took almost ~15 mins. See https://github.com/supabase/supautils/actions/runs/13831763719/job/38697436630 Now each one takes 2 mins max. This is thanks to `cachix` and the centralization of the pg tooling on https://github.com/steve-chavez/nxpg. The location of this repo can be changed later. This does change the way of testing from: ``` supautils-with-pg-13 make installcheck ``` To: ``` nxpg -v 13 test ``` But the speed up is worth it.
1 parent 8227186 commit 2a0d20b

28 files changed

+110
-3279
lines changed

.github/workflows/main.yml

+54-24
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,57 @@ jobs:
1515
pg-version: ['13', '14', '15', '16', '17']
1616

1717
steps:
18-
- uses: actions/checkout@v4
19-
- uses: cachix/install-nix-action@v13
20-
with:
21-
nix_path: nixpkgs=channel:nixos-unstable
22-
- name: Run tests
23-
run: nix-shell --run "supautils-with-pg-${{ matrix.pg-version }} make installcheck"
24-
- if: ${{ failure() }}
25-
run: cat regression.diffs
18+
- uses: actions/checkout@v4
19+
20+
- name: Install Nix
21+
uses: cachix/install-nix-action@v30
22+
with:
23+
nix_path: nixpkgs=channel:nixos-unstable
24+
25+
- name: Use Cachix Cache
26+
uses: cachix/cachix-action@v10
27+
with:
28+
name: nxpg
29+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
30+
31+
- name: Build
32+
run: nix-shell --run "nxpg -v ${{ matrix.pg-version }} build"
33+
34+
- name: Run tests
35+
run: nix-shell --run "nxpg -v ${{ matrix.pg-version }} test"
36+
37+
- if: ${{ failure() }}
38+
run: cat regression.diffs
2639

2740
test-on-macos:
28-
runs-on: macos-13
41+
runs-on: macos-15
2942

3043
strategy:
3144
matrix:
32-
pg-version: ['17']
45+
pg-version: ['15']
3346

3447
steps:
35-
- uses: actions/checkout@v4
36-
- uses: cachix/install-nix-action@v30
37-
with:
38-
nix_path: nixpkgs=channel:nixos-unstable
39-
- name: Run tests
40-
run: nix-shell --run "supautils-with-pg-${{ matrix.pg-version }} make installcheck"
41-
- if: ${{ failure() }}
42-
run: cat regression.diffs
48+
- uses: actions/checkout@v4
49+
50+
- name: install nix
51+
uses: cachix/install-nix-action@v30
52+
with:
53+
nix_path: nixpkgs=channel:nixos-unstable
54+
55+
- name: use cachix cache
56+
uses: cachix/cachix-action@v10
57+
with:
58+
name: nxpg
59+
authtoken: ${{ secrets.cachix_auth_token }}
60+
61+
- name: build
62+
run: nix-shell --run "nxpg -v ${{ matrix.pg-version }} build"
63+
64+
- name: run tests
65+
run: nix-shell --run "nxpg -v ${{ matrix.pg-version }} test"
66+
67+
- if: ${{ failure() }}
68+
run: cat regression.diffs
4369

4470

4571
coverage:
@@ -52,14 +78,18 @@ jobs:
5278

5379
steps:
5480
- uses: actions/checkout@v4
81+
82+
- name: Install Nix
83+
uses: cachix/install-nix-action@v30
84+
85+
- name: Use Cachix Cache
86+
uses: cachix/cachix-action@v10
5587
with:
56-
submodules: true
57-
- uses: cachix/install-nix-action@v18
58-
with:
59-
nix_path: nixpkgs=channel:nixos-unstable
88+
name: nxpg
89+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
6090

61-
- name: Run coverage
62-
run: nix-shell --run "supautils-with-pg-${{ matrix.pg-version }} nxpg-coverage"
91+
- name: Coverage
92+
run: nix-shell --run "nxpg -v ${{ matrix.pg-version }} coverage"
6393

6494
- name: Send coverage to Coveralls
6595
uses: coverallsapp/[email protected]

Makefile

+26-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ GREP ?= grep
22
PG_CONFIG = pg_config
33

44
# the `-Wno`s quiet C90 warnings
5-
PG_CFLAGS = -std=c99 -Wextra -Wall -Werror \
5+
PG_CFLAGS = -std=c11 -Wextra -Wall -Werror \
66
-Wno-declaration-after-statement \
77
-Wno-vla \
88
-Wno-long-long
@@ -15,9 +15,14 @@ ifeq ($(COVERAGE), 1)
1515
PG_CFLAGS += --coverage
1616
endif
1717

18-
MODULE_big = supautils
18+
EXTENSION = supautils
19+
MODULE_big = $(EXTENSION)
20+
21+
SRC_DIR = src
22+
BUILD_DIR ?= build
23+
1924
SRC = $(wildcard src/*.c)
20-
OBJS = $(patsubst src/%.c, src/%.o, $(SRC))
25+
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC))
2126

2227
PG_VERSION = $(strip $(shell $(PG_CONFIG) --version | $(GREP) -oP '(?<=PostgreSQL )[0-9]+'))
2328
PG_GE16 = $(shell test $(PG_VERSION) -ge 16; echo $$?)
@@ -41,6 +46,21 @@ GENERATED_OUT = test/expected/event_triggers.out
4146
EXTRA_CLEAN = $(GENERATED_OUT)
4247

4348
PGXS := $(shell $(PG_CONFIG) --pgxs)
49+
50+
build: $(BUILD_DIR)/$(EXTENSION).so
51+
52+
PG_CPPFLAGS := $(CPPFLAGS) -DTEST=1
53+
54+
$(BUILD_DIR)/.gitignore:
55+
mkdir -p $(BUILD_DIR)
56+
echo "*" > $(BUILD_DIR)/.gitignore
57+
58+
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(BUILD_DIR)/.gitignore
59+
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
60+
61+
$(BUILD_DIR)/$(EXTENSION).so: $(EXTENSION).so
62+
mv $? $@
63+
4464
include $(PGXS)
4565

4666
.PHONY: $(GENERATED_OUT)
@@ -68,3 +88,6 @@ endif
6888
# extra dep for target in pgxs.mk
6989
installcheck: $(GENERATED_OUT)
7090

91+
.PHONY: test
92+
test:
93+
make installcheck

nix/nxpg.nix

+8-102
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,11 @@
1-
{ stdenv, lib, makeWrapper, fetchurl, writeShellScriptBin, findutils, entr, callPackage, lcov } :
1+
{ fetchFromGitHub } :
22
let
3-
prefix = "nxpg";
4-
ourPg = callPackage ./postgresql {
5-
inherit lib;
6-
inherit stdenv;
7-
inherit fetchurl;
8-
inherit makeWrapper;
9-
inherit callPackage;
3+
nxpg = fetchFromGitHub {
4+
owner = "steve-chavez";
5+
repo = "nxpg";
6+
rev = "v1.1";
7+
sha256 = "sha256-R0Z2vDjFtkrFgetL1L/N1iWN0Bh+TWBZ7VZLDARJ3pY=";
108
};
11-
supportedPgs = [
12-
ourPg.postgresql_17
13-
ourPg.postgresql_16
14-
ourPg.postgresql_15
15-
ourPg.postgresql_14
16-
ourPg.postgresql_13
17-
];
18-
build =
19-
writeShellScriptBin "${prefix}-build" ''
20-
set -euo pipefail
21-
22-
make clean
23-
make TEST=1
24-
'';
25-
buildCov =
26-
writeShellScriptBin "${prefix}-build-cov" ''
27-
set -euo pipefail
28-
29-
make clean
30-
make TEST=1 COVERAGE=1
31-
'';
32-
test =
33-
writeShellScriptBin "${prefix}-test" ''
34-
set -euo pipefail
35-
36-
make installcheck
37-
'';
38-
cov =
39-
writeShellScriptBin "${prefix}-coverage" ''
40-
set -euo pipefail
41-
42-
info_file="coverage.info"
43-
out_dir="coverage_html"
44-
45-
make installcheck
46-
${lcov}/bin/lcov --capture --directory . --output-file "$info_file"
47-
48-
# remove postgres headers on the nix store, otherwise they show on the output
49-
${lcov}/bin/lcov --remove "$info_file" '/nix/*' --output-file "$info_file" || true
50-
51-
${lcov}/bin/lcov --list coverage.info
52-
${lcov}/bin/genhtml "$info_file" --output-directory "$out_dir"
53-
54-
echo "${prefix}-coverage: To see the results, visit file://$(pwd)/$out_dir/index.html on your browser"
55-
'';
56-
watch =
57-
writeShellScriptBin "${prefix}-watch" ''
58-
set -euo pipefail
59-
60-
${findutils}/bin/find . -type f \( -name '*.c' -o -name '*.h' \) | ${entr}/bin/entr -dr "$@"
61-
'';
62-
63-
tmpDb =
64-
writeShellScriptBin "${prefix}-tmp" (builtins.readFile ./withTmpDb.sh.in);
65-
66-
allPgPaths = map (pg:
67-
let
68-
ver = builtins.head (builtins.splitVersion pg.version);
69-
script = ''
70-
set -euo pipefail
71-
72-
export PATH=${pg}/bin:"$PATH"
73-
74-
"$@"
75-
'';
76-
in
77-
writeShellScriptBin "${prefix}-${ver}" script
78-
) supportedPgs;
79-
80-
supautilsWith = map (pg:
81-
let
82-
ver = builtins.head (builtins.splitVersion pg.version);
83-
script = ''
84-
set -euo pipefail
85-
86-
export PATH=${pg}/bin:"$PATH"
87-
88-
${buildCov}/bin/${prefix}-build-cov
89-
90-
${tmpDb}/bin/${prefix}-tmp "$@"
91-
'';
92-
in
93-
writeShellScriptBin "supautils-with-pg-${ver}" script
94-
) supportedPgs;
9+
script = import nxpg;
9510
in
96-
[
97-
build
98-
buildCov
99-
test
100-
cov
101-
watch
102-
tmpDb
103-
allPgPaths
104-
supautilsWith
105-
]
11+
script

nix/postgresql/13.nix

-10
This file was deleted.

nix/postgresql/14.nix

-10
This file was deleted.

nix/postgresql/15.nix

-4
This file was deleted.

nix/postgresql/16.nix

-4
This file was deleted.

nix/postgresql/17.nix

-4
This file was deleted.

nix/postgresql/default.nix

-32
This file was deleted.

0 commit comments

Comments
 (0)