From 912fea22f15c91221105db0c574ed2e6fa51c249 Mon Sep 17 00:00:00 2001 From: Sanket Date: Sat, 10 Jun 2023 13:48:05 +0530 Subject: [PATCH 1/2] Fix smoke tests parsing issue by adding smoke_tests.sql and husky pre-commit hook --- node_modules/.bin/husky | 12 ++++++ node_modules/.bin/husky.cmd | 17 ++++++++ node_modules/.bin/husky.ps1 | 28 +++++++++++++ node_modules/.package-lock.json | 22 ++++++++++ node_modules/husky/LICENSE | 21 ++++++++++ node_modules/husky/README.md | 38 ++++++++++++++++++ node_modules/husky/husky.sh | 36 +++++++++++++++++ node_modules/husky/lib/bin.d.ts | 2 + node_modules/husky/lib/bin.js | 30 ++++++++++++++ node_modules/husky/lib/index.d.ts | 4 ++ node_modules/husky/lib/index.js | 67 +++++++++++++++++++++++++++++++ node_modules/husky/package.json | 41 +++++++++++++++++++ package-lock.json | 35 ++++++++++++++++ package.json | 5 +++ smoke_tests.sql | 20 +++++++++ 15 files changed, 378 insertions(+) create mode 100644 node_modules/.bin/husky create mode 100644 node_modules/.bin/husky.cmd create mode 100644 node_modules/.bin/husky.ps1 create mode 100644 node_modules/.package-lock.json create mode 100644 node_modules/husky/LICENSE create mode 100644 node_modules/husky/README.md create mode 100644 node_modules/husky/husky.sh create mode 100644 node_modules/husky/lib/bin.d.ts create mode 100644 node_modules/husky/lib/bin.js create mode 100644 node_modules/husky/lib/index.d.ts create mode 100644 node_modules/husky/lib/index.js create mode 100644 node_modules/husky/package.json create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 smoke_tests.sql diff --git a/node_modules/.bin/husky b/node_modules/.bin/husky new file mode 100644 index 00000000..4f96c887 --- /dev/null +++ b/node_modules/.bin/husky @@ -0,0 +1,12 @@ +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; +esac + +if [ -x "$basedir/node" ]; then + exec "$basedir/node" "$basedir/../husky/lib/bin.js" "$@" +else + exec node "$basedir/../husky/lib/bin.js" "$@" +fi diff --git a/node_modules/.bin/husky.cmd b/node_modules/.bin/husky.cmd new file mode 100644 index 00000000..c7b89a9e --- /dev/null +++ b/node_modules/.bin/husky.cmd @@ -0,0 +1,17 @@ +@ECHO off +GOTO start +:find_dp0 +SET dp0=%~dp0 +EXIT /b +:start +SETLOCAL +CALL :find_dp0 + +IF EXIST "%dp0%\node.exe" ( + SET "_prog=%dp0%\node.exe" +) ELSE ( + SET "_prog=node" + SET PATHEXT=%PATHEXT:;.JS;=;% +) + +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\husky\lib\bin.js" %* diff --git a/node_modules/.bin/husky.ps1 b/node_modules/.bin/husky.ps1 new file mode 100644 index 00000000..d3f34ba1 --- /dev/null +++ b/node_modules/.bin/husky.ps1 @@ -0,0 +1,28 @@ +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + # Support pipeline input + if ($MyInvocation.ExpectingInput) { + $input | & "$basedir/node$exe" "$basedir/../husky/lib/bin.js" $args + } else { + & "$basedir/node$exe" "$basedir/../husky/lib/bin.js" $args + } + $ret=$LASTEXITCODE +} else { + # Support pipeline input + if ($MyInvocation.ExpectingInput) { + $input | & "node$exe" "$basedir/../husky/lib/bin.js" $args + } else { + & "node$exe" "$basedir/../husky/lib/bin.js" $args + } + $ret=$LASTEXITCODE +} +exit $ret diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 00000000..3c723293 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,22 @@ +{ + "name": "WarpSQL", + "lockfileVersion": 2, + "requires": true, + "packages": { + "node_modules/husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + } + } +} diff --git a/node_modules/husky/LICENSE b/node_modules/husky/LICENSE new file mode 100644 index 00000000..049c9dc4 --- /dev/null +++ b/node_modules/husky/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 typicode + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/husky/README.md b/node_modules/husky/README.md new file mode 100644 index 00000000..adfd3773 --- /dev/null +++ b/node_modules/husky/README.md @@ -0,0 +1,38 @@ +# husky + +> Modern native Git hooks made easy + +Husky improves your commits and more 🐶 *woof!* + +# Install + +``` +npm install husky --save-dev +``` + +# Usage + +Edit `package.json > prepare` script and run it once: + +```sh +npm pkg set scripts.prepare="husky install" +npm run prepare +``` + +Add a hook: + +```sh +npx husky add .husky/pre-commit "npm test" +git add .husky/pre-commit +``` + +Make a commit: + +```sh +git commit -m "Keep calm and commit" +# `npm test` will run +``` + +# Documentation + +https://typicode.github.io/husky diff --git a/node_modules/husky/husky.sh b/node_modules/husky/husky.sh new file mode 100644 index 00000000..cec959a6 --- /dev/null +++ b/node_modules/husky/husky.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env sh +if [ -z "$husky_skip_init" ]; then + debug () { + if [ "$HUSKY_DEBUG" = "1" ]; then + echo "husky (debug) - $1" + fi + } + + readonly hook_name="$(basename -- "$0")" + debug "starting $hook_name..." + + if [ "$HUSKY" = "0" ]; then + debug "HUSKY env variable is set to 0, skipping hook" + exit 0 + fi + + if [ -f ~/.huskyrc ]; then + debug "sourcing ~/.huskyrc" + . ~/.huskyrc + fi + + readonly husky_skip_init=1 + export husky_skip_init + sh -e "$0" "$@" + exitCode="$?" + + if [ $exitCode != 0 ]; then + echo "husky - $hook_name hook exited with code $exitCode (error)" + fi + + if [ $exitCode = 127 ]; then + echo "husky - command not found in PATH=$PATH" + fi + + exit $exitCode +fi diff --git a/node_modules/husky/lib/bin.d.ts b/node_modules/husky/lib/bin.d.ts new file mode 100644 index 00000000..b7988016 --- /dev/null +++ b/node_modules/husky/lib/bin.d.ts @@ -0,0 +1,2 @@ +#!/usr/bin/env node +export {}; diff --git a/node_modules/husky/lib/bin.js b/node_modules/husky/lib/bin.js new file mode 100644 index 00000000..b867ba58 --- /dev/null +++ b/node_modules/husky/lib/bin.js @@ -0,0 +1,30 @@ +#!/usr/bin/env node +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const p = require("path"); +const h = require("./"); +function help(code) { + console.log(`Usage: + husky install [dir] (default: .husky) + husky uninstall + husky set|add [cmd]`); + process.exit(code); +} +const [, , cmd, ...args] = process.argv; +const ln = args.length; +const [x, y] = args; +const hook = (fn) => () => !ln || ln > 2 ? help(2) : fn(x, y); +const cmds = { + install: () => (ln > 1 ? help(2) : h.install(x)), + uninstall: h.uninstall, + set: hook(h.set), + add: hook(h.add), + ['-v']: () => console.log(require(p.join(__dirname, '../package.json')).version), +}; +try { + cmds[cmd] ? cmds[cmd]() : help(0); +} +catch (e) { + console.error(e instanceof Error ? `husky - ${e.message}` : e); + process.exit(1); +} diff --git a/node_modules/husky/lib/index.d.ts b/node_modules/husky/lib/index.d.ts new file mode 100644 index 00000000..52062a04 --- /dev/null +++ b/node_modules/husky/lib/index.d.ts @@ -0,0 +1,4 @@ +export declare function install(dir?: string): void; +export declare function set(file: string, cmd: string): void; +export declare function add(file: string, cmd: string): void; +export declare function uninstall(): void; diff --git a/node_modules/husky/lib/index.js b/node_modules/husky/lib/index.js new file mode 100644 index 00000000..37ef89c7 --- /dev/null +++ b/node_modules/husky/lib/index.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.uninstall = exports.add = exports.set = exports.install = void 0; +const cp = require("child_process"); +const fs = require("fs"); +const p = require("path"); +const l = (msg) => console.log(`husky - ${msg}`); +const git = (args) => cp.spawnSync('git', args, { stdio: 'inherit' }); +function install(dir = '.husky') { + if (process.env.HUSKY === '0') { + l('HUSKY env variable is set to 0, skipping install'); + return; + } + if (git(['rev-parse']).status !== 0) { + l(`git command not found, skipping install`); + return; + } + const url = 'https://typicode.github.io/husky/#/?id=custom-directory'; + if (!p.resolve(process.cwd(), dir).startsWith(process.cwd())) { + throw new Error(`.. not allowed (see ${url})`); + } + if (!fs.existsSync('.git')) { + throw new Error(`.git can't be found (see ${url})`); + } + try { + fs.mkdirSync(p.join(dir, '_'), { recursive: true }); + fs.writeFileSync(p.join(dir, '_/.gitignore'), '*'); + fs.copyFileSync(p.join(__dirname, '../husky.sh'), p.join(dir, '_/husky.sh')); + const { error } = git(['config', 'core.hooksPath', dir]); + if (error) { + throw error; + } + } + catch (e) { + l('Git hooks failed to install'); + throw e; + } + l('Git hooks installed'); +} +exports.install = install; +function set(file, cmd) { + const dir = p.dirname(file); + if (!fs.existsSync(dir)) { + throw new Error(`can't create hook, ${dir} directory doesn't exist (try running husky install)`); + } + fs.writeFileSync(file, `#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +${cmd} +`, { mode: 0o0755 }); + l(`created ${file}`); +} +exports.set = set; +function add(file, cmd) { + if (fs.existsSync(file)) { + fs.appendFileSync(file, `${cmd}\n`); + l(`updated ${file}`); + } + else { + set(file, cmd); + } +} +exports.add = add; +function uninstall() { + git(['config', '--unset', 'core.hooksPath']); +} +exports.uninstall = uninstall; diff --git a/node_modules/husky/package.json b/node_modules/husky/package.json new file mode 100644 index 00000000..1ee144bc --- /dev/null +++ b/node_modules/husky/package.json @@ -0,0 +1,41 @@ +{ + "name": "husky", + "version": "8.0.3", + "description": "Modern native Git hooks made easy", + "keywords": [ + "git", + "hooks", + "pre-commit" + ], + "homepage": "https://typicode.github.io/husky", + "repository": "typicode/husky", + "funding": "https://github.com/sponsors/typicode", + "license": "MIT", + "author": "Typicode ", + "bin": "lib/bin.js", + "main": "lib/index.js", + "files": [ + "lib", + "husky.sh" + ], + "scripts": { + "build": "tsc", + "test": "sh test/all.sh", + "lint": "eslint src --ext .ts", + "serve": "docsify serve docs", + "prepare": "npm run build && node lib/bin install", + "pre-commit": "sqlint smoke_tests.sql" + }, + "devDependencies": { + "@commitlint/cli": "^17.3.0", + "@commitlint/config-conventional": "^17.3.0", + "@tsconfig/node14": "^1.0.3", + "@types/node": "^18.11.18", + "@typicode/eslint-config": "^1.1.0", + "docsify-cli": "^4.4.4", + "typescript": "^4.9.4" + }, + "engines": { + "node": ">=14" + } +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..a3540e83 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,35 @@ +{ + "name": "WarpSQL", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "devDependencies": { + "husky": "^8.0.3" + } + }, + "node_modules/husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + } + }, + "dependencies": { + "husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..86422b22 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "husky": "^8.0.3" + } +} diff --git a/smoke_tests.sql b/smoke_tests.sql new file mode 100644 index 00000000..dd33f83e --- /dev/null +++ b/smoke_tests.sql @@ -0,0 +1,20 @@ +-- Test the connection to the database +SELECT 1; + +-- Test the creation of a table +CREATE TABLE test ( + id serial PRIMARY KEY, + name text +); + +-- Test the insertion of a row into the table +INSERT INTO test (name) VALUES ('Test'); + +-- Test the retrieval of a row from the table +SELECT * FROM test; + +-- Test the deletion of a row from the table +DELETE FROM test WHERE id = 1; + +-- Test the drop of the table +DROP TABLE test; \ No newline at end of file From 59b5a3149fbb5364156b7f57ed5df5dbc788eae1 Mon Sep 17 00:00:00 2001 From: Sanket Date: Tue, 13 Jun 2023 15:35:10 +0530 Subject: [PATCH 2/2] Update GitHub Actions workflow to use smoke_tests.sql --- .github/workflows/smoke-test.yml | 43 +++----------------------------- node_modules/husky/README.md | 38 ---------------------------- package.json | 3 +++ 3 files changed, 7 insertions(+), 77 deletions(-) delete mode 100644 node_modules/husky/README.md diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 31539d89..283e4e55 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -50,49 +50,14 @@ jobs: echo "Smoketest container is not running" exit 1 fi - if psql -c "select 1" + if psql -f ../smoke_tests.sql -v ON_ERROR_STOP=1 then - echo "Test Citus Extension" - psql -c "CREATE EXTENSION citus;" - psql -c "SELECT * FROM citus_version();" - - echo "Test Citus Distributed Table" - psql -c "CREATE TABLE test_distributed_table (id serial primary key, data text);" - psql -c "SELECT create_distributed_table('test_distributed_table', 'id');" - psql -c "INSERT INTO test_distributed_table (data) VALUES ('test data');" - psql -c "SELECT * FROM test_distributed_table;" - - echo "Test PostGIS Extension" - psql -c "CREATE EXTENSION postgis;" || true - psql -c "SELECT PostGIS_Version();" - - echo "Test PostGIS Geometry Function" - psql -c "CREATE TABLE test_geometry_table (id serial primary key, geom geometry(Point, 4326));" - psql -c "INSERT INTO test_geometry_table (geom) VALUES (ST_GeomFromText('POINT(0 0)', 4326));" - psql -c "SELECT * FROM test_geometry_table;" - - echo "Test zombodb Extension" - psql -c "CREATE EXTENSION zombodb;" - psql -c "SELECT zdb.internal_version();" - - echo "Test pg_repack Extension" - psql -c "CREATE EXTENSION pg_repack;" - psql -c "select repack.version(), repack.version_sql();" - - echo "Test pgautofailover Extension" - psql -c "CREATE EXTENSION pgautofailover CASCADE;" - psql -c "SELECT pgautofailover.formation_settings();" break fi sleep 1 done - if ! psql -c "select 1" + if ! psql -f ../smoke_tests.sql -v ON_ERROR_STOP=1 then - echo "Cannot connect to PostgreSQL" + echo "Cannot connect to PostgreSQL or smoke tests failed" exit 1 - fi - - - name: Show the logs - if: always() - run: | - docker logs smoketest-container + fi \ No newline at end of file diff --git a/node_modules/husky/README.md b/node_modules/husky/README.md deleted file mode 100644 index adfd3773..00000000 --- a/node_modules/husky/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# husky - -> Modern native Git hooks made easy - -Husky improves your commits and more 🐶 *woof!* - -# Install - -``` -npm install husky --save-dev -``` - -# Usage - -Edit `package.json > prepare` script and run it once: - -```sh -npm pkg set scripts.prepare="husky install" -npm run prepare -``` - -Add a hook: - -```sh -npx husky add .husky/pre-commit "npm test" -git add .husky/pre-commit -``` - -Make a commit: - -```sh -git commit -m "Keep calm and commit" -# `npm test` will run -``` - -# Documentation - -https://typicode.github.io/husky diff --git a/package.json b/package.json index 86422b22..3d2e86d4 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,7 @@ { + "scripts": { + "pre-commit": "sqlint smoke_tests.sql" + }, "devDependencies": { "husky": "^8.0.3" }