Skip to content

Commit

Permalink
Moved git info to the Main executable, so it is updated on each build.
Browse files Browse the repository at this point in the history
  • Loading branch information
maforget committed Jul 12, 2024
1 parent 704da79 commit 8a8a7b2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,6 @@ ASALocalRun/
# BeatPulse healthcheck temp database
healthchecksdb
/Reference
/cYo.Common/CurrentCommit.txt
/cYo.Common/isDirty.txt
/cYo.Common/Tags.txt
*/CurrentCommit.txt
*/isDirty.txt
*/Tags.txt
9 changes: 7 additions & 2 deletions ComicRack/ComicRack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ReaderForm.resx">
<DependentUpon>ReaderForm.cs</DependentUpon>
Expand Down Expand Up @@ -611,6 +612,7 @@
<Content Include="ComicRack.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="CurrentCommit.txt" />
<Content Include="Help\ComicRack Introduction.djvu">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -620,6 +622,7 @@
<Content Include="Help\ComicRack Wiki.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="isDirty.txt" />
<Content Include="Languages\cs-CZ.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -887,8 +890,10 @@ del /Q *.pdb
: Exit</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PreBuildEvent>cd ..\..\
git rev-parse HEAD &gt; "CurrentCommit.txt"
git status --porcelain &gt; "isDirty.txt"
exit 0</PreBuildEvent>
</PropertyGroup>
<Target Name="Clean">
<RemoveDir Directories="$(TargetDir)\Resources\Icons" />
Expand Down
28 changes: 0 additions & 28 deletions cYo.Common/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions cYo.Common/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,4 @@
AAAP//D//wAAAA//////AAAAAAAAAAAAAAA=
</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="CurrentCommit" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CurrentCommit.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="isDirty" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\isDirty.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>
31 changes: 28 additions & 3 deletions cYo.Common/Runtime/GitVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,44 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cYo.Common.Runtime
{
public static class GitVersion
{
public static string GetCurrentVersionInfo()
{
var isDirty = string.IsNullOrEmpty(Properties.Resources.isDirty?.Trim()) ? "" : "-dirty";
var currentCommit = string.IsNullOrEmpty(Properties.Resources.CurrentCommit) ? "" : $" [{Properties.Resources.CurrentCommit?[..7]}{isDirty}]";
Assembly assembly = Assembly.GetEntryAssembly();
var isDirty = string.IsNullOrEmpty(GetString("isDirty", assembly)?.Trim()) ? "" : "-dirty";
string currentCommit = GetString("CurrentCommit", assembly);
return string.IsNullOrEmpty(currentCommit) ? "" : $" [{currentCommit[..7]}{isDirty}]";
}

public static Stream GetStream(string resourceName, Assembly assembly)
{
string fullResourceName = assembly.GetManifestResourceNames().FirstOrDefault(x => x.Contains(resourceName));
return assembly.GetManifestResourceStream(fullResourceName); ;
}


public static string GetString(string resourceName, Assembly containingAssembly)
{
string result = String.Empty;
Stream sourceStream = GetStream(resourceName, containingAssembly);

if (sourceStream != null)
{
using (StreamReader streamReader = new StreamReader(sourceStream))
{
result = streamReader.ReadToEnd();
}
}

return currentCommit;
return result;
}
}
}
8 changes: 3 additions & 5 deletions cYo.Common/cYo.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand All @@ -372,9 +372,7 @@
<!-- </ItemGroup> -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd ..\..\
git rev-parse HEAD &gt; "CurrentCommit.txt"
git status --porcelain &gt; "isDirty.txt"
exit 0</PreBuildEvent>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>

0 comments on commit 8a8a7b2

Please sign in to comment.