|
| 1 | +on: |
| 2 | + push: |
| 3 | + paths: |
| 4 | + - '.github/workflows/typescript.yml' |
| 5 | + - 'libs/gl-sdk-napi/**' |
| 6 | + branches: |
| 7 | + - main |
| 8 | + pull_request: {} |
| 9 | + release: |
| 10 | + types: [created] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +name: Typescript Library |
| 14 | + |
| 15 | +jobs: |
| 16 | + check-version: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + version-changed: ${{ steps.check.outputs.changed }} |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + working-directory: libs/gl-sdk-napi |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 2 |
| 27 | + |
| 28 | + - id: check |
| 29 | + run: | |
| 30 | + CURRENT_VERSION=$(cat package.json | jq -r '.version') |
| 31 | + git checkout HEAD^ |
| 32 | + PREVIOUS_VERSION=$(cat package.json | jq -r '.version') |
| 33 | + git checkout - |
| 34 | + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then |
| 35 | + echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" |
| 36 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 37 | + else |
| 38 | + echo "::warning::Will not trigger publishing because version is unchanged" |
| 39 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 40 | + exit 0 |
| 41 | + fi |
| 42 | +
|
| 43 | + build: |
| 44 | + needs: check-version |
| 45 | + if: needs.check-version.outputs.version-changed == 'true' |
| 46 | + strategy: |
| 47 | + fail-fast: false |
| 48 | + matrix: |
| 49 | + settings: |
| 50 | + - host: ubuntu-latest |
| 51 | + target: x86_64-unknown-linux-gnu |
| 52 | + strip: strip -x *.node |
| 53 | + |
| 54 | + - host: ubuntu-latest |
| 55 | + target: aarch64-unknown-linux-gnu |
| 56 | + strip: aarch64-linux-gnu-strip -x *.node |
| 57 | + |
| 58 | + - host: macos-15-intel |
| 59 | + target: x86_64-apple-darwin |
| 60 | + strip: strip -x *.node |
| 61 | + |
| 62 | + - host: macos-14 |
| 63 | + target: aarch64-apple-darwin |
| 64 | + strip: strip -x *.node |
| 65 | + |
| 66 | + - host: windows-latest |
| 67 | + target: x86_64-pc-windows-msvc |
| 68 | + strip: "" |
| 69 | + |
| 70 | + name: Build - ${{ matrix.settings.target }} |
| 71 | + runs-on: ${{ matrix.settings.host }} |
| 72 | + |
| 73 | + defaults: |
| 74 | + run: |
| 75 | + working-directory: libs/gl-sdk-napi |
| 76 | + |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + |
| 80 | + - name: Setup Node.js |
| 81 | + uses: actions/setup-node@v4 |
| 82 | + with: |
| 83 | + node-version: 20 |
| 84 | + cache: npm |
| 85 | + cache-dependency-path: libs/gl-sdk-napi/package-lock.json |
| 86 | + |
| 87 | + - name: Install Rust |
| 88 | + uses: dtolnay/rust-toolchain@stable |
| 89 | + with: |
| 90 | + targets: ${{ matrix.settings.target }} |
| 91 | + |
| 92 | + - name: Install protobuf compiler (Linux) |
| 93 | + if: runner.os == 'Linux' |
| 94 | + run: | |
| 95 | + sudo apt-get update |
| 96 | + sudo apt-get install -y protobuf-compiler |
| 97 | + |
| 98 | + - name: Install protobuf compiler (macOS) |
| 99 | + if: runner.os == 'macOS' |
| 100 | + run: brew install protobuf |
| 101 | + |
| 102 | + - name: Install protobuf compiler (Windows) |
| 103 | + if: runner.os == 'Windows' |
| 104 | + run: choco install protoc |
| 105 | + |
| 106 | + - name: Setup cross-compilation (Linux ARM64) |
| 107 | + if: matrix.settings.target == 'aarch64-unknown-linux-gnu' |
| 108 | + run: | |
| 109 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 110 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 111 | + |
| 112 | + - name: Cache cargo registry |
| 113 | + uses: actions/cache@v4 |
| 114 | + with: |
| 115 | + path: ~/.cargo/registry/cache |
| 116 | + key: ${{ matrix.settings.target }}-cargo-registry |
| 117 | + |
| 118 | + - name: Cache cargo index |
| 119 | + uses: actions/cache@v4 |
| 120 | + with: |
| 121 | + path: ~/.cargo/registry/index |
| 122 | + key: ${{ matrix.settings.target }}-cargo-index |
| 123 | + |
| 124 | + - name: Install dependencies |
| 125 | + run: npm ci |
| 126 | + |
| 127 | + - name: Build |
| 128 | + run: npm run build -- --target ${{ matrix.settings.target }} |
| 129 | + shell: bash |
| 130 | + |
| 131 | + - name: Strip binary |
| 132 | + if: matrix.settings.strip != '' |
| 133 | + run: ${{ matrix.settings.strip }} |
| 134 | + shell: bash |
| 135 | + |
| 136 | + - name: List build output |
| 137 | + run: ls -la *.node index.js index.d.ts |
| 138 | + shell: bash |
| 139 | + |
| 140 | + - name: Upload artifact |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: bindings-${{ matrix.settings.target }} |
| 144 | + path: | |
| 145 | + libs/gl-sdk-napi/*.node |
| 146 | + libs/gl-sdk-napi/index.js |
| 147 | + libs/gl-sdk-napi/index.d.ts |
| 148 | + if-no-files-found: error |
| 149 | + |
| 150 | + test: |
| 151 | + name: Test - ${{ matrix.settings.target }} |
| 152 | + needs: build |
| 153 | + continue-on-error: true |
| 154 | + strategy: |
| 155 | + fail-fast: false |
| 156 | + matrix: |
| 157 | + settings: |
| 158 | + - host: ubuntu-latest |
| 159 | + target: x86_64-unknown-linux-gnu |
| 160 | + - host: macos-14 |
| 161 | + target: aarch64-apple-darwin |
| 162 | + - host: windows-latest |
| 163 | + target: x86_64-pc-windows-msvc |
| 164 | + runs-on: ${{ matrix.settings.host }} |
| 165 | + |
| 166 | + defaults: |
| 167 | + run: |
| 168 | + working-directory: libs/gl-sdk-napi |
| 169 | + |
| 170 | + steps: |
| 171 | + - uses: actions/checkout@v4 |
| 172 | + |
| 173 | + - name: Setup Node.js |
| 174 | + uses: actions/setup-node@v4 |
| 175 | + with: |
| 176 | + node-version: 20 |
| 177 | + cache: npm |
| 178 | + cache-dependency-path: libs/gl-sdk-napi/package-lock.json |
| 179 | + |
| 180 | + - name: Install dependencies |
| 181 | + run: npm ci |
| 182 | + |
| 183 | + - name: Download artifact |
| 184 | + uses: actions/download-artifact@v4 |
| 185 | + with: |
| 186 | + name: bindings-${{ matrix.settings.target }} |
| 187 | + path: libs/gl-sdk-napi |
| 188 | + |
| 189 | + - name: List downloaded files |
| 190 | + run: ls -la *.node index.js index.d.ts |
| 191 | + shell: bash |
| 192 | + |
| 193 | + - name: Run tests |
| 194 | + uses: nick-fields/retry@v3 |
| 195 | + with: |
| 196 | + timeout_minutes: 5 |
| 197 | + max_attempts: 3 |
| 198 | + retry_wait_seconds: 10 |
| 199 | + shell: bash |
| 200 | + command: cd libs/gl-sdk-napi && npm test -- tests/basic.spec.ts |
| 201 | + |
| 202 | + publish: |
| 203 | + name: Publish to NPM |
| 204 | + runs-on: ubuntu-latest |
| 205 | + needs: test |
| 206 | + |
| 207 | + defaults: |
| 208 | + run: |
| 209 | + working-directory: libs/gl-sdk-napi |
| 210 | + |
| 211 | + steps: |
| 212 | + - uses: actions/checkout@v4 |
| 213 | + |
| 214 | + - name: Setup Node.js |
| 215 | + uses: actions/setup-node@v4 |
| 216 | + with: |
| 217 | + node-version: 20 |
| 218 | + registry-url: 'https://registry.npmjs.org' |
| 219 | + |
| 220 | + - name: Install dependencies |
| 221 | + run: npm ci |
| 222 | + |
| 223 | + - name: Download all artifacts |
| 224 | + uses: actions/download-artifact@v4 |
| 225 | + with: |
| 226 | + path: artifacts |
| 227 | + |
| 228 | + - name: Move artifacts to package directory |
| 229 | + run: | |
| 230 | + for dir in ../../artifacts/bindings-*; do |
| 231 | + if [ -d "$dir" ]; then |
| 232 | + echo "Processing $dir" |
| 233 | + cp "$dir"/* . 2>/dev/null || true |
| 234 | + fi |
| 235 | + done |
| 236 | + ls -la *.* |
| 237 | + |
| 238 | + - name: List package contents |
| 239 | + run: npm pack --dry-run |
| 240 | + |
| 241 | + - name: Publish to NPM |
| 242 | + run: | |
| 243 | + echo "Token length: ${#NODE_AUTH_TOKEN}" |
| 244 | + npm publish --access public |
| 245 | + env: |
| 246 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments