|
| 1 | +on: |
| 2 | + push: |
| 3 | + paths: |
| 4 | + - 'libs/gl-sdk-napi/package.json' |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: {} |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +name: Typescript Library |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-version: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + version-changed: ${{ steps.check.outputs.changed }} |
| 19 | + defaults: |
| 20 | + run: |
| 21 | + working-directory: libs/gl-sdk-napi |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 2 |
| 26 | + |
| 27 | + - id: check |
| 28 | + run: | |
| 29 | + CURRENT_VERSION=$(cat package.json | jq -r '.version') |
| 30 | + git checkout HEAD^ |
| 31 | + PREVIOUS_VERSION=$(cat package.json | jq -r '.version') |
| 32 | + git checkout - |
| 33 | + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then |
| 34 | + echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" |
| 35 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 36 | + else |
| 37 | + echo "Version unchanged" |
| 38 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 39 | + fi |
| 40 | +
|
| 41 | + build: |
| 42 | + needs: check-version |
| 43 | + if: needs.check-version.outputs.version-changed == 'true' |
| 44 | + strategy: |
| 45 | + fail-fast: false |
| 46 | + matrix: |
| 47 | + settings: |
| 48 | + - host: ubuntu-latest |
| 49 | + target: x86_64-unknown-linux-gnu |
| 50 | + build: | |
| 51 | + npm run build --target x86_64-unknown-linux-gnu |
| 52 | + strip -x *.node |
| 53 | + |
| 54 | + - host: ubuntu-latest |
| 55 | + target: aarch64-unknown-linux-gnu |
| 56 | + build: | |
| 57 | + npm run build --target aarch64-unknown-linux-gnu |
| 58 | + |
| 59 | + - host: ubuntu-latest |
| 60 | + target: x86_64-unknown-linux-musl |
| 61 | + build: | |
| 62 | + npm run build --target x86_64-unknown-linux-musl |
| 63 | + strip -x *.node |
| 64 | + |
| 65 | + - host: macos-13 |
| 66 | + target: x86_64-apple-darwin |
| 67 | + build: | |
| 68 | + npm run build --target x86_64-apple-darwin |
| 69 | + strip -x *.node |
| 70 | + |
| 71 | + - host: macos-14 |
| 72 | + target: aarch64-apple-darwin |
| 73 | + build: | |
| 74 | + npm run build --target aarch64-apple-darwin |
| 75 | + strip -x *.node |
| 76 | + |
| 77 | + - host: windows-latest |
| 78 | + target: x86_64-pc-windows-msvc |
| 79 | + build: npm run build --target x86_64-pc-windows-msvc |
| 80 | + |
| 81 | + - host: windows-latest |
| 82 | + target: aarch64-pc-windows-msvc |
| 83 | + build: npm run build --target aarch64-pc-windows-msvc |
| 84 | + |
| 85 | + name: Build - ${{ matrix.settings.target }} |
| 86 | + runs-on: ${{ matrix.settings.host }} |
| 87 | + |
| 88 | + defaults: |
| 89 | + run: |
| 90 | + working-directory: libs/gl-sdk-napi |
| 91 | + |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@v4 |
| 94 | + |
| 95 | + - name: Setup Node.js |
| 96 | + uses: actions/setup-node@v4 |
| 97 | + with: |
| 98 | + node-version: 20 |
| 99 | + cache: npm |
| 100 | + cache-dependency-path: libs/gl-sdk-napi/package-lock.json |
| 101 | + |
| 102 | + - name: Install Rust |
| 103 | + uses: dtolnay/rust-toolchain@stable |
| 104 | + with: |
| 105 | + targets: ${{ matrix.settings.target }} |
| 106 | + |
| 107 | + - name: Setup cross-compilation (Linux ARM64) |
| 108 | + if: matrix.settings.target == 'aarch64-unknown-linux-gnu' |
| 109 | + run: | |
| 110 | + sudo apt-get update |
| 111 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 112 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 113 | + |
| 114 | + - name: Setup musl tools (Linux musl) |
| 115 | + if: matrix.settings.target == 'x86_64-unknown-linux-musl' |
| 116 | + run: | |
| 117 | + sudo apt-get update |
| 118 | + sudo apt-get install -y musl-tools |
| 119 | + |
| 120 | + - name: Cache cargo registry |
| 121 | + uses: actions/cache@v4 |
| 122 | + with: |
| 123 | + path: ~/.cargo/registry/cache |
| 124 | + key: ${{ matrix.settings.target }}-cargo-registry |
| 125 | + |
| 126 | + - name: Cache cargo index |
| 127 | + uses: actions/cache@v4 |
| 128 | + with: |
| 129 | + path: ~/.cargo/registry/index |
| 130 | + key: ${{ matrix.settings.target }}-cargo-index |
| 131 | + |
| 132 | + - name: Install dependencies |
| 133 | + run: npm ci |
| 134 | + |
| 135 | + - name: Build |
| 136 | + run: ${{ matrix.settings.build }} |
| 137 | + shell: bash |
| 138 | + |
| 139 | + - name: Upload artifact |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: bindings-${{ matrix.settings.target }} |
| 143 | + path: libs/gl-sdk-napi/*.node |
| 144 | + if-no-files-found: error |
| 145 | + |
| 146 | + publish: |
| 147 | + name: Publish to NPM |
| 148 | + runs-on: ubuntu-latest |
| 149 | + needs: build |
| 150 | + |
| 151 | + defaults: |
| 152 | + run: |
| 153 | + working-directory: libs/gl-sdk-napi |
| 154 | + |
| 155 | + steps: |
| 156 | + - uses: actions/checkout@v4 |
| 157 | + |
| 158 | + - name: Setup Node.js |
| 159 | + uses: actions/setup-node@v4 |
| 160 | + with: |
| 161 | + node-version: 20 |
| 162 | + registry-url: 'https://registry.npmjs.org' |
| 163 | + |
| 164 | + - name: Install dependencies |
| 165 | + run: npm ci |
| 166 | + |
| 167 | + - name: Download all artifacts |
| 168 | + uses: actions/download-artifact@v4 |
| 169 | + with: |
| 170 | + path: artifacts |
| 171 | + |
| 172 | + - name: Move artifacts to package directory |
| 173 | + run: | |
| 174 | + for dir in ../../artifacts/bindings-*; do |
| 175 | + if [ -d "$dir" ]; then |
| 176 | + echo "Processing $dir" |
| 177 | + cp "$dir"/*.node . 2>/dev/null || true |
| 178 | + fi |
| 179 | + done |
| 180 | + ls -la *.node |
| 181 | + |
| 182 | + - name: List package contents |
| 183 | + run: npm pack --dry-run |
| 184 | + |
| 185 | + - name: Publish to NPM |
| 186 | + run: npm publish --access public |
| 187 | + env: |
| 188 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments