This GitHub Action automates the release process for Node.js projects, similar to the Maven Release Plugin for Java projects.
- Automatically reads current version from package.json
- Creates and pushes Git tags
- Creates GitHub releases
- Updates package.json with the next version
- Supports semantic versioning (major, minor, patch)
- Defaults to minor version increments
- Uses built-in GitHub Actions authentication
This action uses the GITHUB_TOKEN
that is automatically provided by GitHub Actions. You don't need to create or manage any Personal Access Tokens (PAT). The GITHUB_TOKEN
is:
- Automatically created for each workflow run
- Scoped to the current repository
- Automatically expires after the workflow completes
- Requires explicit permissions configuration in your workflow
Add the following to your GitHub workflow (e.g., .github/workflows/release.yml
):
name: Release
on:
workflow_dispatch:
inputs:
release-type:
description: 'Release type (major, minor, patch)'
required: false
default: 'minor'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write # Required for creating releases and tags
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for git history
- name: Create Release
uses: your-username/nodejs-release-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
release-type: ${{ github.event.inputs.release-type }}
The action requires the following permissions to function:
contents: write
- For creating tags, releases, and updating files
You can configure these permissions in two ways:
- In the workflow file (recommended):
jobs:
release:
permissions:
contents: write
- In repository settings:
- Go to Settings > Actions > General
- Scroll to "Workflow permissions"
- Select "Read and write permissions"
Input | Description | Required | Default | Notes |
---|---|---|---|---|
github-token | GitHub token for authentication | Yes | N/A | Use ${{ secrets.GITHUB_TOKEN }} |
release-type | Type of release (major, minor, patch) | No | minor | Determines version increment |
When executed, the action will:
- Verify repository permissions
- Read the current version from package.json
- Calculate the new version based on release-type
- Create and push a new git tag
- Create a GitHub release
- Update package.json with the new version
- Commit and push the changes
The action will fail if:
- Working directory is not clean
- Required permissions are not configured
- Invalid release type is specified
- Unable to push tags or create release
- package.json is not found or invalid
- name: Create Release
uses: your-username/nodejs-release-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create Major Release
uses: your-username/nodejs-release-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
release-type: major
To contribute to this action:
- Clone the repository
- Install dependencies:
npm install
- Make your changes
- Run tests:
npm test
- Submit a pull request
MIT
- The action requires a clean working directory
- Commits will be made using the GitHub Actions bot
- All git operations are performed with the provided GITHUB_TOKEN
- Action runs in a Docker container for consistency