Skip to content
check-circle

GitHub Action

npm-versioning-action

v1 Latest version

npm-versioning-action

check-circle

npm-versioning-action

Generate version number base on Git branch

Installation

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

              

- name: npm-versioning-action

uses: pengyanb/npm-versioning-action@v1

Learn more about this action in pengyanb/npm-versioning-action

Choose a version

npm versioning action

Github action package that generates versioning string base on the npm version value, branch name and commit number.

WARNING: when use with actions/checkout@v2, remember to fetch all history by passing the fetch-depth option

- uses: actions/checkout@v2
  with:
    fetch-depth: 0

Inputs:

  • release-branch : string, default value master.

  • package-json-path : string, path to package.json file, default value ./package.json

  • update-version : boolean, flag to indicate wheather to update package.json file, default value true

outputs:

  • version, the version string generated

  • tag: latest for release branch, beta for other branches

For release branch (default master), version string is generated based on the semantic version specified in package.json file.

For other branches, version string is generated using ${package.json semantic version}-${branchName}.${commitCount} format.

Basic usage:

- name: npm versioning
  id: npmVersioning
  uses: pengyanb/npm-versioning-action@v1

- name: dummy versioning usage
  run: echo "Generated version is \${{ steps.npmVersioning.outputs.version}}"

Specify a different release branch:

- name: npm versioning
  id: npmVersioning
  uses: pengyanb/npm-versioning-action@v1
  with:
    release-branch: "develop"

- name: dummy versioning usage
  run: echo "Generated version is \${{ steps.npmVersioning.outputs.version}}"

Set multiple release branches:

- name: npm versioning
  id: npmVersioning
  uses: pengyanb/npm-versioning-action@v1
  with:
    release-branch: "develop,master"

- name: dummy versioning usage
  run: echo "Generated version is \${{ steps.npmVersioning.outputs.version}}"

use with npm publish:

- name: npm versioning
  id: npmVersioning
  uses: pengyanb/npm-versioning-action@v1
  with:
    release-branch: "master" 
    package-json-path: "./dist/package.json"
    update-version: true

- name: npm publish
  run: run: npm publish ./dist --tag ${{ steps.npmVersioning.outputs.tag }} --dry-run true
  env:
    NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}