GitHub Action to automatically post npm install commands for testing packages directly from GitHub commits.
- 🎯 Generates npm install command with commit hash
- 📦 Allows testing PRs before merging
- 🔄 Updates existing comment instead of creating duplicates
- 💡 Optional package name for context
Add this action to your workflow file (e.g., .github/workflows/ci.yml):
- uses: helderberto/github-package-install-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}name: CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Post install command
uses: helderberto/github-package-install-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
package-name: my-package-name| Input | Description | Required | Default |
|---|---|---|---|
github-token |
GitHub token for authentication | ✅ Yes | - |
package-name |
Package name (for display) | No | - |
comment-title |
Title for the PR comment | No | 🎯 Test this PR |
Basic usage (minimal):
- uses: helderberto/github-package-install-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}With package name:
- uses: helderberto/github-package-install-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
package-name: my-awesome-packageCustom comment title:
- uses: helderberto/github-package-install-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: '📦 Try This Version'Complete example with tests:
name: CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Post install command
if: success()
uses: helderberto/github-package-install-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
package-name: my-package- Requires
pull-requests: writepermission - Only runs on
pull_requestevents - Package must be buildable from the GitHub repository
The action posts a comment on your PR that looks like this:
Install this PR directly from GitHub to test it before merging:
npm install github:helderberto/stato#abc1234Commit: abc1234
Package: stato-react
- Copy the install command from the comment above
- Run it in your project:
npm install github:helderberto/stato#abc1234
- Test the changes in your local environment
- Provide feedback on the PR
To go back to the published version:
npm install stato-react@latestTesting npm packages before they're published:
- ✅ Verify changes work in real projects
- ✅ Test breaking changes before merging
- ✅ Get feedback from reviewers with actual usage
- ✅ No need to publish pre-release versions
GitHub allows installing npm packages directly from repositories using the format:
npm install github:owner/repo#commit-hashThis action:
- Gets the PR commit hash
- Generates the install command
- Posts/updates a PR comment with the command
- Allows users to test the exact PR changes
This action uses @vercel/ncc to bundle dependencies into a single file.
After making changes to src/index.ts, run:
npm run buildThis compiles src/index.ts and all dependencies into dist/index.js. The dist/ folder is committed to the repository (not node_modules/).
- No runtime dependencies -
dist/index.jscontains everything - Faster action execution - no
npm installneeded - Smaller repository - commit bundled code, not
node_modules/
MIT