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

(cherry picked from commit cb7e411)
  • Loading branch information
Yuriy committed Mar 10, 2020
1 parent d644c2f commit bfe70d1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 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>
27 changes: 11 additions & 16 deletions src/build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using CommandLine;
using CommandLine.Text;
using Elastic.Installer;
using ElastiBuild.Commands;
using ElastiBuild.Infra;
using ElastiBuild.Options;

namespace ElastiBuild
{
partial class Program
static class Program
{
static async Task Main(string[] args)
{
await new Program().Run(args);
}
static readonly string ProductVersion = typeof(Program)
.Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;

async Task Run(string[] args)
static async Task Main(string[] args)
{
#if DEBUG
//args = "build --cid 8.0-snapshot functionbeat".Split();
//Console.WriteLine("ARGS: " + string.Join(",", args));
#endif

var commands = typeof(Program)
.Assembly.GetTypes()
.Where(x => x.GetCustomAttributes(typeof(VerbAttribute), inherit: true).Length > 0)
Expand All @@ -44,7 +39,7 @@ await result.MapResult(
async (errs) => await HandleErrorsAndShowHelp(result, commands));
}

Task HandleErrorsAndShowHelp(ParserResult<object> parserResult, Type[] commands)
static Task HandleErrorsAndShowHelp(ParserResult<object> parserResult, Type[] commands)
{
SentenceBuilder.Factory = () => new TweakedSentenceBuilder();

Expand All @@ -58,8 +53,8 @@ Task HandleErrorsAndShowHelp(ParserResult<object> parserResult, Type[] commands)

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

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

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

0 comments on commit bfe70d1

Please sign in to comment.