Skip to content

Commit fd28703

Browse files
authored
Maintenance: Add Linters (#28)
Add code formatters and linters to the pre-commit hook and CI tests: - check github actions - shellcheck to lint for bad practices in shell scripts - shfmt to require consistent formatting (tabs, indent case) - zig fmt checks Remove unused TOML and YAML file linters.
1 parent 8cd8d13 commit fd28703

File tree

14 files changed

+372
-332
lines changed

14 files changed

+372
-332
lines changed

.github/workflows/check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
nix develop --command -- pre-commit run --all-files --color always
3030
- name: Create local postgres installation
3131
run: |
32-
sudo chown $USER /run/postgresql
32+
sudo chown "$USER" /run/postgresql
3333
nix develop --command -- ./ci/setup.sh
3434
- name: Build and run tests
3535
run: |

ci/run.sh

Lines changed: 60 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,114 +4,106 @@
44
set -o pipefail
55

66
test_pgzx() {
7-
rc=0
8-
run_unit_tests ./ || rc=1
9-
extension_drop pgzx_unit
10-
return $rc
7+
rc=0
8+
run_unit_tests ./ || rc=1
9+
extension_drop pgzx_unit
10+
return $rc
1111
}
1212

1313
test_char_count_zig() {
14-
extension_create char_count_zig
15-
trap "extension_drop char_count_zig" INT TERM
14+
extension_create char_count_zig
15+
trap "extension_drop char_count_zig" INT TERM
1616

17-
rc=0
18-
run_regression_tests ./examples/char_count_zig || rc=1
19-
run_unit_tests ./examples/char_count_zig || rc=1
17+
rc=0
18+
run_regression_tests ./examples/char_count_zig || rc=1
19+
run_unit_tests ./examples/char_count_zig || rc=1
2020

21-
extension_drop char_count_zig
22-
return $rc
21+
extension_drop char_count_zig
22+
return $rc
2323
}
2424

2525
test_pgaudit_zig() {
26-
run_unit_tests ./examples/pgaudit_zig
26+
run_unit_tests ./examples/pgaudit_zig
2727
}
2828

29-
3029
extension_build() {
31-
cwd=$(pwd)
32-
cd $1
33-
zig build -freference-trace -p $PG_HOME
34-
cd $cwd
30+
cwd=$(pwd)
31+
cd "$1" || return 1
32+
zig build -freference-trace -p "$PG_HOME" || return 1
33+
cd "$cwd" || return 1
3534
}
3635

3736
extension_create() {
38-
echo "Create extension $1"
39-
psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS $1"
37+
echo "Create extension $1"
38+
psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS $1"
4039
}
4140

4241
extension_drop() {
43-
echo "Drop extension $1"
44-
psql -U postgres -c "DROP EXTENSION IF EXISTS $1"
42+
echo "Drop extension $1"
43+
psql -U postgres -c "DROP EXTENSION IF EXISTS $1"
4544
}
4645

4746
run_regression_tests() {
48-
echo "Run regression tests"
49-
rc=0
50-
51-
cwd=$(pwd)
52-
cd $1
53-
zig build pg_regress --verbose || rc=1
54-
cd $cwd
47+
echo "Run regression tests"
5548

56-
return $rc
49+
cwd=$(pwd)
50+
cd "$1" || return 1
51+
zig build pg_regress --verbose || return 1
52+
cd "$cwd" || return 1
5753
}
5854

5955
run_unit_tests() {
60-
echo "Run unit tests"
61-
rc=0
56+
echo "Run unit tests"
6257

63-
cwd=$(pwd)
64-
cd $1
65-
zig build -freference-trace -p $PG_HOME unit || rc=1
66-
cd $cwd
67-
68-
return $rc
58+
cwd=$(pwd)
59+
cd "$1" || return 1
60+
zig build -freference-trace -p "$PG_HOME" unit || return 1
61+
cd "$cwd" || return 1
6962
}
7063

7164
run_test_suites() {
72-
for t in "$@"; do
73-
echo "# Run $t"
74-
if ! $t; then
75-
return 1
76-
fi
77-
done
65+
for t in "$@"; do
66+
echo "# Run $t"
67+
if ! $t; then
68+
return 1
69+
fi
70+
done
7871
}
7972

80-
fail () {
81-
echo "$1" >&2
82-
exit 1
73+
fail() {
74+
echo "$1" >&2
75+
exit 1
8376
}
8477

8578
main() {
86-
echo "Build and install extension"
87-
eval $(pgenv)
88-
89-
log_init_size=0;
90-
if [ -f $PG_CLUSTER_LOG_FILE ]; then
91-
log_init_size=$(stat -c %s $PG_CLUSTER_LOG_FILE)
92-
fi
93-
echo "Server log size: $log_init_size"
79+
echo "Build and install extension"
80+
eval "$(pgenv)"
9481

95-
extension_build ./examples/char_count_zig || fail "Failed to build char_count_zig"
96-
extension_build ./examples/pgaudit_zig || fail "Failed to build pgaudit_zig"
82+
log_init_size=0
83+
if [ -f "$PG_CLUSTER_LOG_FILE" ]; then
84+
log_init_size=$(stat -c %s "$PG_CLUSTER_LOG_FILE")
85+
fi
86+
echo "Server log size: $log_init_size"
9787

98-
echo "Start PostgreSQL"
99-
pgstart || fail "Failed to start PostgreSQL"
100-
trap pgstop TERM INT EXIT
88+
extension_build ./examples/char_count_zig || fail "Failed to build char_count_zig"
89+
extension_build ./examples/pgaudit_zig || fail "Failed to build pgaudit_zig"
10190

91+
echo "Start PostgreSQL"
92+
pgstart || fail "Failed to start PostgreSQL"
93+
trap pgstop TERM INT EXIT
10294

103-
ok=true
104-
run_test_suites test_pgzx test_char_count_zig || ok=false
95+
ok=true
96+
run_test_suites test_pgzx test_char_count_zig test_pgaudit_zig || ok=false
10597

106-
if ! $ok; then
107-
echo "\n\nServer log:"
98+
if ! $ok; then
99+
printf "\n\nServer log:"
108100

109-
log_size=$(stat -c %s $PG_CLUSTER_LOG_FILE)
110-
tail -c $((log_size - log_init_size)) $PG_CLUSTER_LOG_FILE
111-
fail "Regression tests failed"
112-
fi
101+
log_size=$(stat -c %s "$PG_CLUSTER_LOG_FILE")
102+
tail -c $((log_size - log_init_size)) "$PG_CLUSTER_LOG_FILE"
103+
fail "Regression tests failed"
104+
fi
113105

114-
echo "Success!"
106+
echo "Success!"
115107
}
116108

117109
main

dev/bin/pgbuild

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,44 @@ POSTGRES_BRANCH=${POSTGRES_BRANCH:-"REL_16_STABLE"}
3636

3737
POSITIONAL_ARGS=()
3838
while [[ $# -gt 0 ]]; do
39-
case $1 in
40-
-h)
41-
echo "$USAGE"
42-
exit 0
43-
;;
44-
--repo | -r)
45-
POSTGRES_REPO="$2"
46-
shift 2
47-
;;
48-
-b | --branch)
49-
POSTGRES_BRANCH="$2"
50-
shift 2
51-
;;
52-
*)
53-
POSITIONAL_ARGS+=("$1") # save positional arg
54-
shift # past argument
55-
;;
56-
esac
39+
case $1 in
40+
-h)
41+
echo "$USAGE"
42+
exit 0
43+
;;
44+
--repo | -r)
45+
POSTGRES_REPO="$2"
46+
shift 2
47+
;;
48+
-b | --branch)
49+
POSTGRES_BRANCH="$2"
50+
shift 2
51+
;;
52+
*)
53+
POSITIONAL_ARGS+=("$1") # save positional arg
54+
shift # past argument
55+
;;
56+
esac
5757
done
5858
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
5959

