-
Notifications
You must be signed in to change notification settings - Fork 0
feat: publish to npm or github packages #11
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 all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,37 @@ main() { | |||||||||||||||||||||||||||||||||||||||||||||
| echo "release_url=${release_url}" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Publish to npm | ||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "${INPUT_PUBLISH_NPM:-false}" == "true" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "::group::Publishing to npm" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ! command -v npm &>/dev/null; then | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "::error::npm is not installed. Add a setup-node step before release-champion." | ||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -z "${INPUT_NPM_TOKEN:-}" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "::error::npm-token is required when publish-npm is true" | ||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| local registry="${INPUT_NPM_REGISTRY:-https://registry.npmjs.org}" | ||||||||||||||||||||||||||||||||||||||||||||||
| local registry_host | ||||||||||||||||||||||||||||||||||||||||||||||
| registry_host=$(echo "$registry" | sed 's|https:||') | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| echo "${registry_host}:_authToken=${INPUT_NPM_TOKEN}" > .npmrc | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+77
to
+79
|
||||||||||||||||||||||||||||||||||||||||||||||
| registry_host=$(echo "$registry" | sed 's|https:||') | |
| echo "${registry_host}:_authToken=${INPUT_NPM_TOKEN}" > .npmrc | |
| registry_host="${registry#http://}" | |
| registry_host="${registry_host#https://}" | |
| registry_host="${registry_host%%/*}" | |
| echo "//${registry_host}/:_authToken=${INPUT_NPM_TOKEN}" > .npmrc |
Copilot
AI
Apr 1, 2026
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.
This writes credentials to a workspace .npmrc and then deletes it, but (1) rm -f .npmrc won’t run if npm publish fails (leaving the token behind for subsequent steps), and (2) using a fixed .npmrc path can clobber a repo’s existing .npmrc (common in npm projects). Use a temp userconfig (e.g., via NPM_CONFIG_USERCONFIG / npm --userconfig) and a trap to guarantee cleanup, without overwriting/removing any pre-existing .npmrc.
| echo "${registry_host}:_authToken=${INPUT_NPM_TOKEN}" > .npmrc | |
| echo "registry=${registry}" >> .npmrc | |
| npm publish | |
| rm -f .npmrc | |
| # Use a temporary npm userconfig to avoid clobbering any existing .npmrc | |
| local npm_userconfig | |
| npm_userconfig="$(mktemp)" | |
| cleanup_npm_userconfig() { | |
| if [[ -n "${npm_userconfig:-}" && -f "$npm_userconfig" ]]; then | |
| rm -f "$npm_userconfig" | |
| fi | |
| } | |
| trap cleanup_npm_userconfig EXIT | |
| { | |
| echo "${registry_host}:_authToken=${INPUT_NPM_TOKEN}" | |
| echo "registry=${registry}" | |
| } > "$npm_userconfig" | |
| NPM_CONFIG_USERCONFIG="$npm_userconfig" npm publish |
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.
The
package-lock.jsonstaging condition is checking the staged diff before the file is staged, so it will never be added even ifnpm versionmodified it. This can leavepackage-lock.jsonupdated in the working tree but not committed/pushed on the release branch. Check for an unstaged change (or justgit add package-lock.jsonwhen the file exists) before committing.