Skip to content

Commit 911d797

Browse files
committed
ci(release): make npm/jsr publish idempotent
1 parent 251c7bf commit 911d797

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
- uses: denoland/setup-deno@v2
5151
with:
52-
deno-version: lts
52+
deno-version: v2.x
5353

5454
- name: Resolve release version
5555
id: version
@@ -89,6 +89,36 @@ jobs:
8989
deno publish --dry-run --allow-dirty
9090
npm publish --provenance --dry-run
9191
92+
- if: env.RELEASE_PUBLISH == 'true'
93+
name: Publish to npm and JSR (idempotent)
94+
env:
95+
RELEASE_VERSION: ${{ steps.version.outputs.version }}
96+
run: |
97+
set -euo pipefail
98+
99+
if npm view "@rotu/structview@${RELEASE_VERSION}" version >/dev/null 2>&1; then
100+
echo "npm already has @rotu/structview@${RELEASE_VERSION}; skipping npm publish"
101+
else
102+
npm publish --provenance
103+
fi
104+
105+
if deno eval --quiet 'const packageMeta = await fetch("https://jsr.io/@rotu/structview/meta.json").then((response) => response.json()); const versions = packageMeta?.versions ?? {}; Deno.exit(Object.hasOwn(versions, Deno.env.get("RELEASE_VERSION") ?? "") ? 0 : 1);'; then
106+
echo "JSR already has @rotu/structview@${RELEASE_VERSION}; skipping JSR publish"
107+
else
108+
deno publish --allow-dirty
109+
fi
110+
111+
- if: env.RELEASE_PUBLISH == 'true'
112+
name: Verify published version parity
113+
env:
114+
RELEASE_VERSION: ${{ steps.version.outputs.version }}
115+
run: |
116+
set -euo pipefail
117+
118+
npm view "@rotu/structview@${RELEASE_VERSION}" version >/dev/null
119+
120+
deno eval --quiet 'const packageMeta = await fetch("https://jsr.io/@rotu/structview/meta.json").then((response) => response.json()); const versions = packageMeta?.versions ?? {}; if (!Object.hasOwn(versions, Deno.env.get("RELEASE_VERSION") ?? "")) { throw new Error(`JSR is missing version ${Deno.env.get("RELEASE_VERSION")}`); }'
121+
92122
- if: env.RELEASE_PUBLISH == 'true'
93123
name: Commit and tag release
94124
shell: bash
@@ -113,10 +143,3 @@ jobs:
113143
env:
114144
GH_TOKEN: ${{ github.token }}
115145
run: gh release create "${{ steps.version.outputs.tag }}" --notes-file "$RUNNER_TEMP/release-notes.md"
116-
117-
- if: env.RELEASE_PUBLISH == 'true'
118-
name: Publish to JSR and npm
119-
run: |
120-
set -euo pipefail
121-
deno publish
122-
npm publish --provenance

0 commit comments

Comments
 (0)