1 name: SDK npm Release
2
3 # Publishes @smbcloud/sdk-auth (WASM) to npm.
4 # WASM is a single universal target — no platform matrix needed.
5 #
6 # Authenticates with npm trusted publishing (OIDC), so there is no npm token
7 # to store or rotate. The package needs a trusted publisher on npmjs.com that
8 # names this repository and this workflow file:
9 #
10 # npm trust github @smbcloud/sdk-auth --repo smbcloudXYZ/smbcloud-cli --file release-sdk-npm.yml
11 #
12 # OIDC publishing needs npm >= 11.5.1 and Node >= 22.14.0; .nvmrc covers both.
13
14 on:
15 workflow_dispatch:
16 inputs:
17 tag:
18 description: "Release tag (e.g. v0.3.35)"
19 required: true
20
21 permissions:
22 # Lets the job request the OIDC token npm exchanges for publish rights.
23 id-token: write
24 contents: read
25
26 env:
27 CARGO_TERM_COLOR: always
28 CLI_CLIENT_SECRET: ${{ secrets.CLI_CLIENT_SECRET }}
29
30 jobs:
31 publish-sdk-npm:
32 name: Publish @smbcloud/sdk-auth to npm
33 runs-on: ubuntu-latest
34
35 steps:
36 - name: Checkout
37 uses: actions/checkout@v6
38 with:
39 ref: ${{ github.event.inputs.tag || github.ref }}
40
41 - name: Set the release version
42 shell: bash
43 run: |
44 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
45 release_version="${GITHUB_REF_NAME#v}"
46 else
47 release_version="${{ github.event.inputs.tag }}"
48 release_version="${release_version#v}"
49 fi
50
51 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
52
53 - name: Read Rust toolchain
54 shell: bash
55 run: |
56 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
57 if [ -z "$rust_toolchain" ]; then
58 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
59 exit 1
60 fi
61
62 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
63
64 - name: Install toolkit with wasm32 target
65 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
66 with:
67 toolchain: ${{ env.RUST_TOOLCHAIN }}
68 targets: wasm32-unknown-unknown
69
70 - name: Setup Rust cache
71 uses: Swatinem/rust-cache@v2
72 with:
73 key: sdk-npm
74
75 - name: Verify Cargo.toml version matches tag
76 shell: bash
77 run: |
78 CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 \
79 | jq -r '.packages[] | select(.name == "smbcloud-auth-sdk-wasm") | .version')
80
81 echo "Cargo.toml version : ${CARGO_VERSION}"
82 echo "Release tag version: ${RELEASE_VERSION}"
83
84 if [[ "${CARGO_VERSION}" != "${RELEASE_VERSION}" ]]; then
85 echo "::error::Version mismatch — bump version in crates/smbcloud-auth-sdk-wasm/Cargo.toml before releasing."
86 exit 1
87 fi
88
89 # wasm-pack drives the wasm32 compilation and wasm-bindgen code generation.
90 # prepare-package.mjs calls wasm-pack internally and also enforces that
91 # sdk/npm/smbcloud-auth/package.json version matches the Cargo.toml version.
92 - name: Install wasm-pack
93 run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
94
95 - name: Install Node.js
96 uses: actions/setup-node@v6
97 with:
98 node-version-file: .nvmrc
99 registry-url: "https://registry.npmjs.org"
100
101 - name: Check whether release already exists on npm
102 id: npm-check
103 shell: bash
104 run: |
105 if npm view "@smbcloud/sdk-auth@${RELEASE_VERSION}" version >/dev/null 2>&1; then
106 echo "@smbcloud/sdk-auth@${RELEASE_VERSION} already exists on npm, skipping publish"
107 echo "exists=true" >> "$GITHUB_OUTPUT"
108 else
109 echo "exists=false" >> "$GITHUB_OUTPUT"
110 fi
111
112 - name: Build and prepare package
113 if: steps.npm-check.outputs.exists != 'true'
114 working-directory: sdk/npm/smbcloud-auth
115 run: node ./prepare-package.mjs
116
117 - name: Publish to npm
118 if: steps.npm-check.outputs.exists != 'true'
119 working-directory: sdk/npm/smbcloud-auth
120 run: npm publish --access public