-
-
Notifications
You must be signed in to change notification settings - Fork 711
ci: add canary publish workflow using npm Trusted Publisher (OIDC) #2285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e367178
0c99c82
afd4b84
7b71bdb
29a872c
1f1bbec
39b1949
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| name: Publish Canary | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: Publish canary to npm | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write # required for OIDC Trusted Publisher | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: latest | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| registry-url: https://registry.npmjs.org | ||
|
|
||
| # npm must be upgraded for OIDC Trusted Publisher to work | ||
| - name: Upgrade npm | ||
| run: npm install -g npm@latest | ||
|
|
||
| # Build everything from root — this builds dexie + all addons/libs | ||
| - name: Install dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Build all packages | ||
| run: pnpm run build | ||
|
|
||
| # Publish each package if its version is not already on npm | ||
| - name: Publish dexie | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-cloud-common | ||
| working-directory: libs/dexie-cloud-common | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-cloud-common@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-cloud-common@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-cloud-common@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-react-hooks | ||
| working-directory: libs/dexie-react-hooks | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-react-hooks@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-react-hooks@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-react-hooks@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-svelte-query | ||
| working-directory: libs/dexie-svelte-query | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-svelte-query@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-svelte-query@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-svelte-query@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-export-import | ||
| working-directory: addons/dexie-export-import | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-export-import@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-export-import@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-export-import@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-observable | ||
| working-directory: addons/Dexie.Observable | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-observable@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-observable@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-observable@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-syncable | ||
| working-directory: addons/Dexie.Syncable | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-syncable@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-syncable@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-syncable@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish y-dexie | ||
| working-directory: addons/y-dexie | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show y-dexie@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing y-dexie@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "y-dexie@$VERSION already published, skipping." | ||
| fi | ||
|
|
||
| - name: Publish dexie-cloud-addon | ||
| working-directory: addons/dexie-cloud | ||
| run: | | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| PUBLISHED=$(npm show dexie-cloud-addon@$VERSION version 2>/dev/null || echo "") | ||
| if [ -z "$PUBLISHED" ]; then | ||
| echo "Publishing dexie-cloud-addon@$VERSION as canary..." | ||
| pnpm publish --tag canary --provenance --no-git-checks | ||
| else | ||
| echo "dexie-cloud-addon@$VERSION already published, skipping." | ||
| fi | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: No, npm cannot publish the same package version more than once. The official npm documentation states: "The publish will fail if the package name and version combination already exists in the specified registry. Once a package is published with a given name and version, that specific name and version combination can never be used again, even if it is removed with npm unpublish." The supported way to update or move a dist-tag like canary for an already-published version is to use the npm dist-tag command. Specifically: - To add or move the tag to a specific version: npm dist-tag add @ canary - To remove a tag: npm dist-tag rm canary - To list tags: npm dist-tag ls This allows pointing dist-tags to any existing published version without republishing the version itself. Citations:
Update the publish logic to account for npm's version immutability. The skip guard based on exact version will prevent repeated canaries on each
Option 2 is the standard pattern for dist-tag workflows: publish once per version, then use 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve npm show error handling to distinguish "not found" from other failures.
The current pattern
2>/dev/null || echo ""treats all errors (network issues, auth problems, registry outages) the same as "version not found". This could cause confusing error messages whenpnpm publishthen fails for an already-published version.🔧 Suggested fix using exit code inspection
Note: This same pattern applies to all other publish steps.
🤖 Prompt for AI Agents