|
| 1 | +name: Publish NPM Packages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Target version to publish (e.g., 1.12.2, 2.0.0-rc.1, 1.12.3-canary.20241201)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + branch_ref: |
| 11 | + description: 'Source branch to publish from (e.g., main, releases/1.12.x)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + default: 'main' |
| 15 | + dry_run: |
| 16 | + description: 'Run without actually publishing (for testing)' |
| 17 | + required: false |
| 18 | + type: boolean |
| 19 | + default: false |
| 20 | + |
| 21 | +env: |
| 22 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Compile native bridge code for each target platform. |
| 26 | + # Uploads the native library for each target as a build artifact. |
| 27 | + compile-native-binaries: |
| 28 | + strategy: |
| 29 | + fail-fast: true |
| 30 | + matrix: |
| 31 | + include: |
| 32 | + - platform: linux-x64 |
| 33 | + runner: ubuntu-latest |
| 34 | + target: x86_64-unknown-linux-gnu |
| 35 | + container: quay.io/pypa/manylinux_2_24_x86_64 |
| 36 | + out-file: libtemporal_sdk_typescript_bridge.so |
| 37 | + protobuf-url: https://github.com/protocolbuffers/protobuf/releases/download/v22.3/protoc-22.3-linux-x86_64.zip |
| 38 | + - platform: linux-arm |
| 39 | + runner: ubuntu-24.04-arm64-2-core |
| 40 | + target: aarch64-unknown-linux-gnu |
| 41 | + container: quay.io/pypa/manylinux_2_24_aarch64 |
| 42 | + out-file: libtemporal_sdk_typescript_bridge.so |
| 43 | + protobuf-url: https://github.com/protocolbuffers/protobuf/releases/download/v22.3/protoc-22.3-linux-aarch_64.zip |
| 44 | + - platform: macos-x64 |
| 45 | + runner: macos-13 |
| 46 | + target: x86_64-apple-darwin |
| 47 | + out-file: libtemporal_sdk_typescript_bridge.dylib |
| 48 | + - platform: macos-arm |
| 49 | + runner: macos-14 |
| 50 | + target: aarch64-apple-darwin |
| 51 | + out-file: libtemporal_sdk_typescript_bridge.dylib |
| 52 | + - platform: windows-x64 |
| 53 | + runner: windows-latest |
| 54 | + target: x86_64-pc-windows-msvc |
| 55 | + out-file: temporal_sdk_typescript_bridge.dll |
| 56 | + name: Compile Native Binaries (${{ matrix.platform }}) |
| 57 | + runs-on: ${{ matrix.runner }} |
| 58 | + defaults: |
| 59 | + run: |
| 60 | + shell: bash |
| 61 | + steps: |
| 62 | + - name: 'Checkout code' |
| 63 | + uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + ref: ${{ inputs.branch_ref }} |
| 66 | + submodules: recursive |
| 67 | + |
| 68 | + # Note we intentionally don't use the artifact cache here. |
| 69 | + # Publishing a release deserves making a fresh build. |
| 70 | + |
| 71 | + - name: Install protoc |
| 72 | + uses: arduino/setup-protoc@v3 |
| 73 | + with: |
| 74 | + # TODO: Upgrade proto once https://github.com/arduino/setup-protoc/issues/99 is fixed |
| 75 | + version: '23.x' |
| 76 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Upgrade Rust to latest stable |
| 79 | + uses: dtolnay/rust-toolchain@stable |
| 80 | + |
| 81 | + - name: Rust Cargo and Build cache |
| 82 | + uses: Swatinem/rust-cache@v2 |
| 83 | + with: |
| 84 | + workspaces: packages/core-bridge -> target |
| 85 | + prefix-key: corebridge-buildcache |
| 86 | + shared-key: ${{ matrix.platform }} |
| 87 | + env-vars: '' |
| 88 | + |
| 89 | + - name: Compile rust code (non-Docker) |
| 90 | + if: ${{ !matrix.container }} |
| 91 | + working-directory: ./packages/core-bridge |
| 92 | + run: | |
| 93 | + cargo build --release --target ${{ matrix.target }} |
| 94 | +
|
| 95 | + - name: Compile rust code (Docker) |
| 96 | + if: ${{ matrix.container }} |
| 97 | + working-directory: ./packages/core-bridge |
| 98 | + run: | |
| 99 | + docker run --rm -v "$(pwd):/workspace" -w /workspace \ |
| 100 | + ${{ matrix.container }} \ |
| 101 | + sh -c ' |
| 102 | + curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y |
| 103 | + curl -L -o /tmp/protoc.zip ${{ matrix.protobuf-url }} |
| 104 | + unzip /tmp/protoc.zip -d $HOME/.protobuf |
| 105 | + export PATH="$PATH:$HOME/.cargo/bin:$HOME/.protobuf/bin" |
| 106 | +
|
| 107 | + cargo build --release --target ${{ matrix.target }} |
| 108 | + ' |
| 109 | +
|
| 110 | + - name: Move built artifacts in place |
| 111 | + working-directory: ./packages/core-bridge |
| 112 | + run: | |
| 113 | + mkdir -p ./releases/${{ matrix.target }} |
| 114 | + cp target/${{ matrix.target }}/release/${{ matrix.out-file }} ./releases/${{ matrix.target }}/index.node |
| 115 | +
|
| 116 | + - name: Print required GLIBC version |
| 117 | + if: startsWith(matrix.platform, 'linux') |
| 118 | + working-directory: ./packages/core-bridge |
| 119 | + run: | |
| 120 | + objdump -T ./releases/${{ matrix.target }}/index.node | |
| 121 | + grep GLIBC | sed 's/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -V | tail -1 |
| 122 | +
|
| 123 | + - uses: actions/upload-artifact@v4 |
| 124 | + with: |
| 125 | + name: corebridge-native-${{ matrix.platform }} |
| 126 | + # Actual file will be named ${{ matrix.target }}/index.node |
| 127 | + path: ./packages/core-bridge/releases/*/index.node |
| 128 | + |
| 129 | + # Main publishing job that builds packages and publishes to NPM |
| 130 | + build-and-publish-packages: |
| 131 | + name: Build and Publish Packages |
| 132 | + needs: |
| 133 | + - compile-native-binaries |
| 134 | + runs-on: ubuntu-latest |
| 135 | + permissions: |
| 136 | + contents: write |
| 137 | + id-token: write |
| 138 | + defaults: |
| 139 | + run: |
| 140 | + shell: bash |
| 141 | + steps: |
| 142 | + - name: Checkout code |
| 143 | + uses: actions/checkout@v4 |
| 144 | + with: |
| 145 | + ref: ${{ inputs.branch_ref }} |
| 146 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + submodules: recursive |
| 148 | + |
| 149 | + - name: Download core-bridge native libraries |
| 150 | + uses: actions/download-artifact@v4 |
| 151 | + with: |
| 152 | + path: ./packages/core-bridge/releases/tmp |
| 153 | + |
| 154 | + - name: Put native files into place |
| 155 | + working-directory: ./packages/core-bridge/releases |
| 156 | + run: | |
| 157 | + mv tmp/corebridge-*/* ./ |
| 158 | + rm -rf tmp |
| 159 | +
|
| 160 | + - name: Install Node |
| 161 | + uses: actions/setup-node@v4 |
| 162 | + with: |
| 163 | + node-version: 22 |
| 164 | + |
| 165 | + - name: Get NPM cache directory |
| 166 | + id: npm-cache-dir |
| 167 | + run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} |
| 168 | + |
| 169 | + - name: Restore NPM cache |
| 170 | + uses: actions/cache/restore@v4 |
| 171 | + with: |
| 172 | + path: ${{ steps.npm-cache-dir.outputs.dir }} |
| 173 | + key: npm-main-linux-x64-${{ hashFiles('./package-lock.json') }} |
| 174 | + restore-keys: | |
| 175 | + npm-main-linux-x64- |
| 176 | +
|
| 177 | + - name: Install dependencies |
| 178 | + # Make up to 3 attempts to install NPM dependencies, to work around transient NPM errors :( |
| 179 | + run: | |
| 180 | + npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose |
| 181 | +
|
| 182 | + - name: Build packages |
| 183 | + run: npm run build -- --ignore @temporalio/core-bridge |
| 184 | + |
| 185 | + - name: Configure Git |
| 186 | + run: | |
| 187 | + git config user.name "github-actions[bot]" |
| 188 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 189 | +
|
| 190 | + - name: Update version and create tag |
| 191 | + run: | |
| 192 | + npx lerna version ${{ inputs.version }} --force-publish='*' --yes |
| 193 | + env: |
| 194 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 195 | + |
| 196 | + - name: Fix dependencies for publishing |
| 197 | + run: | |
| 198 | + git checkout -B fix-deps |
| 199 | + node scripts/prepublish.mjs |
| 200 | + git commit -am "Fix peer dependencies" |
| 201 | +
|
| 202 | + - name: Publish packages |
| 203 | + if: ${{ !inputs.dry_run }} |
| 204 | + run: | |
| 205 | + if [[ ${{ inputs.version }} =~ '^[0-9]+\.[0-9]+\.[0-9]+$' ]]; then |
| 206 | + npx lerna publish from-package --yes |
| 207 | + else |
| 208 | + npx lerna publish from-package --dist-tag next --yes |
| 209 | + fi |
| 210 | + env: |
| 211 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 212 | + |
| 213 | + - name: Deprecate temporalio package |
| 214 | + if: ${{ !inputs.dry_run }} |
| 215 | + run: | |
| 216 | + npm deprecate "temporalio@^${{ inputs.version }}" "Instead of installing temporalio, we recommend directly installing our packages: npm remove temporalio; npm install @temporalio/client @temporalio/worker @temporalio/workflow @temporalio/activity" |
| 217 | + env: |
| 218 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 219 | + |
| 220 | + - name: Create GitHub Release |
| 221 | + if: ${{ !inputs.dry_run }} |
| 222 | + run: | |
| 223 | + # Extract tag name from the version (lerna creates tags like v1.12.2) |
| 224 | + tag_name="v${{ inputs.version }}" |
| 225 | +
|
| 226 | + # Create draft release |
| 227 | + gh release create "$tag_name" \ |
| 228 | + --draft \ |
| 229 | + --title "$tag_name" \ |
| 230 | + --notes "Release $tag_name" \ |
| 231 | + --target ${{ inputs.branch_ref }} |
| 232 | +
|
| 233 | + - name: Publish Summary |
| 234 | + if: ${{ inputs.dry_run }} |
| 235 | + run: | |
| 236 | + echo "DRY RUN COMPLETED" |
| 237 | + echo "Version: ${{ inputs.version }}" |
| 238 | + echo "Branch: ${{ inputs.branch_ref }}" |
| 239 | + echo "No packages were actually published" |
| 240 | + echo "No GitHub release was created" |
0 commit comments