This guide explains how to set up GitHub Actions for automated testing, building, and deploying the Discord Notify package to npm.
- Triggers: Push to main/develop, Pull Requests
- Purpose: Run tests, build package, security audit
- Runs on: Multiple Node.js versions (16.x, 18.x, 20.x)
- Triggers: Push to main branch
- Purpose: Auto-detect version changes, create GitHub releases
- Runs on: Node.js 20.x
- Triggers: GitHub releases, manual dispatch
- Purpose: Publish package to npm
- Runs on: Node.js 20.x
-
Login to npm:
npm login
-
Create Access Token:
- Go to npmjs.com
- Click your profile β Access Tokens
- Click "Generate New Token"
- Select "Automation" token type
- Copy the token (you won't see it again!)
Go to your GitHub repository β Settings β Secrets and variables β Actions
Add these secrets:
| Secret Name | Value | Description |
|---|---|---|
NPM_TOKEN |
npm_xxxxxxxxxxxx |
Your npm automation token |
DISCORD_WEBHOOK_URL |
https://discord.com/api/webhooks/... |
Discord webhook for notifications (optional) |
Make sure your package.json has the correct configuration:
{
"name": "discord-notify",
"version": "1.0.0",
"publishConfig": {
"access": "public"
},
"files": ["dist"],
"main": "dist/index.js",
"types": "dist/index.d.ts"
}-
Push to main branch:
git add . git commit -m "feat: initial release" git push origin main
-
Check GitHub Actions:
- Go to Actions tab in your repository
- You should see the CI workflow running
-
Update version in package.json:
npm version patch # 1.0.0 β 1.0.1 npm version minor # 1.0.1 β 1.1.0 npm version major # 1.1.0 β 2.0.0
-
Push to main:
git push origin main --tags
-
What happens automatically:
- CI workflow runs tests
- Release workflow detects version change
- Creates GitHub release
- Triggers deploy workflow
- Publishes to npm
- Go to Actions tab
- Select "Deploy to NPM" workflow
- Click "Run workflow"
- Enter version number
- Click "Run workflow"
- Runs on Node.js 16.x, 18.x, 20.x
- Installs dependencies
- Runs linting (
npm run lint) - Runs all tests (
npm run test:all) - Builds package (
npm run build) - Validates build output
- Runs only on main branch pushes
- Uses Discord webhook from secrets
- Runs integration tests
- Continues on error (optional)
- Runs npm audit
- Checks for high severity vulnerabilities
- Fails if high severity issues found
- Detects version changes in package.json
- Creates GitHub release with changelog
- Triggers deploy workflow
- Skips if version already exists
- Runs tests and builds package
- Validates package with
npm pack --dry-run - Publishes to npm using NPM_TOKEN
- Creates GitHub release (if manual trigger)
Error: npm ERR! 401 Unauthorized
Solution:
- Verify NPM_TOKEN secret is set correctly
- Ensure token has publish permissions
- Check if package name is available on npm
Error: TypeScript compilation failed
Solution:
- Run
npm run buildlocally to check for errors - Fix TypeScript errors
- Ensure all dependencies are installed
Error: Tests are failing
Solution:
- Run
npm testlocally - Fix failing tests
- Check if all test dependencies are installed
Error: Version already exists
Solution:
- Update version in package.json
- Use
npm versionto bump version - Push with tags:
git push --tags
# Test locally
npm run test:all
npm run build
npm pack --dry-run
# Check npm token
npm whoami
# Test publish (dry run)
npm publish --dry-run- Go to Actions tab to monitor workflow runs
- Check logs for detailed error information
- Set up notifications for workflow failures
- Monitor downloads: https://www.npmjs.com/package/discord-notify
- Check for issues or feedback
- Monitor package health
If you set up DISCORD_WEBHOOK_URL, you'll get notifications for:
- Successful deployments
- Failed workflows
- New releases
- name: Run additional tests
run: npm run test:custom- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info- name: Notify Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
webhook_url: ${{ secrets.SLACK_WEBHOOK }}- Always test locally before pushing
- Use semantic versioning (patch/minor/major)
- Write meaningful commit messages
- Monitor workflow runs regularly
- Keep dependencies updated
- Use descriptive release notes
If you encounter issues:
- Check the troubleshooting section above
- Review GitHub Actions logs
- Test locally with the debug commands
- Open an issue in the repository
- Join our Discord community for help