Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
package

GitHub Action

Package Version Check Action

v1.3.9

Package Version Check Action

package

Package Version Check Action

GitHub Action to check package version before publish

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Package Version Check Action

uses: technote-space/package-version-check-action@v1.3.9

Learn more about this action in technote-space/package-version-check-action

Choose a version

Package Version Check Action

CI Status codecov CodeFactor License: MIT

Read this in other languages: English, 日本語.

This is a GitHub Actions to check package version before publish npm.

Table of Contents

Screenshots

  1. Running GitHub Action

    Running

  2. Updated version of package.json and commit (if branch is not protected)

    Updated

Installation

Used 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@v1
        with:
          fetch-depth: 3

      # Use this GitHub Action
      - name: Check package version
        uses: technote-space/package-version-check-action@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH_PREFIX: release/

Used 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@master
        with:
          fetch-depth: 3

      # Use this GitHub Action
      - name: Check package version
        uses: technote-space/package-version-check-action@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Install Package dependencies
        run: yarn install
      - name: Build
        run: yarn build
      - name: Publish
        uses: actions/npm@master
        env:
          NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
        with:
          args: publish

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/'

Action event details

Target events

eventName: action condition
push: * condition1
release: published condition1
release: rerequested condition1
created: * condition2

Conditions

condition1

  • tags
    • semantic versioning tag (e.g. v1.2.3)
  • branches
    • ${BRANCH_PREFIX}${tag}
      • tag: semantic versioning tag (e.g. v1.2.3)
      • e.g. branch: release/v1.2.3

condition2

  • tags
    • semantic versioning tag (e.g. v1.2.3)

Motivation

If you forget to update the package.json version, publishing the npm package will fail.

Failed

If you are invoking an action by pushing a tag, you have to do following steps again.

  1. Delete pushed tag
  2. Update package.json version
  3. Commit and tag again
  4. 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.

Not commit

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.

GITHUB_TOKEN

This can be a problem if you have branch protection configured.

If you want to trigger actions, use a personal access token instead.

  1. Generate a personal access token with the public_repo or repo scope.
    (repo is required for private repositories).
  2. Save as ACCESS_TOKEN
  3. Use ACCESS_TOKEN instead of GITHUB_TOKEN.
    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@v1
            with:
              fetch-depth: 3
    
          # Use this GitHub Action
          - name: Check package version
            uses: technote-space/package-version-check-action@v1
            with:
              # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
              BRANCH_PREFIX: release/

ACCESS_TOKEN

Tags

Tag name format must be Semantic Versioning.

Sample repositories using this Action

Author

GitHub (Technote)
Blog