From 9e00f356912bed6dec4c0726e179a7aeae1faf04 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Sun, 4 Oct 2026 11:50:56 -0400 Subject: [PATCH] ci: allow re-running publish script --- .github/workflows/rust.yml | 7 +---- s/publish-npm.js | 61 ++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100755 s/publish-npm.js diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1aaa357fa..78e8c53ea 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -240,12 +240,7 @@ jobs: chmod +x npm/darwin-x64/bin/squawk npm/darwin-arm64/bin/squawk npm/linux-x64/bin/squawk npm/linux-arm64/bin/squawk npm/linux-x64-musl/bin/squawk npm/linux-arm64-musl/bin/squawk - name: Publish packages - run: | - set -euo pipefail - for pkg in darwin-x64 darwin-arm64 linux-x64 linux-arm64 linux-x64-musl linux-arm64-musl win32-x64; do - (cd "npm/$pkg" && npm publish --access public --provenance) - done - npm publish --access public --provenance + run: ./s/publish-npm.js publish-docker: if: startsWith(github.ref, 'refs/tags/') diff --git a/s/publish-npm.js b/s/publish-npm.js new file mode 100755 index 000000000..61f9005f4 --- /dev/null +++ b/s/publish-npm.js @@ -0,0 +1,61 @@ +#!/usr/bin/env node +"use strict" + +const childProcess = require("child_process") +const fs = require("fs") +const path = require("path") + +/** @type {readonly string[]} */ +const PLATFORMS = [ + "darwin-x64", + "darwin-arm64", + "linux-x64", + "linux-arm64", + "linux-x64-musl", + "linux-arm64-musl", + "win32-x64", +] + +/** + * @param {string} name + * @param {string} version + * @returns {boolean} + */ +function isPublished(name, version) { + const result = childProcess.spawnSync( + "npm", + ["view", `${name}@${version}`, "version"], + { encoding: "utf8" }, + ) + return result.status === 0 && result.stdout.trim() === version +} + +/** + * @param {string} dir + * @returns {void} + */ +function publish(dir) { + /** @type {{ name: string, version: string }} */ + const { name, version } = JSON.parse( + fs.readFileSync(path.join(dir, "package.json"), "utf8"), + ) + if (isPublished(name, version)) { + console.log(`skipping ${name}@${version}, already published`) + return + } + childProcess.execFileSync( + "npm", + ["publish", "--access", "public", "--provenance"], + { cwd: dir, stdio: "inherit" }, + ) +} + +/** @returns {void} */ +function main() { + for (const platform of PLATFORMS) { + publish(path.join("npm", platform)) + } + publish(".") +} + +main() diff --git a/tsconfig.json b/tsconfig.json index e379b39f6..615e922ec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,6 @@ "jsx": "react", "noEmit": true }, - "include": ["js/**/*.js"], + "include": ["js/**/*.js", "s/**/*.js"], "exclude": ["build", "node_modules", "docs", "plopfile.js", "playground"] }