Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
| `publish-npm` | Publish the package to an npm registry when the release PR is merged | No | `false` |
| `npm-token` | Auth token for the npm registry (required when `publish-npm` is `true`) | No | — |
| `npm-registry` | npm registry URL (set to `https://npm.pkg.github.com` for GitHub Packages) | No | `https://registry.npmjs.org` |
| `npm-build-command` | Build command to run before `npm publish` (e.g., `npm run build`) | No | — |

## Outputs

Expand Down Expand Up @@ -178,6 +179,7 @@ Commits that can't be linked to a PR will reference the commit SHA instead.
github-token: ${{ secrets.GITHUB_TOKEN }}
publish-npm: true
npm-token: ${{ secrets.NPM_TOKEN }}
npm-build-command: 'npm run build'
```

### Publish to GitHub Packages
Expand All @@ -189,6 +191,7 @@ Commits that can't be linked to a PR will reference the commit SHA instead.
publish-npm: true
npm-token: ${{ secrets.GITHUB_TOKEN }}
npm-registry: 'https://npm.pkg.github.com'
npm-build-command: 'npm run build'
```

### Tag only, no GitHub release
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ inputs:
description: 'npm registry URL (e.g., https://npm.pkg.github.com for GitHub Packages)'
required: false
default: 'https://registry.npmjs.org'
npm-build-command:
description: 'Build command to run before npm publish (e.g., npm run build)'
required: false

outputs:
version:
Expand Down Expand Up @@ -80,6 +83,7 @@ runs:
INPUT_PUBLISH_NPM: ${{ inputs.publish-npm }}
INPUT_NPM_TOKEN: ${{ inputs.npm-token }}
INPUT_NPM_REGISTRY: ${{ inputs.npm-registry }}
INPUT_NPM_BUILD_COMMAND: ${{ inputs.npm-build-command }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_MERGED: ${{ github.event.pull_request.merged }}
Expand Down
6 changes: 6 additions & 0 deletions scripts/finalize-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ main() {
echo "${registry_host}/:_authToken=${INPUT_NPM_TOKEN}" > .npmrc
echo "registry=${registry}" >> .npmrc

if [[ -n "${INPUT_NPM_BUILD_COMMAND:-}" ]]; then
echo "Running build: ${INPUT_NPM_BUILD_COMMAND}"
npm install
eval "$INPUT_NPM_BUILD_COMMAND"
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using eval to run the build command adds an extra round of shell parsing/expansion (beyond what bash -c would do) and can lead to unexpected behavior or command injection if the input ever becomes attacker-controlled. Prefer invoking a shell with -c (or restricting this input to an npm run <script> pattern) instead of eval.

Suggested change
eval "$INPUT_NPM_BUILD_COMMAND"
bash -c "$INPUT_NPM_BUILD_COMMAND"

Copilot uses AI. Check for mistakes.
Comment on lines 79 to +85
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .npmrc containing the publish token is written before npm install / the build command runs. That means dependency lifecycle scripts (and any build tooling) can read/exfiltrate the token, and if the build fails the .npmrc cleanup won’t run. Consider (1) moving .npmrc creation to immediately before npm publish (or using NODE_AUTH_TOKEN just for publish), and (2) adding an EXIT trap to reliably remove .npmrc even on failures.

Copilot uses AI. Check for mistakes.
fi

npm publish

rm -f .npmrc
Expand Down
Loading