Skip to content

Commit 0d53010

Browse files
committed
ci: add testing workflow
1 parent 4504c61 commit 0d53010

File tree

5 files changed

+187
-61
lines changed

5 files changed

+187
-61
lines changed

.github/workflows/testing.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Run tests
2+
on: [push, pull_request]
3+
defaults:
4+
run:
5+
shell: bash
6+
7+
jobs:
8+
setup:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Setup repository
12+
uses: actions/checkout@v4
13+
- name: Setup NodeJS
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
cache: 'npm'
18+
- name: Setup environment
19+
run: |
20+
sudo apt-get install -y build-essential wget
21+
npm install --save-dev
22+
- name: Build extension
23+
run: npm run compile
24+
- name: Install databases
25+
run: |
26+
./src/test/setup.sh -j 4 --pg-version=17
27+
./src/test/setup.sh -j 4 --pg-version=16
28+
./src/test/setup.sh -j 4 --pg-version=15
29+
./src/test/setup.sh -j 4 --pg-version=14
30+
./src/test/setup.sh -j 4 --pg-version=13
31+
./src/test/setup.sh -j 4 --pg-version=12
32+
./src/test/setup.sh -j 4 --pg-version=11
33+
./src/test/setup.sh -j 4 --pg-version=10
34+
./src/test/setup.sh -j 4 --pg-version=9.6
35+
- uses: actions/upload-artifact@v4
36+
with:
37+
name: prepared-env
38+
path: |
39+
pgsrc
40+
node_modules
41+
out
42+
43+
test:
44+
needs: setup
45+
runs-on: ubuntu-latest
46+
strategy:
47+
fail-fast: false
48+
max-parallel: 1
49+
matrix:
50+
pgversion: ['17', '16']
51+
vscodeversion: ['stable']
52+
debugger: ['cppdbg', 'lldb']
53+
steps:
54+
- name: Setup repository
55+
uses: actions/checkout@v4
56+
- name: Setup NodeJS
57+
uses: actions/setup-node@v4
58+
with:
59+
node-version: '20.x'
60+
cache: 'npm'
61+
- name: Download artifacts
62+
uses: actions/download-artifact@v4
63+
- name: Run test
64+
run: ./src/test/test.sh -j 4 --no-gui \
65+
--pg-versions="${{ matrix.pgversion }}" \
66+
--vscode-versions="${{ matrix.vscodeversion }}" \
67+
--debuggers="${{ matrix.debugger }}"
68+

