package-version-check-action
package-version-check-action copied to clipboard
GitHub Actions to check package version before publish
Package Version Check Action
Read this in other languages: English, 日本語.
This is a GitHub Actions to check package version before publish npm.
Table of Contents
Details
- Screenshots
- Usage
- Use when push
- Use in the release process
- Options
- BRANCH_PREFIX
- COMMIT_DISABLED
- COMMIT_MESSAGE
- PACKAGE_NAME
- PACKAGE_DIR
- TEST_TAG_PREFIX
- NEXT_VERSION
- Action event details
- Target events
- Conditions
- Motivation
- Addition
- Commit
- Tags
- Example repositories using this Action
- Author
Screenshots
-
Running
GitHub Action
-
Updated version of package.json and commit (if branch is not protected)

Usage
Use when push
e.g. .github/workflows/check_version.yml
on: push
name: Check package version
jobs:
checkVersion:
name: Check package version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Use this GitHub Action
- name: Check package version
uses: technote-space/package-version-check-action@v1
with:
BRANCH_PREFIX: release/
Use in the release process
e.g. .github/workflows/release.yml
on:
push:
tags:
- 'v*'
name: Publish Package
jobs:
release:
name: Publish Package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Use this GitHub Action
- name: Check package version
uses: technote-space/package-version-check-action@v1
with:
COMMIT_DISABLED: 1
- name: Install Package dependencies
run: yarn install
- name: Build
run: yarn build
- name: Publish
run: |
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
npm publish
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
More details of target event
Options
BRANCH_PREFIX
Branch name prefix.
default: ''
e.g. release/
COMMIT_DISABLED
Whether commit is disabled.
default: ''
COMMIT_MESSAGE
Commit message of update package version commit.
default: 'feat: update package version'
PACKAGE_NAME
Package file name.
default: 'package.json'
PACKAGE_DIR
Package directory.
default: ''
TEST_TAG_PREFIX
Prefix for test tag.
default: ''
e.g. 'test/'
NEXT_VERSION
Specify next version.
default: ''
e.g. 'v1.2.3'
Action event details
Target events
| eventName: action | condition |
|---|---|
| push: * | condition1 |
| release: published | condition1 |
| pull_request, pull_request_target: opened, reopened, synchronize | condition2 |
| created: * | condition3 |
Conditions
condition1
- tags
- semantic versioning tag (e.g.
v1.2.3)
- semantic versioning tag (e.g.
- branches
${BRANCH_PREFIX}${tag}- tag: semantic versioning tag (e.g.
v1.2.3) - e.g. branch:
release/v1.2.3
- tag: semantic versioning tag (e.g.
condition2
- branches
${BRANCH_PREFIX}${tag}- tag: semantic versioning tag (e.g.
v1.2.3) - e.g. branch:
release/v1.2.3
- tag: semantic versioning tag (e.g.
condition3
- tags
- semantic versioning tag (e.g.
v1.2.3)
- semantic versioning tag (e.g.
Motivation
If you forget to update the package.json version, publishing the npm package will fail.

If you are invoking an action by pushing a tag, you have to do following steps again.
- Delete pushed tag
- Update package.json version
- Commit and tag again
- Push
This is very troublesome.
This GitHub Action updates the version in package.json based on the tag name automatically.
So you don't have to worry about the version in package.json.
This action also commits the change if the branch is not protected.
If the branch is protected, this action just update the version in package.json.

Addition
Commit
Commit is valid when pushing to default branch with tag or branch starting with ${BRANCH_PREFIX}.
The GITHUB_TOKEN that is provided as a part of GitHub Actions doesn't have authorization to create any successive events.
So it won't spawn actions which triggered by push.

This can be a problem if you have branch protection configured.
If you want to trigger actions, use a personal access token instead.
- Generate a personal access token with the public_repo or repo scope.
(repo is required for private repositories). - Save as ACCESS_TOKEN
- Add input to use
ACCESS_TOKENinstead ofGITHUB_TOKEN.
e.g..github/workflows/check_version.ymlon: push name: Check package version jobs: checkVersion: name: Check package version runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 # Use this GitHub Action - name: Check package version uses: technote-space/package-version-check-action@v1 with: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} BRANCH_PREFIX: release/

Tags
Tag name format must be Semantic Versioning.
Example repositories using this Action
- GitHub Action Helper
- GitHub Action Config Helper
- GitHub Action Test Helper
- Filter GitHub Action
- jQuery Marker Animation
- Gutenberg Utils
- Register Grouped Format Type