Skip to content

Commit

Permalink
Fix TagSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaykul committed Nov 12, 2023
1 parent 2fd2181 commit b3ab76b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
119 changes: 60 additions & 59 deletions GitVersion.Task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,80 @@ Add-BuildTask GitVersion @{
}
}
Jobs = {
$script:GitVersionTags = @()
$script:MultiGitVersion = @{}
foreach ($Name in $PackageNames) {
$script:GitVersionTags = @(
foreach ($Name in $PackageNames) {

if ($PackageNames.Count -gt 1) {
$GitVersionMessagePrefix = ($GitVersionMessagePrefix, $Name) -join "-"
$GitVersionTagPrefix = ($Name, $GitVersionTagPrefix) -join "-"
}
if ($PackageNames.Count -gt 1) {
$GitVersionMessagePrefix = ($GitVersionMessagePrefix, $Name) -join "-"
$GitVersionTagPrefix = ($Name, $GitVersionTagPrefix) -join "-"
}

# Since we know the things we need to version, let's make *sure* that we version it:
# Write-Host git commit "--ammend" "-m" "$commitMessage`n$GitVersionMessagePrefix:patch"
# git commit --ammend -m "$commitMessage`n$GitVersionMessagePrefix:patch"
# Since we know the things we need to version, let's make *sure* that we version it:
# Write-Host git commit "--ammend" "-m" "$commitMessage`n$GitVersionMessagePrefix:patch"
# git commit --ammend -m "$commitMessage`n$GitVersionMessagePrefix:patch"

$GitVersionYaml = if (Test-Path (Join-Path $BuildRoot GitVersion.yml)) {
Join-Path $BuildRoot GitVersion.yml
} else {
Convert-Path (Join-Path $PSScriptRoot GitVersion.yml)
}
$GitVersionYaml = if (Test-Path (Join-Path $BuildRoot GitVersion.yml)) {
Join-Path $BuildRoot GitVersion.yml
} else {
Convert-Path (Join-Path $PSScriptRoot GitVersion.yml)
}

Write-Verbose "Using GitVersion config $GitVersionYaml" -Verbose
Write-Verbose "Using GitVersion config $GitVersionYaml" -Verbose

$LogFile = Join-Path $TempRoot -ChildPath "$GitVersionTagPrefix$GitSha.log"
if (Test-Path $LogFile) {
Remove-Item $LogFile
}
$VersionFile = Join-Path $TempRoot -ChildPath "$GitVersionTagPrefix$GitSha.json"
if (Test-Path $VersionFile) {
Remove-Item $VersionFile
}
$LogFile = Join-Path $TempRoot -ChildPath "$GitVersionTagPrefix$GitSha.log"
if (Test-Path $LogFile) {
Remove-Item $LogFile
}
$VersionFile = Join-Path $TempRoot -ChildPath "$GitVersionTagPrefix$GitSha.json"
if (Test-Path $VersionFile) {
Remove-Item $VersionFile
}

# We can't splat because it's 5 copies of the same parameter, so, use line-wrapping escapes:
# Also, the no-bump-message has to stay at .* or else every commit to main will increment all components
# Write-Host dotnet gitversion -config $GitVersionYaml -output file -outputfile $VersionFile -verbosity verbose
<# -output file -outputfile $VersionFile #>
dotnet gitversion -verbosity diagnostic -config $GitVersionYaml `
-overrideconfig tag-prefix="$($GitVersionTagPrefix)" `
-overrideconfig major-version-bump-message="$($GitVersionMessagePrefix):\s*(breaking|major)" `
-overrideconfig minor-version-bump-message="$($GitVersionMessagePrefix):\s*(feature|minor)" `
-overrideconfig patch-version-bump-message="$($GitVersionMessagePrefix):\s*(fix|patch)" `
-overrideconfig no-bump-message="$($GitVersionMessagePrefix):\s*(skip|none)" > $VersionFile 2> $LogFile
# We can't splat because it's 5 copies of the same parameter, so, use line-wrapping escapes:
# Also, the no-bump-message has to stay at .* or else every commit to main will increment all components
# Write-Host dotnet gitversion -config $GitVersionYaml -output file -outputfile $VersionFile -verbosity verbose
<# -output file -outputfile $VersionFile #>
dotnet gitversion -verbosity diagnostic -config $GitVersionYaml `
-overrideconfig tag-prefix="$($GitVersionTagPrefix)" `
-overrideconfig major-version-bump-message="$($GitVersionMessagePrefix):\s*(breaking|major)" `
-overrideconfig minor-version-bump-message="$($GitVersionMessagePrefix):\s*(feature|minor)" `
-overrideconfig patch-version-bump-message="$($GitVersionMessagePrefix):\s*(fix|patch)" `
-overrideconfig no-bump-message="$($GitVersionMessagePrefix):\s*(skip|none)" > $VersionFile 2> $LogFile

if (Test-Path $LogFile) {
Write-Host $PSStyle.Formatting.Error ((Get-Content $LogFile) -join "`n") $PSStyle.Reset
}
if (Test-Path $LogFile) {
Write-Host $PSStyle.Formatting.Error ((Get-Content $LogFile) -join "`n") $PSStyle.Reset
}

if (!(Test-Path $VersionFile)) {
throw "GitVersion failed to produce a version file or a log file"
} else {
Get-Content $VersionFile | Out-Host
$GitVersion = Get-Content $VersionFile | ConvertFrom-Json
}
if (!(Test-Path $VersionFile)) {
throw "GitVersion failed to produce a version file or a log file"
} else {
$GitVersion = Get-Content $VersionFile | ConvertFrom-Json |
Add-Member ScriptProperty Tag -Value { $GitVersionTagPrefix + $this.SemVer } -PassThru
$GitVersion | Format-List | Out-Host
}

Set-Variable "GitVersion.$Name" $GitVersion -Scope Script
$MultiGitVersion.$Name = $GitVersion
Set-Variable "GitVersion.$Name" $GitVersion -Scope Script
$MultiGitVersion.$Name = $GitVersion

# Output for Azure DevOps
if ($ENV:SYSTEM_COLLECTIONURI) {
foreach ($envar in $GitVersion.PSObject.Properties) {
$EnvVarName = if ($Name) {
@($Name, $Envar.Name) -join "."
} else {
$Envar.Name
# Output for Azure DevOps
if ($ENV:SYSTEM_COLLECTIONURI) {
foreach ($envar in $GitVersion.PSObject.Properties) {
$EnvVarName = if ($Name) {
@($Name, $Envar.Name) -join "."
} else {
$Envar.Name
}
Write-Host "INFO [task.setvariable variable=$EnvVarName;isOutput=true]$($envar.Value)"
Write-Host "##vso[task.setvariable variable=$EnvVarName;isOutput=true]$($envar.Value)"
}
Write-Host "INFO [task.setvariable variable=$EnvVarName;isOutput=true]$($envar.Value)"
Write-Host "##vso[task.setvariable variable=$EnvVarName;isOutput=true]$($envar.Value)"
} else {
Write-Host "GitVersion: $($GitVersion.InformationalVersion)"
}
} else {
Write-Host "GitVersion: $($GitVersion.InformationalVersion)"
# Output the expected tag
$GitVersionTagPrefix + $GitVersion.SemVer
}
# Output the expected tag
$GitVersionTagPrefix + $GitVersion.SemVer
}

)
$MultiGitVersion | ConvertTo-Json | Set-Content $VersionFile

# Output for Azure DevOps
Expand Down
7 changes: 5 additions & 2 deletions TagSource.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Add-BuildTask TagSource @{
If = { $script:BranchName -match "main|master" }
Jobs = "GitVersion", {
git tag ("v" + $script:GitVersion.MajorMinorPatch) -m "Release $($script:GitVersion.InformationalVersion)"
git push origin --tags
foreach ($Name in $PackageNames) {
$Version = (Get-Variable "GitVersion.$($Name.ToLower())" -ValueOnly)
git tag $Version.Tag -m "Release $($Version.InformationalVersion)"
git push origin --tags
}
}
}

0 comments on commit b3ab76b

Please sign in to comment.