src/test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Example usage:
2828
./src/test/setup.sh --pg-version=17.4
2929
```
3030

31-
After that, source code, binaries and database will be installed in `./pgsrc`, `./pgsrc/build` and `./pgsrc/data` accordingly (starting from extension directory root).
31+
After that, source code, binaries and database will be installed in `./pgsrc/VERSION`, `./pgsrc/VERSION/build` and `./pgsrc/VERSION/data` accordingly (starting from extension directory root), where `VERSION` - is a major version of PostgreSQL.
3232

3333
To run tests use `./src/test/test.sh` script:
3434

src/test/runTests.ts

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,40 @@ import { downloadAndUnzipVSCode,
55
resolveCliArgsFromVSCodeExecutablePath,
66
runTests } from '@vscode/test-electron';
77

8-
function getDebuggerExtensionId() {
9-
const debuggerType = process.env.PGHH_DEBUGGER;
10-
if (!debuggerType || debuggerType === 'cppdbg') {
8+
function getDebuggerExtensionId(debuggerType: string) {
9+
if (debuggerType === 'cppdbg') {
1110
return 'ms-vscode.cpptools';
12-
} else if (debuggerType == 'lldb') {
13-
return 'vadimcn.vscode-lldb';
1411
} else {
15-
throw new Error(`Unknown debugger type: ${debuggerType}`);
12+
return 'vadimcn.vscode-lldb';
1613
}
1714
}
1815

16+
function getPgsrcDir(extPath: string, version: string) {
17+
return path.join(extPath, 'pgsrc', version);
18+
}
19+
20+
function getTestEnv() {
21+
const pgVersion = process.env.PGHH_PG_VERSION;
22+
const debuggerType = process.env.PGHH_DEBUGGER ?? 'cppdbg';
23+
const vscodeVersion = process.env.PGHH_VSCODE_VERSION ?? 'stable';
24+
25+
if (!pgVersion) {
26+
throw new Error('PGHH_PG_VERSION env variable is not set');
27+
}
28+
29+
if (!debuggerType) {
30+
throw new Error('PGHH_DEBUGGER env variable is not set');
31+
}
32+
33+
if (!['cppdbg', 'lldb'].includes(debuggerType)) {
34+
throw new Error(`Debugger ${debuggerType} is not supported`);
35+
}
36+
37+
return {pgVersion, debuggerType, vscodeVersion};
38+
}
39+
1940
async function main() {
20-
let error = false;
21-
/*
41+
/*
2242
* The folder containing the Extension Manifest package.json.
2343
* Passed to `--extensionDevelopmentPath`
2444
*/
@@ -28,28 +48,29 @@ async function main() {
2848
* Passed to --extensionTestsPath
2949
*/
3050
const extensionTestsPath = path.resolve(__dirname, './suite/index');
51+
52+
const testEnv = getTestEnv();
53+
3154
/*
3255
* The path to source code of PostgreSQL we are testing now
3356
*/
34-
const pgsrcDir = path.resolve(extensionDevelopmentPath, './pgsrc');
57+
const pgsrcDir = getPgsrcDir(extensionDevelopmentPath, testEnv.pgVersion);
58+
const vscodeExecutablePath = await downloadAndUnzipVSCode(testEnv.vscodeVersion);
59+
const [cliPath, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
3560

61+
/* Install required debugger extension */
62+
const dbgExtId = getDebuggerExtensionId(testEnv.debuggerType);
63+
cp.spawnSync(cliPath, [...args, '--install-extension', dbgExtId],
64+
{ encoding: 'utf-8', stdio: 'inherit'});
65+
66+
/* Run PostgreSQL */
67+
cp.spawnSync('/bin/bash', ['./run.sh', '--run'], {
68+
cwd: pgsrcDir,
69+
stdio: 'inherit',
70+
encoding: 'utf-8',
71+
});
72+
3673
try {
37-
const vscodeVersion = process.env.PGHH_VSCODE_VERSION ?? 'stable';
38-
const vscodeExecutablePath = await downloadAndUnzipVSCode(vscodeVersion);
39-
const [cliPath, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
40-
41-
/* Install required debugger extension */
42-
const dbgExtId = getDebuggerExtensionId();
43-
cp.spawnSync(cliPath, [...args, '--install-extension', dbgExtId],
44-
{ encoding: 'utf-8', stdio: 'inherit'});
45-
46-
/* Run PostgreSQL */
47-
cp.spawnSync('/bin/bash', ['./run.sh', '--run'], {
48-
cwd: pgsrcDir,
49-
stdio: 'inherit',
50-
encoding: 'utf-8',
51-
});
52-
5374
/* Start tests */
5475
await runTests({
5576
extensionDevelopmentPath,
@@ -62,21 +83,19 @@ async function main() {
6283
'--enable-proposed-api', dbgExtId,
6384
],
6485
});
65-
} catch (err) {
66-
console.error(err);
67-
console.error('Failed to run tests');
68-
error = true;
69-
}
70-
71-
cp.spawnSync('/bin/bash', ['./run.sh', '--stop'], {
72-
cwd: pgsrcDir,
73-
stdio: 'inherit',
74-
encoding: 'utf-8',
75-
});
76-
77-
if (error) {
78-
process.exit(1);
86+
} finally {
87+
cp.spawnSync('/bin/bash', ['./run.sh', '--stop'], {
88+
cwd: pgsrcDir,
89+
stdio: 'inherit',
90+
encoding: 'utf-8',
91+
});
7992
}
8093
}
8194

82-
main();
95+
try {
96+
main();
97+
} catch (err) {
98+
console.error(err);
99+
console.error('Failed to run tests');
100+
process.exit(1);
101+
}

src/test/setup.sh

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ function print_help {
44
cat <<EOM
55
Setup environment for PostgreSQL Hacker Helper extension testing.
66
This script downloads specified PostgreSQL version (source code), applies patch, runs build and setups database (initdb + initial schema).
7-
Source code is installed to EXT_SRC/pgsrc, where EXT_SRC - root directory of extension.
7+
Source code is installed to EXT_SRC/pgsrc/PG_VERSION, where EXT_SRC - root directory of extension and PG_VERSION - major PostgreSQL version.
88
99
Usage: $0 --pg-version=17
1010
1111
Options:
1212
-h, --help Print this help message
1313
--pg-version Major version of PostgreSQL to install.
1414
--threads Number of threads to use during build
15+
--force Remove old installation if it exists.
1516
1617
Supported PG versions from 17 to 9.6 inclusive.
1718
@@ -21,17 +22,21 @@ Example:
2122
EOM
2223
}
2324

24-
ARG_PG_VERSION=""
25+
MAJOR_PG_VERSION=""
2526
THREADS="1"
27+
FORCE=""
2628
while [ "$1" ]; do
2729
ARG="$1"
2830
case "$ARG" in
2931
--pg-version=*)
30-
ARG_PG_VERSION="${ARG#*=}"
32+
MAJOR_PG_VERSION="${ARG#*=}"
3133
;;
3234
--threads=*)
3335
THREADS="${ARG#*=}"
3436
;;
37+
--force)
38+
FORCE="1"
39+
;;
3540
-j)
3641
shift
3742
THREADS="$1"
@@ -51,13 +56,13 @@ done
5156
# Exit on error
5257
set -e -o pipefail
5358

54-
if [[ -z "$ARG_PG_VERSION" ]]; then
59+
if [[ -z "$MAJOR_PG_VERSION" ]]; then
5560
echo "--pg-version is not set - specify PostgreSQL version"
5661
exit 1
5762
fi
5863

5964
PG_VERSION=""
60-
case "$ARG_PG_VERSION" in
65+
case "$MAJOR_PG_VERSION" in
6166
'17')
6267
PG_VERSION='17.4'
6368
;;
@@ -86,38 +91,49 @@ case "$ARG_PG_VERSION" in
8691
PG_VERSION='9.6.24'
8792
;;
8893
*)
89-
echo "Version $ARG_PG_VERSION is not supported"
94+
echo "Version $MAJOR_PG_VERSION is not supported"
9095
echo "Supported version from 17 to 9.6 inclusive"
9196
exit 1
9297
;;
9398
esac
9499

95100
# Normalize path - switch to extension root
101+
ls
102+
pwd
96103
cd "$(dirname ${BASH_SOURCE[0]:-$0})/../.."
97104
EXT_ROOT_DIR="$PWD"
98105

99-
CFLAGS="-O0 -g $CFLAGS"
100-
CPPFLAGS="-O0 -g $CPPFLAGS"
101106
PATCH_FILE="$EXT_ROOT_DIR/src/test/patches/pg${PG_VERSION}.patch"
102107
PG_SRC_DOWNLOAD_URL="https://ftp.postgresql.org/pub/source/v${PG_VERSION}/postgresql-${PG_VERSION}.tar.gz"
103-
CACHEDIR="$PWD/src/test/cache"
108+
CACHEDIR="$EXT_ROOT_DIR/src/test/cache"
104109
TARFILE="$CACHEDIR/postgresql-${PG_VERSION}.tar.gz"
105-
SRC_PATH="$EXT_ROOT_DIR/pgsrc"
106-
INSTALL_PATH="$EXT_ROOT_DIR/pgsrc/build"
107-
LOGDIR="$PWD/src/test/log"
110+
SRC_PATH="$EXT_ROOT_DIR/pgsrc/$MAJOR_PG_VERSION"
111+
INSTALL_PATH="$SRC_PATH/build"
112+
LOGDIR="$EXT_ROOT_DIR/src/test/log"
108113
LOGFILE="$LOGDIR/setup_$(date +%Y%m%d%H%M).log"
114+
115+
set -e -o pipefail
116+
117+
{
118+
119+
if [[ -d "$SRC_PATH" ]]; then
120+
if [[ -z "$FORCE" ]]; then
121+
echo "Installation already exists. Use --force to remove old src dir"
122+
exit 0
123+
else
124+
rm -rf "$SRC_PATH"
125+
fi
126+
fi
127+
109128
mkdir -p "$LOGDIR"
110129

111130
# Download PostgreSQL source code into it's directory and apply patch
112-
{
113-
set -e -o pipefail
114-
rm -rf "$SRC_PATH"
115131
mkdir -p "$SRC_PATH"
116132
mkdir -p "$CACHEDIR"
117133
if [[ ! -f "$TARFILE" ]]; then
118-
wget "$PG_SRC_DOWNLOAD_URL" -O "$TARFILE"
134+
wget -q "$PG_SRC_DOWNLOAD_URL" -O "$TARFILE"
119135
fi
120-
tar -xvzf "$TARFILE" -C "$SRC_PATH" --strip-components=1
136+
tar -xvzf "$TARFILE" -C "$SRC_PATH" --strip-components=1 1>/dev/null
121137
cd "$SRC_PATH"
122138
patch -p1 -i "$PATCH_FILE"
123139

@@ -127,8 +143,22 @@ patch -p1 -i "$PATCH_FILE"
127143
--enable-debug \
128144
--enable-cassert \
129145
--without-openssl \
130-
CFLAGS="$CFLAGS" \
131-
CPPFLAGS="$CPPFLAGS"
146+
--without-readline \
147+
--without-python \
148+
--without-tcl \
149+
--without-pam \
150+
--without-selinux \
151+
--without-icu \
152+
--without-ldap \
153+
--without-libxml \
154+
--without-libxslt \
155+
--without-bonjour \
156+
--without-lz4 \
157+
--without-zstd \
158+
--without-llvm \
159+
--without-zlib \
160+
CFLAGS="-O0 -g3 $CFLAGS" \
161+
CPPFLAGS="-O0 -g3 $CPPFLAGS"
132162

133163
# Setup special file with
134164
ENV_PATH="${PWD}/env.sh"

src/test/test.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Options:
1919
--debuggers List of debug extensions to tests against
2020
--no-rebuild Do not rebuild PostgreSQL at first run.
2121
Useful during development when installation already present.
22+
--no-gui Run tests without GUI (using 'xvfb')
2223
2324
Supported PG versions from 17 to 9.6 inclusive.
2425
Default value: $DEFAULT_PG_VERSIONS
@@ -44,6 +45,7 @@ THREADS=""
4445
PG_VERSIONS=""
4546
DEBUGGERS=""
4647
NO_REBUILD=""
48+
NO_GUI=""
4749
while [ "$1" ]; do
4850
ARG="$1"
4951
case "$ARG" in
@@ -70,6 +72,9 @@ while [ "$1" ]; do
7072
--no-rebuild)
7173
NO_REBUILD="1"
7274
;;
75+
--no-gui)
76+
NO_GUI="1"
77+
;;
7378
*)
7479
echo "Unknown option: $1"
7580
exit 1
@@ -111,7 +116,11 @@ for PGVERSION in $PG_VERSIONS; do
111116
echo "Testing PostgreSQL $PGVERSION in VS Code $VSCODEVERSION using $DEBUGGER"
112117
export PGHH_DEBUGGER="$DEBUGGER"
113118

114-
npm test
119+
if [[ -z "$NO_GUI" ]]; then
120+
npm test
121+
else
122+
xvfb-run -a npm test
123+
fi
115124
} 2>&1 | tee "$LOGFILE"
116125
done
117126
done

0 commit comments

Comments
 (0)