diff --git a/.github/workflows/sync-spannerlib-node.yml b/.github/workflows/sync-spannerlib-node.yml new file mode 100644 index 00000000000..f9cb53a065d --- /dev/null +++ b/.github/workflows/sync-spannerlib-node.yml @@ -0,0 +1,35 @@ +name: Sync SpannerLib Node code from go-sql-spanner + +permissions: + contents: read + +on: + pull_request: + workflow_dispatch: # Allows manual triggering + +jobs: + sync-code: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 + with: + persist-credentials: false + + - name: Copy SpannerLib code + run: ./scripts/sync_spannerlib_node.sh false main + working-directory: handwritten/spanner-driver + shell: bash + + - uses: googleapis/code-suggester@f9fef85aa02459e30e62526abe950341cbbd768b # v5 + env: + ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} + with: + command: pr + upstream_owner: googleapis + upstream_repo: google-cloud-node + description: 'Update the Spanner Node.js driver with the latest spannerlib-node code from go-sql-spanner.' + title: 'chore(spanner-driver): sync spannerlib-node code' + message: 'chore(spanner-driver): sync spannerlib-node code' + branch: automated-spanner-lib-code-update + git_dir: '.' + force: true diff --git a/handwritten/spanner-driver/scripts/sync_spannerlib_node.sh b/handwritten/spanner-driver/scripts/sync_spannerlib_node.sh new file mode 100755 index 00000000000..e48b4ea1c25 --- /dev/null +++ b/handwritten/spanner-driver/scripts/sync_spannerlib_node.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +SKIP_CLONE=$1 +SPANNER_LIB_BRANCH="${2:-main}" + +if ! [ "$SKIP_CLONE" == "true" ]; then + git clone https://github.com/googleapis/go-sql-spanner.git --branch "$SPANNER_LIB_BRANCH" +fi + +mkdir -p spannerlib-node +rm -rf spannerlib-node/* + +cp -r go-sql-spanner/spannerlib/wrappers/spannerlib-node/* spannerlib-node/ +mkdir -p spannerlib-node/shared +cp -r go-sql-spanner/spannerlib/shared/* spannerlib-node/shared/ + +# Update build-shared-lib.sh and binding.gyp paths for self-contained spannerlib-node +if [ -f "spannerlib-node/scripts/build-shared-lib.sh" ]; then + sed -i '' 's|\.\./\.\./\.\./shared|\.\./shared|g' spannerlib-node/scripts/build-shared-lib.sh 2>/dev/null || \ + sed -i 's|\.\./\.\./\.\./shared|\.\./shared|g' spannerlib-node/scripts/build-shared-lib.sh +fi + +if [ -f "spannerlib-node/binding.gyp" ]; then + sed -i '' 's|\.\./\.\./shared|\./shared|g' spannerlib-node/binding.gyp 2>/dev/null || \ + sed -i 's|\.\./\.\./shared|\./shared|g' spannerlib-node/binding.gyp +fi + +rm -rf go-sql-spanner