6060
clone() {
61-
echo "Downloading postgres source from $POSTGRES_REPO"
61+
echo "Downloading postgres source from $POSTGRES_REPO"
6262

63-
if [ -d "$PG_SRC_DIR" ] && [ -n "$(ls -A $PG_SRC_DIR)" ]; then
64-
echo "The directory $PG_SRC_DIR already exists and is not empty. Aborting."
65-
return 0
66-
fi
63+
if [ -d "$PG_SRC_DIR" ] && [ -n "$(ls -A "$PG_SRC_DIR")" ]; then
64+
echo "The directory $PG_SRC_DIR already exists and is not empty. Aborting."
65+
return 0
66+
fi
6767

68-
mkdir -p $(dirname $PG_SRC_DIR)
69-
git clone --single-branch -b ${POSTGRES_BRANCH} ${POSTGRES_REPO} $PG_SRC_DIR
68+
mkdir -p "$(dirname "$PG_SRC_DIR")"
69+
git clone --single-branch -b "$POSTGRES_BRANCH" "$POSTGRES_REPO" "$PG_SRC_DIR"
7070
}
7171

7272
patch() {
73-
# The meson scripts assume that clang is part of the LLVM suite, which is used when
74-
# enabling the jit build (which we do).
75-
# Unfortunately the is not always the case. We work around this by patching the build scripts:
76-
git -C "$PG_SRC_DIR" apply - <<EOF
73+
# The meson scripts assume that clang is part of the LLVM suite, which is used when
74+
# enabling the jit build (which we do).
75+
# Unfortunately the is not always the case. We work around this by patching the build scripts:
76+
git -C "$PG_SRC_DIR" apply - <<EOF
7777
diff --git a/meson.build b/meson.build
7878
index 6804f941be..d62142c8f7 100644
7979
--- a/meson.build
@@ -91,18 +91,18 @@ EOF
9191
}
9292

