Skip to content

Commit

Permalink
Implemented assembly versioning with optional Git SHA
Browse files Browse the repository at this point in the history
closes #9
  • Loading branch information
Yuriy committed Mar 10, 2020
1 parent 4787584 commit cb7e411
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--Elastic Stack version for this release -->
<PropertyGroup>
<StackVersion>8.0.0</StackVersion>
</PropertyGroup>

<PropertyGroup>
<Company>Elastic</Company>
<Description>Elastic MSI package build system</Description>
<Copyright>(c) $([System.DateTime]::Now.ToString(yyyy)) Elastic</Copyright>
<FileVersion>$(StackVersion)</FileVersion>
<AssemblyVersion>$(StackVersion)</AssemblyVersion>
<InformationalVersion>$(StackVersion)</InformationalVersion>

<!-- Add commit hash if we can -->
<_GitHEADFilename>HEAD</_GitHEADFilename>
<_GitSHALength>7</_GitSHALength>
<_GitDir Condition="'$(_GitHEADFilename)' != '' And $(_GitSHALength) &gt; 0 And $(_GitSHALength) &lt; 40 And Exists('$(MSBuildThisFileDirectory).git')">$(MSBuildThisFileDirectory).git</_GitDir>
<_GitHEAD Condition="'$(_GitDir)' != '' And Exists('$(_GitDir)\$(_GitHEADFilename)')">$([System.IO.File]::ReadAllText('$(_GitDir)\$(_GitHEADFilename)').Trim())</_GitHEAD>
<_GitSHA Condition="'$(_GitHEAD)' != '' And '$(_GitHEAD.StartsWith(ref:))' == 'true'">$([System.IO.File]::ReadAllText('$(_GitDir)\$(_GitHEAD.Substring(5))').Substring(0,$(_GitSHALength)))</_GitSHA>
<_GitSHA Condition="'$(_GitHEAD)' != '' And '$(_GitHEAD.StartsWith(ref:))' == 'false'">$(_GitHEAD.Substring(0,$(_GitSHALength)))</_GitSHA>
<InformationalVersion Condition="'$(_GitSHA)' != ''">$(InformationalVersion)-$(_GitSHA)</InformationalVersion>
</PropertyGroup>
</Project>
12 changes: 9 additions & 3 deletions src/build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using CommandLine;
using CommandLine.Text;
Expand All @@ -11,6 +12,11 @@ namespace ElastiBuild
{
static class Program
{
static readonly string ProductVersion = typeof(Program)
.Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;

static async Task Main(string[] args)
{
var commands = typeof(Program)
Expand Down Expand Up @@ -47,8 +53,8 @@ static Task HandleErrorsAndShowHelp(ParserResult<object> parserResult, Type[] co

var result = parser.ParseArguments<GlobalOptions>(string.Empty.Split(' '));

HelpText htGlobals = new HelpText(
$"ElastiBuild v8.0.0",
var htGlobals = new HelpText(
"ElastiBuild " + ProductVersion,
$"Copyright (c) {DateTime.Now.Year}, https://elastic.co")
{
AdditionalNewLineAfterOption = false,
Expand All @@ -65,7 +71,7 @@ static Task HandleErrorsAndShowHelp(ParserResult<object> parserResult, Type[] co

if (isGlobalHelp)
{
var htVerbs = new HelpText()
var htVerbs = new HelpText
{
AddDashesToOption = false,
AutoHelp = false,
Expand Down

0 comments on commit cb7e411

Please sign in to comment.