@sigit / si Mirror · read-only
Fork 0

Mirror of github.com/getsigit/si.

Mirrored from https://github.com/getsigit/si.git

Synced Nov 24, 08:15 UTC

1 name: Release npm
2
3 # Publishes @getsigit/si, a launcher that resolves the native `si` binary from one of six
4 # platform packages (@getsigit/si-<os>-<arch>), on the same tag that release-crates.yml
5 # publishes from.
6 #
7 # Auth is npm Trusted Publishing (OIDC), so no token is stored. Each of the seven packages needs
8 # a trusted publisher for this repository and workflow (release-npm.yml). `npm trust` only works
9 # on a package that already exists, so the first version of each is published by hand.
10
11 on:
12 push:
13 tags:
14 - "v*.*.*"
15 workflow_dispatch:
16 inputs:
17 tag:
18 description: "Release tag (e.g. v1.3.0)"
19 required: true
20
21 concurrency:
22 group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }}
23 cancel-in-progress: false
24
25 permissions:
26 contents: read
27
28 env:
29 CARGO_TERM_COLOR: always
30
31 jobs:
32 # The binary reports CARGO_PKG_VERSION, and the launcher package.json carries its own copy of
33 # the version, so both must agree with the tag.
34 verify-version:
35 runs-on: ubuntu-latest
36 steps:
37 - uses: actions/checkout@v6
38 with:
39 ref: ${{ github.event.inputs.tag || github.ref }}
40 - name: Tag matches the workspace and npm package versions
41 shell: bash
42 env:
43 TAG: ${{ github.event.inputs.tag || github.ref_name }}
44 run: |
45 workspace=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
46 if [ "$TAG" != "v$workspace" ]; then
47 echo "::error::tag $TAG does not match the workspace version $workspace"
48 exit 1
49 fi
50
51 npm_version=$(node -p "require('./packaging/npm/si/package.json').version")
52 if [ "$TAG" != "v$npm_version" ]; then
53 echo "::error::tag $TAG does not match packaging/npm/si/package.json version $npm_version. Bump it (and its lockfile) with the workspace version."
54 exit 1
55 fi
56
57 publish-npm-binaries:
58 name: Publish @getsigit/si-${{ matrix.build.NAME }}
59 needs: verify-version
60 runs-on: ${{ matrix.build.OS }}
61 permissions:
62 contents: read
63 id-token: write
64 strategy:
65 fail-fast: false
66 matrix:
67 build:
68 - {
69 NAME: linux-x64,
70 OS: ubuntu-22.04,
71 TARGET: x86_64-unknown-linux-gnu,
72 NODE_OS: linux,
73 NODE_ARCH: x64,
74 }
75 - {
76 NAME: linux-arm64,
77 OS: ubuntu-22.04-arm,
78 TARGET: aarch64-unknown-linux-gnu,
79 NODE_OS: linux,
80 NODE_ARCH: arm64,
81 }
82 - {
83 NAME: windows-x64,
84 OS: windows-2022,
85 TARGET: x86_64-pc-windows-msvc,
86 NODE_OS: win32,
87 NODE_ARCH: x64,
88 }
89 - {
90 NAME: windows-arm64,
91 OS: windows-2022,
92 TARGET: aarch64-pc-windows-msvc,
93 NODE_OS: win32,
94 NODE_ARCH: arm64,
95 }
96 - {
97 NAME: darwin-x64,
98 OS: macos-26,
99 TARGET: x86_64-apple-darwin,
100 NODE_OS: darwin,
101 NODE_ARCH: x64,
102 }
103 - {
104 NAME: darwin-arm64,
105 OS: macos-26,
106 TARGET: aarch64-apple-darwin,
107 NODE_OS: darwin,
108 NODE_ARCH: arm64,
109 }
110 steps:
111 - name: Checkout
112 uses: actions/checkout@v6
113 with:
114 ref: ${{ github.event.inputs.tag || github.ref }}
115
116 - name: Set the release version
117 shell: bash
118 run: |
119 release_version="${{ github.event.inputs.tag || github.ref_name }}"
120 echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV"
121
122 - name: Read Rust toolchain
123 shell: bash
124 run: |
125 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
126 if [ -z "$rust_toolchain" ]; then
127 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
128 exit 1
129 fi
130 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
131
132 - name: Install Rust toolchain
133 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
134 with:
135 toolchain: ${{ env.RUST_TOOLCHAIN }}
136
137 - name: Install Rust target
138 shell: bash
139 run: |
140 rustup target add ${{ matrix.build.TARGET }} --toolchain ${{ env.RUST_TOOLCHAIN }}
141 rustup target list --installed
142
143 - name: Setup Rust cache
144 uses: Swatinem/rust-cache@v2
145 with:
146 key: npm-${{ matrix.build.TARGET }}
147
148 # Linux builds on the oldest runner image for its glibc floor (2.35). The repo uses rustls,
149 # so there is no OpenSSL to link or vendor.
150 - name: Build binary
151 shell: bash
152 run: cargo build --locked --release -p sigit-si-cli --bin si --target ${{ matrix.build.TARGET }}
153
154 # The exe must not import the VC++ runtime DLLs (see .cargo/config.toml), or it fails to
155 # load on a machine without the redistributable.
156 - name: Check static CRT
157 if: contains(matrix.build.TARGET, 'windows')
158 shell: pwsh
159 run: ./packaging/windows/check-static-crt.ps1 -Path target/${{ matrix.build.TARGET }}/release/si.exe
160
161 - name: Install Node
162 uses: actions/setup-node@v6
163 with:
164 node-version-file: .nvmrc
165 registry-url: "https://registry.npmjs.org"
166
167 - name: Render the platform package
168 shell: bash
169 env:
170 BUILD_NAME: ${{ matrix.build.NAME }}
171 TARGET: ${{ matrix.build.TARGET }}
172 NODE_OS: ${{ matrix.build.NODE_OS }}
173 NODE_ARCH: ${{ matrix.build.NODE_ARCH }}
174 run: |
175 package_directory="si-${BUILD_NAME}"
176 executable_name="si"
177 if [[ "${BUILD_NAME}" == windows-* ]]; then
178 executable_name="si.exe"
179 fi
180
181 mkdir -p "packaging/npm/${package_directory}/bin"
182 node packaging/npm/scripts/render-platform-package.cjs \
183 "${package_directory}" "${RELEASE_VERSION}" "${NODE_OS}" "${NODE_ARCH}"
184 cp "target/${TARGET}/release/${executable_name}" "packaging/npm/${package_directory}/bin/"
185
186 - name: Check whether the package version already exists on npm
187 id: npm-check
188 shell: bash
189 env:
190 BUILD_NAME: ${{ matrix.build.NAME }}
191 run: |
192 # A 404 means this version is not on npm yet. Anything other than 200 or 404 is an
193 # outage or a block, which must not read as "not published yet".
194 status=$(curl -sS -o /dev/null -w '%{http_code}' \
195 --retry 3 --retry-delay 2 --retry-all-errors \
196 "https://registry.npmjs.org/@getsigit%2Fsi-${BUILD_NAME}/${RELEASE_VERSION}")
197
198 case "$status" in
199 200)
200 echo "@getsigit/si-${BUILD_NAME}@${RELEASE_VERSION} already exists on npm, skipping publish"
201 echo "exists=true" >> "$GITHUB_OUTPUT"
202 ;;
203 404)
204 echo "exists=false" >> "$GITHUB_OUTPUT"
205 ;;
206 *)
207 echo "Unexpected ${status} from npm while checking @getsigit/si-${BUILD_NAME}@${RELEASE_VERSION}" >&2
208 exit 1
209 ;;
210 esac
211
212 - name: Publish to npm
213 if: steps.npm-check.outputs.exists != 'true'
214 shell: bash
215 env:
216 BUILD_NAME: ${{ matrix.build.NAME }}
217 run: |
218 cd "packaging/npm/si-${BUILD_NAME}"
219 npm publish --access public --provenance
220
221 publish-npm-base:
222 name: Publish @getsigit/si
223 needs: publish-npm-binaries
224 runs-on: ubuntu-latest
225 permissions:
226 contents: read
227 id-token: write
228 steps:
229 - name: Checkout
230 uses: actions/checkout@v6
231 with:
232 ref: ${{ github.event.inputs.tag || github.ref }}
233
234 - name: Set the release version
235 shell: bash
236 run: |
237 release_version="${{ github.event.inputs.tag || github.ref_name }}"
238 echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV"
239
240 - name: Install Node
241 uses: actions/setup-node@v6
242 with:
243 node-version-file: .nvmrc
244 registry-url: "https://registry.npmjs.org"
245
246 - name: Render and build the launcher
247 shell: bash
248 working-directory: packaging/npm/si
249 run: |
250 node ../scripts/render-main-package.cjs ./package.json "${RELEASE_VERSION}"
251 npm ci
252 npm run build
253
254 - name: Check whether the package version already exists on npm
255 id: npm-check
256 shell: bash
257 run: |
258 status=$(curl -sS -o /dev/null -w '%{http_code}' \
259 --retry 3 --retry-delay 2 --retry-all-errors \
260 "https://registry.npmjs.org/@getsigit%2Fsi/${RELEASE_VERSION}")
261
262 case "$status" in
263 200)
264 echo "@getsigit/si@${RELEASE_VERSION} already exists on npm, skipping publish"
265 echo "exists=true" >> "$GITHUB_OUTPUT"
266 ;;
267 404)
268 echo "exists=false" >> "$GITHUB_OUTPUT"
269 ;;
270 *)
271 echo "Unexpected ${status} from npm while checking @getsigit/si@${RELEASE_VERSION}" >&2
272 exit 1
273 ;;
274 esac
275
276 - name: Publish to npm
277 if: steps.npm-check.outputs.exists != 'true'
278 shell: bash
279 working-directory: packaging/npm/si
280 run: npm publish --access public --provenance