9393
configure() {
94-
echo "Configuring postgres build"
95-
96-
patch
97-
98-
meson setup "$PG_BUILD_DIR" "$PG_SRC_DIR" \
99-
--debug \
100-
-Dprefix=${PG_INSTALL_DIR} \
101-
-Dbindir=${PG_INSTALL_DIR}/bin \
102-
-Ddatadir=${PG_INSTALL_DIR}/share \
103-
-Dincludedir=${PG_INSTALL_DIR}/include \
104-
-Dlibdir=${PG_INSTALL_DIR}/lib \
105-
-Dsysconfdir=${PG_INSTALL_DIR}/etc \
94+
echo "Configuring postgres build"
95+
96+
patch
97+
98+
meson setup "$PG_BUILD_DIR" "$PG_SRC_DIR" \
99+
--debug \
100+
-Dprefix="${PG_INSTALL_DIR}" \
101+
-Dbindir="${PG_INSTALL_DIR}/bin" \
102+
-Ddatadir="${PG_INSTALL_DIR}/share" \
103+
-Dincludedir="${PG_INSTALL_DIR}/include" \
104+
-Dlibdir="${PG_INSTALL_DIR}/lib" \
105+
-Dsysconfdir="${PG_INSTALL_DIR}/etc" \
106106
-Dplperl=auto \
107107
-Dplpython=auto \
108108
-Dssl=openssl \
@@ -121,43 +121,43 @@ configure() {
121121
}
122122

123123
build() {
124-
echo "Building postgres"
124+
echo "Building postgres"
125125

126126
ninja -C "$PG_BUILD_DIR"
127127
}
128128

129129
install() {
130-
echo "Installing postgres to $PG_INSTALL_DIR"
130+
echo "Installing postgres to $PG_INSTALL_DIR"
131131

132-
mkdir -p ${PG_INSTALL_DIR}
133-
ninja -C ${PG_BUILD_DIR} install
132+
mkdir -p "${PG_INSTALL_DIR}"
133+
ninja -C "${PG_BUILD_DIR}" install
134134
}
135135

136136
# The first argument determines the function to run. If no argument is given we run all commands in order:
137137

138138
if [ -z "$1" ]; then
139-
clone && configure && build && install
140-
exit 0
139+
clone && configure && build && install
140+
exit 0
141141
fi
142142

143143
case $1 in
144-
clone)
145-
clone
146-
;;
147-
patch)
148-
patch
149-
;;
150-
configure)
151-
configure
152-
;;
153-
build)
154-
build
155-
;;
156-
install)
157-
install
158-
;;
159-
*)
160-
echo "Usage: $0 {clone|configure|build|install}"
161-
exit 1
162-
;;
144+
clone)
145+
clone
146+
;;
147+
patch)
148+
patch
149+
;;
150+
configure)
151+
configure
152+
;;
153+
build)
154+
build
155+
;;
156+
install)
157+
install
158+
;;
159+
*)
160+
echo "Usage: $0 {clone|configure|build|install}"
161+
exit 1
162+
;;
163163
esac

0 commit comments

Comments
 (0)