chore: use NPM trusted publishing with semver tag triggers#1907
Merged
chore: use NPM trusted publishing with semver tag triggers#1907
Conversation
…g triggers Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add GitHub Action for trusted npm publish on tag creation
Add GitHub Actions workflow for NPM trusted publishing with semver tag triggers
Oct 17, 2025
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1907 +/- ##
=======================================
Coverage 99.90% 99.90%
=======================================
Files 9 9
Lines 2066 2066
=======================================
Hits 2064 2064
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an automated NPM publishing workflow that leverages GitHub's trusted publishing feature to securely publish the Koa package whenever a semantic versioning tag is pushed.
Overview
The new
.github/workflows/npm-publish.ymlworkflow automates the release process with enhanced security through NPM provenance, ensuring packages are verifiably linked to their source code.Key Features
🏷️ Semver Tag Triggers
The workflow triggers only when tags matching semantic versioning format are pushed:
v1.0.0,v2.10.15v3.0.0-alpha,v3.0.0-beta.1v4.0.0-rc.2Tags without the
vprefix, incomplete versions (e.g.,v1.0), or non-semver formats are ignored.🔐 NPM Trusted Publishing
Implements NPM's trusted publishing with provenance:
--provenanceflag: Generates cryptographic attestations linking the published package to the GitHub repository and specific commit✅ Quality Gates
Before publishing, the workflow automatically:
npm run lint)npm test)This ensures only quality-validated releases reach NPM.
🛠️ Best Practices
npm cifor reproducible, consistent buildsSetup Requirements
To use this workflow, repository maintainers need to:
Add NPM token to GitHub Secrets
NPM_TOKENwith your NPM automation tokenConfigure NPM account for trusted publishing
--access publicfrom the workflow)Usage
To publish a new version:
# Create a semver tag git tag v3.0.2 git push origin v3.0.2The workflow will automatically:
Technical Details
The workflow uses three tag patterns to cover common semver formats while working within GitHub Actions' glob pattern limitations:
v[0-9]+.[0-9]+.[0-9]+- Standard semver (v1.0.0)v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+- Pre-release (v1.0.0-alpha)v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+.[0-9]+- Pre-release with number (v1.0.0-beta.1)Permissions are configured for trusted publishing:
contents: read- Access repository codeid-token: write- Generate OIDC tokens for NPM authenticationThis implementation enhances the project's release automation while improving security and supply chain transparency for all Koa users.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.