PaulHatch / semantic-version

A GitHub Action to generate semantic version from a git repository's commit history.
MIT License
347 stars 63 forks source link

zero-pad increment #128

Closed astldev closed 11 months ago

astldev commented 1 year ago

How can I zero-pad the increment?

PaulHatch commented 1 year ago

It is not possible at the moment to do this type of formatting in the action. At the moment you can specify a format by setting the version_format parameter, which defaults to "${major}.${minor}.${patch}-prerelease${increment}". Internally this is implemented with a simple string replace.

I've had mixed feelings about this, the format impacts the output only but sometimes people have mistakenly believed it was used to set the input format.

Anyway, all the values are available as outputs, so you can just format this in a subsequent something like this:

...
- name: Format Version
  id: format-version
  run: echo "::set-output name=version::$MAJOR.$MINOR.$PATCH-$(printf '%03d' $INCREMENT)"
  env:
    MAJOR: {{ steps.version.outputs.major }}
    MINOR: {{ steps.version.outputs.minor }}
    PATCH: {{ steps.version.outputs.patch }}
    INCREMENT: {{ steps.version.outputs.increment }}