Browse Source

* TFA-Bot.sln:
* BuildCommon.targets:
* TFA-Bot.csproj:
* AssemblyInfo.cs: Add GitCommit

* Dockerfile: Add git commit to msbuild

Logic Ethos Ltd 9 months ago
parent
commit
07da990979
5 changed files with 11 additions and 14 deletions
  1. 9 11
      TFA-Bot/BuildCommon.targets
  2. 1 1
      Dockerfile
  3. 1 0
      TFA-Bot.sln
  4. 0 1
      TFA-Bot/Properties/AssemblyInfo.cs
  5. 0 1
      TFA-Bot/TFA-Bot.csproj

+ 9 - 11
TFA-Bot/BuildCommon.targets

@@ -6,7 +6,7 @@
         $(CompileDependsOn);
     </CompileDependsOn>
 </PropertyGroup>
-<Target Name="CommonBuildDefineModifiedAssemblyVersion" Condition="'$(VersionAssembly)' != ''">
+<Target Name="CommonBuildDefineModifiedAssemblyVersion" Condition="'$(GitCommit)' != ''">
     <!-- Find AssemblyInfo.cs or AssemblyInfo.vb in the "Compile" Items. Remove it from "Compile" Items because we will use a modified version instead. -->
     <ItemGroup>
         <OriginalAssemblyInfo Include="@(Compile)" Condition="%(Filename) == 'AssemblyInfo' And (%(Extension) == '.vb' Or %(Extension) == '.cs')" />
@@ -18,11 +18,10 @@
           DestinationFiles="@(OriginalAssemblyInfo->'$(IntermediateOutputPath)%(Identity)')">
         <Output TaskParameter="DestinationFiles" ItemName="ModifiedAssemblyInfo"/>
     </Copy>
-    <!-- Replace the version bit (in AssemblyVersion and AssemblyFileVersion attributes) using regular expression. Use the defined property: $(VersionAssembly). -->
-    <Message Text="Setting AssemblyVersion to $(VersionAssembly)" />
+    <!-- Replace the version bit (in AssemblyVersion and AssemblyFileVersion attributes) using regular expression. Use the defined property: $(GitCommit). -->
+    <Message Text="Setting GitCommit to $(GitCommit)" />
     <RegexUpdateFile Files="@(ModifiedAssemblyInfo)"
-                Regex="Version\(&quot;(\d+)\.(\d+)(\.(\d+)\.(\d+)|\.*)&quot;\)"
-                ReplacementText="Version(&quot;$(VersionAssembly)&quot;)"
+                GitHash="$(GitCommit)"
                 />
     <!-- Include the modified AssemblyInfo.cs/.vb file in "Compile" items (instead of the original). -->
     <ItemGroup>
@@ -33,8 +32,7 @@
 <UsingTask TaskName="RegexUpdateFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
     <ParameterGroup>
         <Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
-        <Regex ParameterType="System.String" Required="true" />
-        <ReplacementText ParameterType="System.String" Required="true" />
+        <GitHash ParameterType="System.String" Required="true" />
     </ParameterGroup>
     <Task>
         <Reference Include="System.Core" />
@@ -46,15 +44,15 @@
         <Code Type="Fragment" Language="cs">
             <![CDATA[
             try {
-                var rx = new System.Text.RegularExpressions.Regex(this.Regex);
                 for (int i = 0; i < Files.Length; ++i)
                 {
                     var path = Files[i].GetMetadata("FullPath");
                     if (!File.Exists(path)) continue;
 
-                    var txt = File.ReadAllText(path);
-                    txt = rx.Replace(txt, this.ReplacementText);
-                    File.WriteAllText(path, txt);
+                    using (StreamWriter sw = File.AppendText(path)) 
+                    {
+                      sw.WriteLine($"[assembly: AssemblyGitCommit(\"{GitHash}\")]");
+                    } 
                 }
                 return true;
             }

+ 1 - 1
Dockerfile

@@ -31,7 +31,7 @@ RUN git clone -b ${BRANCH} https://git.factoid.org/TFA/TFA-Bot.git
 RUN wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
 WORKDIR /app/TFA-Bot
 RUN mono ../nuget.exe restore TFA-Bot.sln
-RUN msbuild -p:Configuration=Release TFA-Bot.sln
+RUN msbuild -p:Configuration=Release -property:GitCommit=$(git rev-parse HEAD) TFA-Bot.sln
 
 RUN apt-get clean
 RUN rm -rf /var/lib/apt/lists/*

+ 1 - 0
TFA-Bot.sln

@@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
 		.gitignore = .gitignore
 		LICENSE = LICENSE
 		README.md = README.md
+		BuildCommon.targets = BuildCommon.targets
 	EndProjectSection
 EndProject
 Global

+ 0 - 1
TFA-Bot/Properties/AssemblyInfo.cs

@@ -20,7 +20,6 @@ using TFABot;
 
 [assembly: AssemblyVersion("1.0.*")]
 
-[assembly: AssemblyGitCommit("")]
 
 // The following attributes are used to specify the signing key for the assembly, 
 // if desired. See the Mono documentation for more information about signing.

+ 0 - 1
TFA-Bot/TFA-Bot.csproj

@@ -131,7 +131,6 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />
-    <None Include="BuildCommon.targets" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="DiscordBot\" />