This reusable GitHub Actions workflow automates the process of creating releases for npm packages, including building, packaging, and publishing releases with optional email notifications.
The workflow performs these main tasks:
- Checks prerequisites and existing releases
- Builds and packages the npm module
- Creates a GitHub release with package artifacts
- Sends email notifications (optional)
Create a workflow file (e.g., .github/workflows/create-package-release.yml
) in your repository:
name: Create Package Release
on:
workflow_dispatch:
inputs:
tag-name:
description: 'Tag name for release (optional)'
required: false
jobs:
create-release:
uses: wrappid/workflows/.github/workflows/create-package-release.yml@main
with:
GIT_USER_NAME: "Your Name"
TOOLKIT_VERSION: "1.0.0"
EMAIL_NOTIFY: "true"
EMAIL_SENDER_NAME: "CI/CD Pipeline"
secrets:
PAT: ${{ secrets.PAT }}
GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
WRAPPID_REGISTRY_TOKEN: ${{ secrets.WRAPPID_REGISTRY_TOKEN }}
EMAIL_SERVER_ADDRESS: ${{ secrets.EMAIL_SERVER_ADDRESS }}
EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }}
EMAIL_USER_ID: ${{ secrets.EMAIL_USER_ID }}
EMAIL_USER_PASSWORD: ${{ secrets.EMAIL_USER_PASSWORD }}
EMAIL_TO: ${{ secrets.EMAIL_TO }}
EMAIL_CC: ${{ secrets.EMAIL_CC }}
EMAIL_BCC: ${{ secrets.EMAIL_BCC }}
Name | Required | Default | Description |
---|---|---|---|
GIT_USER_NAME |
Yes | - | The name to use for Git operations |
TOOLKIT_VERSION |
Yes | - | Version of @wrappid/toolkit to use |
EMAIL_NOTIFY |
Yes | "true" | Enable/disable email notifications |
EMAIL_SENDER_NAME |
No | - | Name to use as email sender |
PAT
: GitHub Personal Access TokenGIT_USER_EMAIL
: Email for Git operationsWRAPPID_REGISTRY_TOKEN
: Token for Wrappid npm registry access
EMAIL_SERVER_ADDRESS
: SMTP server addressEMAIL_SERVER_PORT
: SMTP server portEMAIL_USER_ID
: SMTP user IDEMAIL_USER_PASSWORD
: SMTP user passwordEMAIL_TO
: Recipient email address(es)
EMAIL_CC
: CC email address(es)EMAIL_BCC
: BCC email address(es)
- Verifies if a tag exists
- Checks if a release already exists
- Outputs:
tag-version
: Version tag to userelease-exist
: Whether release exists
- Runs only if release doesn't exist
- Sets up Node.js environment
- Builds the package
- Creates npm package using
npm pack
- Creates GitHub release with artifacts:
- NPM package (.tgz)
- Release notes
- Uploads release assets
Two separate email notification jobs are included:
call-send-email-released
: Sends success notification when release is createdcall-send-email-failure
: Sends failure notification if the workflow fails
The workflow creates and uploads these artifacts:
{package-name}-{version}.tgz
: NPM packageRELEASE_NOTES.md
: Auto-generated release notes
- Node.js project with package.json
- GitHub repository with proper permissions
- NPM registry access configured
- Required secrets configured
- SMTP server access (if email notifications enabled)
- Runs on: Ubuntu latest
- Node.js version: 16
- Required permissions: write-all
- NPM Registry: GitHub Package Registry (npm.pkg.github.com)
-
Project setup:
- Installs dependencies (excluding dev dependencies)
- Uses npm cache for faster installations
-
Build steps:
- Runs the project's build script
- Creates distribution package
- Generates package archive
- Separate build and artifact creation into different jobs
- Add support for different registry deployments
- Implement package version validation
- Add package testing before release
- The workflow automatically falls back to the latest tag if no tag name is provided
- Release creation is skipped if a release already exists for the tag
- Package version is extracted from package.json
- Build artifacts are created in the dist directory
-
Common Issues:
-
Build failures
- Check build script configuration
- Verify dependencies are installed correctly
- Review Node.js version compatibility
-
Release creation failures
- Verify PAT permissions
- Check if version tag already exists
- Ensure package.json version is correct
-
Package publishing issues
- Verify registry authentication
- Check package scope configuration
- Review registry permissions
-
-
Debugging Steps:
- Review workflow logs
- Check package.json configuration
- Verify secret configurations
- Test build process locally
-
Token Management:
- Use restricted PATs
- Regularly rotate credentials
- Set appropriate token expiration
-
Registry Access:
- Use scoped registry tokens
- Implement least privilege access
- Regular access review
-
Package Configuration:
- Recommended package.json settings
- Build script configuration
- Version management
-
Related Documentation:
- NPM packaging guidelines
- GitHub release documentation
- Node.js best practices