Skip to content

Commit de1680c

Browse files
authored
ci: update npm based install method (#1133)
rel: #1131
1 parent 533a39e commit de1680c

15 files changed

Lines changed: 217 additions & 331 deletions

File tree

.github/workflows/rust.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,39 @@ jobs:
209209
with:
210210
node-version: 24
211211
- run: npm --version
212-
- run: npm publish
212+
213+
- name: Download release artifacts
214+
uses: actions/download-artifact@v4
215+
with:
216+
path: artifacts
217+
pattern: release-squawk-*
218+
219+
- name: Stage platform binaries
220+
run: |
221+
set -euo pipefail
222+
mkdir -p npm/darwin-x64/bin npm/darwin-arm64/bin npm/linux-x64/bin npm/linux-arm64/bin npm/win32-x64/bin
223+
cp artifacts/release-squawk-darwin-x64/squawk-darwin-x64 npm/darwin-x64/bin/squawk
224+
cp artifacts/release-squawk-darwin-arm64/squawk-darwin-arm64 npm/darwin-arm64/bin/squawk
225+
cp artifacts/release-squawk-linux-x64/squawk-linux-x64 npm/linux-x64/bin/squawk
226+
cp artifacts/release-squawk-linux-arm64/squawk-linux-arm64 npm/linux-arm64/bin/squawk
227+
cp artifacts/release-squawk-windows-x64.exe/squawk-windows-x64.exe npm/win32-x64/bin/squawk.exe
228+
chmod +x npm/darwin-x64/bin/squawk npm/darwin-arm64/bin/squawk npm/linux-x64/bin/squawk npm/linux-arm64/bin/squawk
229+
230+
- name: Inject optionalDependencies into root package.json
231+
run: |
232+
set -euo pipefail
233+
VERSION=$(node -p 'require("./package.json").version')
234+
for tgt in darwin-x64 darwin-arm64 linux-x64 linux-arm64 win32-x64; do
235+
npm pkg set "optionalDependencies.@squawk-cli/${tgt}=${VERSION}"
236+
done
237+
238+
- name: Publish packages
239+
run: |
240+
set -euo pipefail
241+
for pkg in darwin-x64 darwin-arm64 linux-x64 linux-arm64 win32-x64; do
242+
(cd "npm/$pkg" && npm publish --access public --provenance)
243+
done
244+
npm publish --access public --provenance
213245
214246
publish-docker:
215247
if: startsWith(github.ref, 'refs/tags/')

crates/xtask/src/update_version.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ fn update_versions(sh: &Shell, v: &str) -> Result<()> {
105105
r#""version": ".*""#,
106106
&json_rep,
107107
)?;
108+
for target in [
109+
"darwin-arm64",
110+
"darwin-x64",
111+
"linux-arm64",
112+
"linux-x64",
113+
"win32-x64",
114+
] {
115+
replace_in_file(
116+
sh,
117+
&format!("npm/{target}/package.json"),
118+
r#""version": ".*""#,
119+
&json_rep,
120+
)?;
121+
}
108122

109123
replace_in_file(
110124
sh,

js/bin/squawk

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,4 @@
22

33
"use strict"
44

5-
// Copyright (c) 2016 Sentry (https://sentry.io/) and individual contributors.
6-
// All rights reserved.
7-
//
8-
// Redistribution and use in source and binary forms, with or without
9-
// modification, are permitted provided that the following conditions are met:
10-
//
11-
// 1. Redistributions of source code must retain the above copyright notice,
12-
// this list of conditions and the following disclaimer.
13-
//
14-
// 2. Redistributions in binary form must reproduce the above copyright
15-
// notice, this list of conditions and the following disclaimer in the
16-
// documentation and/or other materials provided with the distribution.
17-
//
18-
// 3. Neither the name of the Sentry nor the names of its contributors may be
19-
// used to endorse or promote products derived from this software without specific
20-
// prior written permission.
21-
//
22-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23-
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24-
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25-
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26-
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27-
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28-
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29-
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30-
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32-
//
33-
// from: https://github.com/getsentry/sentry-cli/blob/acc8d00eb1965d8f49a9f337b7776c782d253ac4/bin/sentry-cli
34-
35-
const childProcess = require("child_process")
36-
const { binaryPath } = require("../helpers")
37-
38-
const child = childProcess.spawn(binaryPath, process.argv.slice(2), {
39-
stdio: "inherit",
40-
})
41-
42-
child.on("error", err => {
43-
console.error("error: failed to invoke squawk")
44-
console.error(err.stack)
45-
process.exit(1)
46-
})
47-
48-
child.on("exit", code => {
49-
process.exit(code)
50-
})
51-
52-
process.on("SIGTERM", () => {
53-
child.kill("SIGTERM")
54-
})
55-
56-
process.on("SIGINT", () => {
57-
child.kill("SIGINT")
58-
})
5+
require("../index.js").run()

js/binaries/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

js/helpers.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

js/index.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use strict"
2+
3+
const childProcess = require("child_process")
4+
5+
/** @type {Record<string, string>} */
6+
const PLATFORM_PACKAGES = {
7+
"darwin-x64": "@squawk-cli/darwin-x64",
8+
"darwin-arm64": "@squawk-cli/darwin-arm64",
9+
"linux-x64": "@squawk-cli/linux-x64",
10+
"linux-arm64": "@squawk-cli/linux-arm64",
11+
"win32-x64": "@squawk-cli/win32-x64",
12+
}
13+
14+
function getBinaryPath() {
15+
const key = `${process.platform}-${process.arch}`
16+
const pkg = PLATFORM_PACKAGES[key]
17+
if (!pkg) {
18+
throw new Error(
19+
`squawk: unsupported platform "${key}". Supported: ${Object.keys(PLATFORM_PACKAGES).join(", ")}.`,
20+
)
21+
}
22+
const binaryName = process.platform === "win32" ? "squawk.exe" : "squawk"
23+
try {
24+
return require.resolve(`${pkg}/bin/${binaryName}`)
25+
} catch {
26+
throw new Error(
27+
`squawk: the "${pkg}" optional dependency was not installed.\n` +
28+
`This usually means your package manager skipped optional dependencies. ` +
29+
`Re-install with optional dependencies enabled (e.g. "npm install --include=optional").`,
30+
)
31+
}
32+
}
33+
34+
function resolveBinaryOrExit() {
35+
try {
36+
return getBinaryPath()
37+
} catch (err) {
38+
console.error(err instanceof Error ? err.message : err)
39+
process.exit(1)
40+
}
41+
}
42+
43+
function run() {
44+
const binaryPath = resolveBinaryOrExit()
45+
46+
const child = childProcess.spawn(binaryPath, process.argv.slice(2), {
47+
stdio: "inherit",
48+
})
49+
50+
child.on("error", (err) => {
51+
console.error("error: failed to invoke squawk")
52+
console.error(err.stack)
53+
})
54+
55+
child.on("exit", (code) => {
56+
process.exit(code ?? 1)
57+
})
58+
59+
process.on("SIGTERM", () => {
60+
child.kill("SIGTERM")
61+
})
62+
63+
process.on("SIGINT", () => {
64+
child.kill("SIGINT")
65+
})
66+
}
67+
68+
module.exports = { getBinaryPath, run }

js/install.js

Lines changed: 0 additions & 168 deletions
This file was deleted.

npm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*/bin/squawk
2+
*/bin/squawk.exe

npm/darwin-arm64/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@squawk-cli/darwin-arm64",
3+
"version": "0.0.0",
4+
"description": "squawk-cli binary for darwin-arm64",
5+
"repository": "git@github.com:sbdchd/squawk.git",
6+
"license": "(Apache-2.0 OR MIT)",
7+
"os": [
8+
"darwin"
9+
],
10+
"cpu": [
11+
"arm64"
12+
],
13+
"bin": {
14+
"squawk": "bin/squawk"
15+
},
16+
"files": [
17+
"bin/squawk"
18+
]
19+
}

0 commit comments

Comments
 (0)