Skip to content

Commit 9a7b9f7

Browse files
committed
feat(spannerlib-node): add workflows for lint and tests, and full automation wrapper
1 parent 570928f commit 9a7b9f7

10 files changed

Lines changed: 192 additions & 18 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Node Wrapper Lint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'spannerlib/wrappers/spannerlib-node/**'
8+
pull_request:
9+
branches: [ "main" ]
10+
paths:
11+
- 'spannerlib/wrappers/spannerlib-node/**'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: spannerlib/wrappers/spannerlib-node
23+
24+
steps:
25+
- uses: actions/checkout@v6
26+
27+
- name: Set up Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '20'
31+
cache: 'npm'
32+
cache-dependency-path: spannerlib/wrappers/spannerlib-node/package.json
33+
34+
- name: Install Dependencies
35+
run: npm install
36+
37+
- name: Run Lint
38+
run: npm run lint
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Node Wrapper Unit Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'spannerlib/wrappers/spannerlib-node/**'
8+
pull_request:
9+
branches: [ "main" ]
10+
paths:
11+
- 'spannerlib/wrappers/spannerlib-node/**'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
unit-tests:
19+
name: Test ${{ matrix.os }} (Node ${{ matrix.node-version }})
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [ubuntu-latest, macos-latest, windows-latest]
25+
node-version: ['20']
26+
27+
defaults:
28+
run:
29+
shell: bash
30+
working-directory: ./spannerlib/wrappers/spannerlib-node
31+
32+
steps:
33+
- uses: actions/checkout@v6
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@v6
37+
with:
38+
go-version: '1.26.x'
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
cache: 'npm'
45+
cache-dependency-path: spannerlib/wrappers/spannerlib-node/package.json
46+
47+
- name: Install Dependencies
48+
run: npm install
49+
50+
- name: Build Addon and TS
51+
run: npm run build
52+
53+
- name: Run Unit Tests
54+
run: npm test
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
insert_final_newline = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json'),
3+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let customConfig = [];
2+
let hasIgnoresFile = false;
3+
try {
4+
require.resolve('./eslint.ignores.js');
5+
hasIgnoresFile = true;
6+
} catch {
7+
// eslint.ignores.js doesn't exist
8+
}
9+
10+
if (hasIgnoresFile) {
11+
const ignores = require('./eslint.ignores.js');
12+
customConfig = [{ignores}];
13+
}
14+
15+
module.exports = [...customConfig, ...require('gts')];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = ['build/']

spannerlib/wrappers/spannerlib-node/package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
"node": ">=20.0.0"
2222
},
2323
"scripts": {
24-
"build": "node-gyp rebuild && npm run compile",
24+
"build:go": "bash scripts/build-shared-lib.sh",
25+
"build": "npm run build:go && node-gyp rebuild && npm run compile",
2526
"postbuild": "node -e \"if (process.platform === 'darwin') require('child_process').execSync('install_name_tool -change libspanner.dylib @loader_path/libspanner.dylib ./build/Release/spanner_napi.node')\"",
2627
"compile:esm": "tsc -p .",
2728
"compile:cjs": "tsc -p ./tsconfig.cjs.json && babel build/cjs --out-dir build/cjs --out-file-extension .cjs && node scripts/fix-extensions.cjs",
2829
"compile": "npm run compile:esm && npm run compile:cjs",
2930
"test:esm": "mocha build/esm/test/**/*.js",
3031
"test:cjs": "mocha build/cjs/test/**/*.cjs",
31-
"test": "npm run test:esm && npm run test:cjs"
32+
"test": "npm run test:esm && npm run test:cjs",
33+
"lint": "gts lint",
34+
"clean": "gts clean",
35+
"fix": "gts fix",
36+
"prepare": "npm run compile",
37+
"pretest": "npm run compile"
3238
},
3339
"files": [
3440
"build/esm/src",
@@ -42,13 +48,14 @@
4248
},
4349
"devDependencies": {
4450
"mocha": "^10.2.0",
45-
"typescript": "^5.4.0",
46-
"@types/node": "^20.11.0",
51+
"typescript": "^5.6.3",
52+
"@types/node": "^22.7.5",
4753
"@types/mocha": "^10.0.6",
4854
"@babel/core": "^7.24.0",
4955
"@babel/cli": "^7.23.9",
5056
"sinon": "^18.0.0",
51-
"@types/sinon": "^17.0.3"
57+
"@types/sinon": "^17.0.3",
58+
"gts": "^7.0.0"
5259
},
5360
"gypfile": false
5461
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Copyright 2026 Google LLC
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Builds the shared library and places it in the shared directory.
19+
# This script handles OS detection to use the correct file extension.
20+
21+
log() {
22+
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
23+
}
24+
25+
log "Starting Spannerlib Shared Library Build for Node Wrapper..."
26+
27+
# Resolve absolute paths
28+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
29+
SHARED_LIB_DIR="$(cd "$SCRIPT_DIR/../../../shared" && pwd)"
30+
31+
log "Script Directory: $SCRIPT_DIR"
32+
log "Shared Lib Directory: $SHARED_LIB_DIR"
33+
34+
# Auto-detect OS
35+
case "$(uname -s)" in
36+
Linux*) OS="Linux";;
37+
Darwin*) OS="macOS";;
38+
CYGWIN*|MINGW*|MSYS*) OS="Windows";;
39+
*) OS="Unknown";;
40+
esac
41+
log "Auto-detected OS: $OS"
42+
43+
if [ "$OS" == "macOS" ]; then
44+
echo "Building for macOS..."
45+
go build -C "$SHARED_LIB_DIR" -o libspanner.dylib -buildmode=c-shared shared_lib.go
46+
elif [ "$OS" == "Linux" ]; then
47+
echo "Building for Linux..."
48+
go build -C "$SHARED_LIB_DIR" -o libspanner.so -buildmode=c-shared shared_lib.go
49+
elif [ "$OS" == "Windows" ]; then
50+
echo "Building for Windows..."
51+
go build -C "$SHARED_LIB_DIR" -o spannerlib.dll -buildmode=c-shared shared_lib.go
52+
else
53+
echo "Unsupported operating system: $OS"
54+
exit 1
55+
fi
56+
57+
echo "Build complete."

spannerlib/wrappers/spannerlib-node/tsconfig.cjs.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
{
2+
"extends": "gts/tsconfig-google.json",
23
"compilerOptions": {
34
"target": "es2023",
4-
"module": "commonjs",
5-
"lib": ["es2023"],
6-
"strict": true,
7-
"noImplicitAny": false,
8-
"esModuleInterop": true,
9-
"forceConsistentCasingInFileNames": true,
10-
"declaration": true,
115
"outDir": "build/cjs",
6+
"esModuleInterop": true,
127
"types": ["node", "mocha"]
138
},
149
"include": ["src/**/*", "test/**/*"],

spannerlib/wrappers/spannerlib-node/tsconfig.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
2+
"extends": "gts/tsconfig-google.json",
23
"compilerOptions": {
34
"target": "es2023",
45
"module": "nodenext",
56
"moduleResolution": "nodenext",
6-
"lib": ["es2023"],
7-
"strict": true,
8-
"noImplicitAny": false,
9-
"esModuleInterop": true,
10-
"forceConsistentCasingInFileNames": true,
11-
"declaration": true,
127
"outDir": "build/esm",
8+
"esModuleInterop": true,
139
"types": ["node", "mocha"]
1410
},
1511
"include": ["src/**/*", "test/**/*"],

0 commit comments

Comments
 (0)