ctaggart / SourceLink

Source Code On Demand
MIT License
356 stars 55 forks source link

may be create SourceLink.VersionFromTag #378

Closed ctaggart closed 5 years ago

ctaggart commented 5 years ago

I'm tempted to make a executable that outputs a version for use in build environments that I use: AppVeyor, TeamCity, TravisCI, BitRise, Azure Pipelines. I've implemented this logic multiple times in various types of scripts. It boils down to this:

https://github.com/ctaggart/SourceLink/blob/master/build.ps1#L1-L16

$version = '3.0.0' # the version under development, update after a release
$versionSuffix = '-build.0' # manually incremented for local builds

function isVersionTag($tag){
    $v = New-Object Version
    [Version]::TryParse($tag, [ref]$v)
}

if ($env:appveyor){
    $versionSuffix = '-build.' + $env:appveyor_build_number
    if ($env:appveyor_repo_tag -eq 'true' -and (isVersionTag($env:appveyor_repo_tag_name))){
        $version = $env:appveyor_repo_tag_name
        $versionSuffix = ''
    }
    Update-AppveyorBuild -Version "$version$versionSuffix"
}

I like how @panesofglass modified what I did to pull the version from the project file. https://github.com/xyncro/chiron/blob/master/build.ps1#L1-L3

[xml]$doc = Get-Content .\src\Directory.Build.props
$version = $doc.Project.PropertyGroup.VersionPrefix # the version under development, update after a release
$versionSuffix = '-build.0' # manually incremented for local builds

Question:

Evaluate existing alternatives:

AArnott commented 5 years ago

I'm not sure why SourceLink would be where you'd turn to address a versioning requirement. Isn't that a very different use case than PDB-related concerns that SourceLink addresses?

ctaggart commented 5 years ago

@AArnott Yes, I could create a whole different project. In the past, I've used this as an umbrella project for utilities. Not sure yet what I prefer. Ideally, a tool like Nerbank.GitVersioning would already provide a close enough solution that I could live with.

AArnott commented 5 years ago

So which requirements do you need that GitVersion or NB.GV do not deliver?

Your desire to get version info from tags suggest GitVersion may be a better fit, since NB.GV always gets it from a version.json file. But from what I hear, GitVersion has some significant limitations that may be important to you.

ctaggart commented 5 years ago

Regarding Version, VersionPrefix, & VersionSuffix, here is how the .NET SDK handles it: https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DefaultAssemblyInfo.targets

  <PropertyGroup Condition=" '$(Version)' == '' ">
    <VersionPrefix Condition=" '$(VersionPrefix)' == '' ">1.0.0</VersionPrefix>
    <Version Condition=" '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</Version>
    <Version Condition=" '$(Version)' == '' ">$(VersionPrefix)</Version>
</PropertyGroup>
ctaggart commented 5 years ago

I'm not sure if PreReleaseVersionLabel is replacing VersionSuffix, but it is being used in some Microsoft projects https://github.com/dotnet/sourcelink/pull/191/files#r225758664

ctaggart commented 5 years ago

I'm most interested in using Netbank.GitVersioning by @AArnott if I can get https://github.com/AArnott/Nerdbank.GitVersioning/pull/304 merged.

AArnott commented 5 years ago

gah! I need to review that. Sorry for the delay.

ctaggart commented 5 years ago

I've been using & contributing to GitVersioning. http://blog.ctaggart.com/2019/04/automate-your-net-versioning-with.html