2

When using gitversion (the latest, v6.*) in a github action, is the SemVer supposed to increase by 1 at the end each commit? I thought it was from what I was reading, but I never see it happen. for example, here's the gitversion output for a branch (left out some of the values):

{
  "BranchName": "ActionsFeaturesBranchTestV2",
  "BuildMetaData": 3,
  "CommitsSinceVersionSource": 3,
  "FullSemVer": "1.0.0-ActionsFeaturesBranchTestV2.1+3",
  "PreReleaseLabel": "ActionsFeaturesBranchTestV2",
  "PreReleaseNumber": 1,
  "SemVer": "1.0.0-ActionsFeaturesBranchTestV2.1",
  "WeightedPreReleaseNumber": 1
}

The SemVer has the .1 at the end. When I do another commit (or rather push, the action only runs on a push), I expected the .1 to go to .2 but it never happens. The BuildMetaData and CommitsSinceVersionSource increment fine. Here's after another commit/push:

{
  "BranchName": "ActionsFeaturesBranchTestV2",
  "BuildMetaData": 4,
  "CommitsSinceVersionSource": 4,
  "FullSemVer": "1.0.0-ActionsFeaturesBranchTestV2.1+4",
  "PreReleaseLabel": "ActionsFeaturesBranchTestV2",
  "PreReleaseNumber": 1,
  "SemVer": "1.0.0-ActionsFeaturesBranchTestV2.1",
  "WeightedPreReleaseNumber": 1
}

I believe my branch falls under the "unknown" section of the gitversion.yml config. The default config per gitversion's website for this is:

  unknown:
    mode: ManualDeployment
    label: '{BranchName}'
    increment: Inherit
    prevent-increment:
      when-current-commit-tagged: false
    track-merge-message: false
    regex: (?<BranchName>.+)
    source-branches:
    - main
    - release
    - feature
    - pull-request
    is-source-branch-for: []
    is-main-branch: false

Is there a certain setting I have to use? Or am I misunderstanding what that .1 is used for? The reason I need that number is that each push needs to produce a unique build version for a nuget package. I know I could just combine a few of the outputs to get what I want, but I'd like to understand why isn't working as is.

1 Answer 1

0

I think you configured too much, which might prevent the version number to be incremented. Reduce your setup to see the default behaviour, then add options as you need them. I have had good success with the below code - a snippet from the Github Actions workflow. You may skip the second step - it helped me to use the values in dependent jobs.

    - name: Determine Version
      id: gitversion
      uses: gittools/actions/gitversion/execute@v0
      
    - id: output1
      run: |
        set -x
        printenv | grep GitVersion_ | sort
        echo "GITVERSION_SEMVER=${GitVersion_SemVer}" >> "$GITHUB_OUTPUT"
        echo "GITVERSION_ASSEMBLYSEMVER=${GitVersion_AssemblySemVer}" >> "$GITHUB_OUTPUT"
        echo "GITVERSION_MAJORMINORPATCH=${GitVersion_MajorMinorPatch}" >> "$GITHUB_OUTPUT"
        echo "GITVERSION_MAJOR=${GitVersion_Major}" >> "$GITHUB_OUTPUT"
        echo "GITVERSION_MINOR=${GitVersion_Minor}" >> "$GITHUB_OUTPUT"
        echo "GITVERSION_PATCH=${GitVersion_Patch}" >> "$GITHUB_OUTPUT"
        echo "DEBIAN_PKGVERSION=${GitVersion_Major}.${GitVersion_Minor}-${GitVersion_Patch}" >> "$GITHUB_OUTPUT"
        if [ "${GitVersion_Major}" == "0" ]
        then
          echo "MACOS_MAJORMINORPATCH=1.${GitVersion_Minor}.${GitVersion_Patch}" >> "$GITHUB_OUTPUT"
        else
          echo "MACOS_MAJORMINORPATCH=${GitVersion_MajorMinorPatch}" >> "$GITHUB_OUTPUT"
        fi
        if [ "$GITHUB_REF_NAME" != "master" ]
        then
          echo "FLAVOR=_${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
          echo "FLAVOR2=-${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
        fi
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.