Skip to content

polygon-software/npm-version-date

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

NPM-Version-Date GitHub Action

Github action that sets the NPM package version based on a date schema.

run npm-version pipeline

Examples:

Schema Output Description
V.yyyy.MM.P 3.2021.05.1 Version.Year.Month.Patch
V.yyMM.P 3.2105.1 Version.YearhMonth.Patch
yyyy.MM.P 2021.05.1 Year.Month.Patch
V.yy.QQ.P 2021.05.1 Version.Year.Quarter.Patch

Each part of the version string (seperated by a dot) can be one of the following:

  • V: Major Version Number, passed as input to the github action
  • P: Patch Version Number, read from the projects package.json and - optionally - automatically incremented.
  • DateFormat: A string that describes a date format.

Important: You can not mix V,P and DateFormat. The following examples are invalid schemas:

  • VYY.MM.P -> V-and-YY can not occur in the same part and must be seperated by dots. Valid: V.YY.MM.P
  • yyyy.MM.VP -> V-and-P can not occur in the same part and must be separated by dots. Valid: yyyy.MM.V.P
  • yyyy.MM.V.ddP -> dd-and-P can not occur in the same part and must be separated by dots. Valid: yyyy.MM.V.dd.P

NPM Limitations: A NPM version number should only exist of three parts: a.b.c.

How to use the NPM-Version-Date GitHub action

An example of workflow

name: run npm-version pipeline
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@master
        
      - name: 'change version'
        uses: polygon-software/npm-version-date@master
        with:
          schema: 'V.yyMM.P'
          V: '2'
          increase-patch: true

Variables

Variable Default Example Description
schema - V.yyyy.MM.P Date schema based on date-fns format.
V 1 - Major version number. Must only be provided if "V" is used within the schema.
increase-patch false - Increment patch verison "P" for the new version string.

Date-String formation options:

The Formation options follow the date-fns format..

Unit Pattern Result examples Notes
Calendar year y 44, 1, 1900, 2017 5
yy 44, 01, 00, 17 5
yyy 044, 001, 1900, 2017 5
yyyy 0044, 0001, 1900, 2017 5
yyyyy ... 3,5
Local week-numbering year Y 44, 1, 1900, 2017 5
YY 44, 01, 00, 17 5,8
YYY 044, 001, 1900, 2017 5
YYYY 0044, 0001, 1900, 2017 5,8
YYYYY ... 3,5
ISO week-numbering year R -43, 0, 1, 1900, 2017 5,7
RR -43, 00, 01, 1900, 2017 5,7
RRR -043, 000, 001, 1900, 2017 5,7
RRRR -0043, 0000, 0001, 1900, 2017 5,7
RRRRR ... 3,5,7
Extended year u -43, 0, 1, 1900, 2017 5
uu -43, 01, 1900, 2017 5
uuu -043, 001, 1900, 2017 5
uuuu -0043, 0001, 1900, 2017 5
uuuuu ... 3,5
Quarter (formatting) Q 1, 2, 3, 4
QQQQQ 1, 2, 3, 4 4
Quarter (stand-alone) q 1, 2, 3, 4
qq 01, 02, 03, 04
qqqqq 1, 2, 3, 4 4
Month (formatting) M 1, 2, ..., 12
MM 01, 02, ..., 12
Month (stand-alone) L 1, 2, ..., 12
LL 01, 02, ..., 12
Local week of year w 1, 2, ..., 53
ww 01, 02, ..., 53
ISO week of year I 1, 2, ..., 53 7
II 01, 02, ..., 53 7
Day of month d 1, 2, ..., 31
dd 01, 02, ..., 31
Day of year D 1, 2, ..., 365, 366 9
DD 01, 02, ..., 365, 366 9
DDD 001, 002, ..., 365, 366
DDDD ... 3
ISO day of week (formatting) i 1, 2, 3, ..., 7 7
ii 01, 02, ..., 07 7
Local day of week (formatting) e 2, 3, 4, ..., 1
ee 02, 03, ..., 01
Local day of week (stand-alone) c 2, 3, 4, ..., 1
cc 02, 03, ..., 01
Hour [1-12] h 1, 2, ..., 11, 12
hh 01, 02, ..., 11, 12
Hour [0-23] H 0, 1, 2, ..., 23
HH 00, 01, 02, ..., 23
Hour [0-11] K 1, 2, ..., 11, 0
KK 01, 02, ..., 11, 00
Hour [1-24] k 24, 1, 2, ..., 23
kk 24, 01, 02, ..., 23
Minute m 0, 1, ..., 59
mm 00, 01, ..., 59
Second s 0, 1, ..., 59
ss 00, 01, ..., 59
Fraction of second S 0, 1, ..., 9
SS 00, 01, ..., 99
SSS 000, 001, ..., 999
SSSS ... 3
Seconds timestamp t 512969520 7
tt ... 3,7
Milliseconds timestamp T 512969520900 7
TT ... 3,7

This project was developed in Zurich, switzerland by PolygonSoftware