| 1 | Set-StrictMode -Version Latest |
| 2 | |
| 3 | function Get-Current-Commit-Hash() |
| 4 | { |
| 5 | return ([string](git log -1 --pretty=%h)).Trim() |
| 6 | } |
| 7 | |
| 8 | function Get-VersionInfo |
| 9 | { |
| 10 | [CmdletBinding()] |
| 11 | param([Parameter(Mandatory = $true)]$Nightly) |
| 12 | |
| 13 | $ErrorActionPreference = "Stop" |
| 14 | |
| 15 | if ($Nightly) |
| 16 | { |
| 17 | $suffix = 'nightly' |
| 18 | } |
| 19 | else |
| 20 | { |
| 21 | $suffix = 'build' |
| 22 | } |
| 23 | |
| 24 | $output = git.exe describe --tags --match *.*.* --abbrev=1 |
| 25 | if ($LastExitCode -ne 0) |
| 26 | { |
| 27 | throw "git describe exited with error status: $LastExitCode. Make sure the main branch and tags are available." |
| 28 | } |
| 29 | |
| 30 | $versionInfo = $output.split('-') |
| 31 | if ($versionInfo.Length -lt 1) |
| 32 | { |
| 33 | throw "Unexpected output from git describe: $output" |
| 34 | } |
| 35 | |
| 36 | $version = $versionInfo[0] |
| 37 | if ($versionInfo.Length -lt 2) |
| 38 | { |
| 39 | $revision = 0 # This path is taken when the commit is directly on a tag |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | $revision = $versionInfo[1] |
| 44 | } |
| 45 | |
| 46 | $result = @{ |
| 47 | 'MsixVersion' = "$version.$revision" |
| 48 | 'NugetVersion' = "$version-$suffix{0:d3}" -f $revision |
| 49 | } |
| 50 | |
| 51 | return $result |
| 52 | } |