|
| 1 | +name: Build and Release Node Wrapper |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + platform: |
| 7 | + description: 'Target platform package to release' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - 'all' |
| 12 | + - 'darwin-arm64' |
| 13 | + - 'linux-x64' |
| 14 | + - 'linux-arm64' |
| 15 | + - 'win32-x64' |
| 16 | + default: 'all' |
| 17 | + npm_tag: |
| 18 | + description: 'NPM distribution tag (e.g. alpha(default), beta, latest, next)' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + default: 'alpha' |
| 22 | + npm_token: |
| 23 | + description: 'NPM Token for Wombat (leave empty for dry run)' |
| 24 | + required: false |
| 25 | + type: string |
| 26 | + default: '' |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + |
| 31 | +jobs: |
| 32 | + release: |
| 33 | + name: Release ${{ matrix.pkg_name }} |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: |
| 39 | + - os: macos-latest |
| 40 | + target: darwin-arm64 |
| 41 | + os_name: darwin |
| 42 | + cpu_name: arm64 |
| 43 | + goarch: arm64 |
| 44 | + pkg_name: "@google-cloud/spannerlib-node-darwin-arm64" |
| 45 | + - os: ubuntu-22.04 |
| 46 | + target: linux-x64 |
| 47 | + os_name: linux |
| 48 | + cpu_name: x64 |
| 49 | + goarch: amd64 |
| 50 | + pkg_name: "@google-cloud/spannerlib-node-linux-x64" |
| 51 | + - os: ubuntu-22.04 |
| 52 | + target: linux-arm64 |
| 53 | + os_name: linux |
| 54 | + cpu_name: arm64 |
| 55 | + goarch: arm64 |
| 56 | + pkg_name: "@google-cloud/spannerlib-node-linux-arm64" |
| 57 | + cc: aarch64-linux-gnu-gcc |
| 58 | + cxx: aarch64-linux-gnu-g++ |
| 59 | + ar: aarch64-linux-gnu-ar |
| 60 | + - os: windows-2022 |
| 61 | + target: win32-x64 |
| 62 | + os_name: win32 |
| 63 | + cpu_name: x64 |
| 64 | + goarch: amd64 |
| 65 | + pkg_name: "@google-cloud/spannerlib-node-win32-x64" |
| 66 | + |
| 67 | + defaults: |
| 68 | + run: |
| 69 | + shell: bash |
| 70 | + working-directory: ./spannerlib/wrappers/spannerlib-node |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Checkout repository |
| 74 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 75 | + |
| 76 | + - name: Check Platform Target |
| 77 | + id: check |
| 78 | + env: |
| 79 | + PLATFORM_INPUT: ${{ inputs.platform || 'all' }} |
| 80 | + MATRIX_TARGET: ${{ matrix.target }} |
| 81 | + run: | |
| 82 | + if [ "$PLATFORM_INPUT" = "all" ] || [ "$PLATFORM_INPUT" = "$MATRIX_TARGET" ]; then |
| 83 | + echo "run=true" >> "$GITHUB_OUTPUT" |
| 84 | + else |
| 85 | + echo "run=false" >> "$GITHUB_OUTPUT" |
| 86 | + echo "Skipping matrix target $MATRIX_TARGET (requested: $PLATFORM_INPUT)" |
| 87 | + fi |
| 88 | +
|
| 89 | + - name: Install ARM64 Cross-Compiler (Linux ARM64) |
| 90 | + if: steps.check.outputs.run == 'true' && matrix.target == 'linux-arm64' |
| 91 | + run: | |
| 92 | + sudo apt-get update |
| 93 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu |
| 94 | +
|
| 95 | + - name: Set up Go |
| 96 | + if: steps.check.outputs.run == 'true' |
| 97 | + uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 |
| 98 | + with: |
| 99 | + go-version: '1.26.x' |
| 100 | + cache-dependency-path: spannerlib/go.sum |
| 101 | + |
| 102 | + - name: Set up Node.js |
| 103 | + if: steps.check.outputs.run == 'true' |
| 104 | + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 |
| 105 | + with: |
| 106 | + node-version: '22' |
| 107 | + cache: 'npm' |
| 108 | + cache-dependency-path: spannerlib/wrappers/spannerlib-node/package.json |
| 109 | + |
| 110 | + - name: Mask NPM Token |
| 111 | + if: steps.check.outputs.run == 'true' && inputs.npm_token != '' |
| 112 | + env: |
| 113 | + NPM_TOKEN: ${{ inputs.npm_token }} |
| 114 | + run: | |
| 115 | + echo "::add-mask::${NPM_TOKEN}" |
| 116 | +
|
| 117 | + - name: Configure NPM registry auth |
| 118 | + if: steps.check.outputs.run == 'true' && inputs.npm_token != '' |
| 119 | + env: |
| 120 | + NPM_TOKEN: ${{ inputs.npm_token }} |
| 121 | + run: | |
| 122 | + echo "//wombat-dressing-room.appspot.com/:_authToken=${NPM_TOKEN}" > ~/.npmrc |
| 123 | +
|
| 124 | + - name: Install dependencies |
| 125 | + if: steps.check.outputs.run == 'true' |
| 126 | + run: npm install |
| 127 | + |
| 128 | + - name: Build Go library and C++ Addon |
| 129 | + if: steps.check.outputs.run == 'true' |
| 130 | + env: |
| 131 | + npm_config_enable_thin_lto: "false" |
| 132 | + npm_config_enable_lto: "false" |
| 133 | + npm_config_use_lld: "false" |
| 134 | + GYP_DEFINES: "enable_thin_lto=false enable_lto=false use_lld=false lto_jobs=" |
| 135 | + npm_config_arch: ${{ matrix.cpu_name }} |
| 136 | + GOARCH: ${{ matrix.goarch }} |
| 137 | + CGO_ENABLED: "1" |
| 138 | + run: | |
| 139 | + unset CFLAGS CXXFLAGS LDFLAGS 2>/dev/null || true |
| 140 | + [ -n "${{ matrix.cc }}" ] && export CC="${{ matrix.cc }}" |
| 141 | + [ -n "${{ matrix.cxx }}" ] && export CXX="${{ matrix.cxx }}" |
| 142 | + [ -n "${{ matrix.ar }}" ] && export AR="${{ matrix.ar }}" |
| 143 | + npm run build |
| 144 | +
|
| 145 | + - name: Prepare Platform Package Manifest |
| 146 | + if: steps.check.outputs.run == 'true' |
| 147 | + env: |
| 148 | + PKG_NAME: ${{ matrix.pkg_name }} |
| 149 | + OS_NAME: ${{ matrix.os_name }} |
| 150 | + CPU_NAME: ${{ matrix.cpu_name }} |
| 151 | + run: | |
| 152 | + node -e ' |
| 153 | + const fs = require("fs"); |
| 154 | + const pkg = JSON.parse(fs.readFileSync("./package.json", "utf8")); |
| 155 | + pkg.name = process.env.PKG_NAME; |
| 156 | + pkg.os = [process.env.OS_NAME]; |
| 157 | + pkg.cpu = [process.env.CPU_NAME]; |
| 158 | + fs.writeFileSync("./package.json", JSON.stringify(pkg, null, 2) + "\n"); |
| 159 | + console.log("Updated package.json for " + pkg.name + " (" + pkg.os + "/" + pkg.cpu + ")"); |
| 160 | + ' |
| 161 | +
|
| 162 | + - name: Package and Publish |
| 163 | + if: steps.check.outputs.run == 'true' |
| 164 | + env: |
| 165 | + NPM_TOKEN: ${{ inputs.npm_token }} |
| 166 | + NPM_TAG: ${{ inputs.npm_tag || 'alpha' }} |
| 167 | + run: | |
| 168 | + set -eo pipefail |
| 169 | + export NPM_CONFIG_PREFIX="${HOME}/.npm-global" |
| 170 | +
|
| 171 | + # Optional releasetool publisher script reporter if available |
| 172 | + if python3 -c "import releasetool" 2>/dev/null; then |
| 173 | + python3 -m releasetool publish-reporter-script > /tmp/publisher-script 2>/dev/null || true |
| 174 | + if [ -f /tmp/publisher-script ]; then |
| 175 | + source /tmp/publisher-script || true |
| 176 | + fi |
| 177 | + fi |
| 178 | +
|
| 179 | + npm pack . |
| 180 | + TARBALL=$(ls -1 -t *.tgz | head -1) |
| 181 | + echo "Generated tarball: $TARBALL" |
| 182 | +
|
| 183 | + # Publish only when a non-empty npm_token is provided |
| 184 | + if [ -n "$NPM_TOKEN" ]; then |
| 185 | + echo "Publishing $TARBALL with tag '$NPM_TAG' to Wombat registry..." |
| 186 | + npm publish --access=public --tag "$NPM_TAG" --registry=https://wombat-dressing-room.appspot.com "$TARBALL" |
| 187 | + else |
| 188 | + echo "Dry run mode active: No NPM token provided. Skipped publishing $TARBALL." |
| 189 | + fi |
| 190 | +
|
| 191 | + find node_modules -name package-lock.json -o -name "*.tgz" | xargs rm -f 2>/dev/null || true |
| 192 | +
|
| 193 | + - name: Upload Release Tarball Artifact |
| 194 | + if: steps.check.outputs.run == 'true' |
| 195 | + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 |
| 196 | + with: |
| 197 | + name: spannerlib-node-${{ matrix.target }}-tarball |
| 198 | + path: spannerlib/wrappers/spannerlib-node/*.tgz |
| 199 | + |
| 200 | + - name: Cleanup credentials |
| 201 | + if: always() |
| 202 | + run: | |
| 203 | + rm -f ~/.npmrc |
| 204 | + rm -f /tmp/publisher-script 2>/dev/null || true |
0 commit comments