From 34fe129258bb8047156bc983e371ce62ddab7ff8 Mon Sep 17 00:00:00 2001 From: bntvllnt <32437578+bntvllnt@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:02:49 +0100 Subject: [PATCH] ci: bump canary when the package version is already published If package.json still matches npm latest, or that exact version is already on the registry, increment the patch and publish BASE-canary. so the canary always sorts above the current stable. Also run the canary job when package.json itself changes. --- .github/workflows/publish.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a4b444b..3fa8aaa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,6 +5,7 @@ on: branches: [main] paths: - "src/**" + - "package.json" - "pnpm-lock.yaml" - ".github/workflows/publish.yml" workflow_dispatch: {} @@ -73,7 +74,22 @@ jobs: run: | sed -i '/_authToken/d' "$NPM_CONFIG_USERCONFIG" unset NODE_AUTH_TOKEN + PKG=$(node -p "require('./package.json').name") BASE_VERSION=$(node -p "require('./package.json').version") + LATEST=$(npm view "${PKG}" dist-tags.latest 2>/dev/null || true) + # A canary must sort above the current stable (npm latest) and above any + # already-published copy of package.json's version. + if [ -n "$(npm view "${PKG}@${BASE_VERSION}" version 2>/dev/null || true)" ] || \ + { [ -n "$LATEST" ] && [ "$BASE_VERSION" = "$LATEST" ]; }; then + BASE_VERSION=$(node -e "const v=require('./package.json').version.split('.').map(Number); console.log(v[0]+'.'+v[1]+'.'+(v[2]+1))") + fi + if [ -n "$LATEST" ] && [[ "$LATEST" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + BASE_VERSION=$(node -e ' + const [b,l]=process.argv.slice(1).map(v=>v.split(".").map(Number)); + const less=b[0]