4tecture/BuildVersioning

Ambiguous `VersionCode` for prereleases

Closed this issue · 4 comments

Hi,

first of all I gotta thank you for this extension. It really helps versioning by a lot!

While building a CI/CD Pipeline for a android application, I noticed the undocumented BuildVersion.VersionCode variable which is exactly what I'm looking for.

Unfortunately, the version code is only raised by updating the patch version at least.
Is there a configuration value to make the version code depending on pre-releases?

Example:
VersionCode for 1.0.0-alpha0002 should be higher than the version code for release 1.0.0-alpha0001.

Thanks in advance.

Configuration

My versioning template looks like this:

steps:
- task: UseDotNet@2
  displayName: 'Install Dependencies'
  inputs:
    packageType: 'sdk'
    version: '5.x'

- task: BuildVersioning@0
  name: BuildVersioning
  displayName: 'Build Versioning'
  inputs:
    versionSource: 'gitversion'
    doInstallGitVersion: true
    GitVersionInstallerVersion: '5.6.10'
    doUseLatestGitVersionInstallerVersion: false
    GitVersionToolInstallation: 'global'
    paramAssemblyVersion: '7'
    paramAssemblyFileVersion: '7'
    paramAssemblyInformationalVersion: '6'
    paramOverwriteFourthDigitWithBuildCounter: true
    paramVersionCode: '2'
    doAssemblyInfoAppendSuffix: false
    doConvertAssemblyInfoToLowerCase: false
    buildNumberVersionFormat: '3'
    buildNumberAction: 'replace'
    doReplaceAssemblyInfo: false
    doReplaceNuspec: false
    doReplaceNpm: false
    doReplaceDotNetCore: false
    filePatternDotNetCore: |
      **\*.csproj
      **\*.props
    paramDotNetCoreVersionType: '3'
    doReplaceAndroid: false
    doReplaceiOS: false
    doReplaceCustom: false
    doShowWarningsForUnmatchedRegex: false
    excludeFilePattern: |
      !**/bin/**
      !**/obj/**
      !**/node_modules/**

I am just using the buildversioning to calculate the required values. I'm updating the AndroidManifest.xml manually:

  - task: android-manifest-version@1
    displayName: Update Manifest (Version)
    inputs:
      sourcePath: 'MyPath/AndroidManifest.xml'
      versionCodeOption: 'buildid'
      versionCode: '$(BuildVersion.VersionCode)'
      versionName: '$(BuildVersion.VersionInfo)'
      printFile: true

Hi @NecatiMeral

Thanks for your feedback. Yes, the version code is exactly what you need for android (let me check the documentation again, was not aware that this option is missing in the documentation). It is not that easy to achieve what you would like to have. The problem is that this version is only going forward, so you can't deploy something else with a lower version. So taking the feature branch commits into that calculation, could result in another feature branch which is newer to have a lower version code (if they are based on the same main version). Could you elaborate how you would use those different version codes?

Currently we are supporting to modes to calculate the version code. This is the parameter "paramVersionCode":

  • code = Number(this.versionTokens[0]) * 10000000 + Number(this.versionTokens[1]) * 100000 + Number(this.versionTokens[2]) * 100 + Number(this.versionTokens[3]) * 1;
  • code = this.convertSemVerToInt32(`${this.versionTokens[0]}.${this.versionTokens[1]}.${this.versionTokens[2]}`);

Reserving some space for the commit count will again increase the size of the code generated. I am open to add a third option for the calculation, but currently I don't have a good solution at hand. Do you have any suggestions?

--Marc

Just thinking out loud: What you could try is to set paramOverwriteFourthDigitWithBuildCounter to true and define a paramBuildCounterKey which is the SemVer. This would then generate the patch version (4th digit) to be increased for every build as long as the first three version parts stay the same. If you then set the paramVersionCode to '1', you will get a version code which is always increased for every build.

Would that solve your problem? Could you try it?

Hi @marc-mueller,

thank you for the information and tips.

Our use-case is the following scenario:
We're deploying an android app only for pushes into master or develop branches. Deployment of feature branches isn't planned yet.
We assign different package ids (including display names, activity names, you name it) for each branch (myapp for master; myapp_develop for develop), so a higher versionCode in another branch wouldn't break updates for the master or develop branches since they are considered as a different application.

I'm currently on time constraints but definitely will test some approaches by this week and report back.

Still tracking this; currently not working in the mobile area.
Will bookmark this issue and open another issue if required.