Sets project version to YYYY.MM.DD.BUILD where:
YYYY.MM.DDis the current action runner dateBUILDis Github run number (unique number incremented on every build)
Resulting project version is unique but also meaningful since it also contains the date when the project was build.
Example of resulting version: 2021.10.17.123.
This format of versioning is better suited for projects with continious delivery model of development: when releases are frequient and with relatively small incremental changes in between. For this type of projects semver does not make much sense while the actual date in version format does.
project-file: (optional) path to the file which contains the version of the project
Defaults to:package.jsonversion-stub: (optional) stub version value
Defaults to:'0.0.0'leading-zeros: (optional) pad month and day with0for a single-digit values
Defaults totruee.g2021/06/07current date by default results in2021.06.07.123version and otherwise in2021.6.7.123time-zone: (optional) time zone to be used to determine the current date/time
If not set the action runner current date/time is used
project-version: is set to the resulting version and can be referenced in subsequent steps viasteps.step_id.outputs.project-versionVERSION: (environment variable) is also set to resulting project version, is set for subsequent steps and has shorter syntax${{ env.VERSION }}
In your project set version to some predefined stub version value. This value should probably still be a valid version number if you intend to compile your project outside Github action. For example in Node project package.json by default is expected to contain stub version 0.0.0:
{
"name": "example",
"version": "0.0.0"
}Add EduardSergeev/project-version-action@v1 to your CI script after actions/checkout@v2 step:
- name: Set project version for Node project
uses: EduardSergeev/project-version-action@mainIf a different from package.json file is used or a different from 0.0.0 stub version value was specified set project-file and version-stub input parameters accordingly. For example for .NET project it could be:
- name: Set project version for .NET project
uses: EduardSergeev/project-version-action@main
with:
version-file: example.csproj
version-stub: '65534.65534.65534.65534'By default this action pads single-digit "month" and "day" bits of the resulting version with 0 but since some build systems, like Cabal does not allow leading zeros in version parts use leading-zeroes: false to prevent the padding:
- name: Set project version for Cabal project
uses: EduardSergeev/project-version-action@main
with:
version-file: example.cabal
leading-zeros: falseSince this action uses action runner's local date/time, which is by default is UTC, the resulting version might be one day before or after your local date, depending on your local time zone. To avoid this situation you can either set runner's time zone to your local time zone, e.g.:
jobs:
build:
runs-on: ubuntu-latest
env:
TZ: Australia/Sydneyor set input parameter time-zone to your local time zone, e.g.:
- name: Set project version for Node project
uses: EduardSergeev/project-version-action@main
with:
time-zone: Australia/SydneyThe former will change time zone for entire action job while the latter will use it only to calculate the version without changing it for the runner.