Skip to content

Commit

Permalink
add version information to Index Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Volker Hänsel committed Oct 1, 2023
1 parent 17bfd1e commit f312f2f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tuya_mqtt.net/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
RID=linux-arm ; \
fi \
&& echo "target $TARGETPLATFORM build $BUILDPLATFORM RID $RID" \
&& dotnet build "tuya_mqtt.net.csproj" -r $RID -c Release -o /app/build
&& dotnet build "tuya_mqtt.net.csproj" -r $RID --self-contained -c Release -o /app/build

FROM build AS publish
ARG BUILDPLATFORM
Expand Down
30 changes: 29 additions & 1 deletion tuya_mqtt.net/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
@inject ILogger<Index> Logger

<PageTitle>tuya mqtt.net Status</PageTitle>

@* ReSharper disable UnknownCssClass *@
<MudCard>
<MudCardHeader>
<MudText Typo="Typo.button">Version:</MudText>
<MudText Class="ml-4">@_versionCompile</MudText>
<MudText Class="ml-4">@_versionGit</MudText>
</MudCardHeader>
<MudCardContent>
<div class="markdown"> @((MarkupString)_readmeHtml) </div>
</MudCardContent>
</MudCard>
@* ReSharper restore UnknownCssClass *@
@code {
private MarkdownPipeline? _pipeline;
private string _readmeHtml = null!;
private string _versionCompile = String.Empty;
private string _versionGit = String.Empty;

protected override async Task OnInitializedAsync()
{
Expand Down Expand Up @@ -48,6 +56,26 @@
{
_readmeHtml = "<b>An error occurred, cannot convert markdown in README.md</b>";
}

try
{
await using (var reader = embeddedProvider.GetFileInfo("Resources/BuildDate.txt").CreateReadStream())
//Resources/BuildDate.txt is an embedded resource
{
var sr = new StreamReader(reader);
var str = await sr.ReadToEndAsync();
string[] strings = str.Split('\n');
if (strings.Length > 0) _versionCompile = strings[0];
if (strings.Length > 1) _versionGit = strings[1];
}
}
catch (Exception e)
{
Logger.LogError(e, "");

_versionCompile = "cannot read version information";
_versionGit = String.Empty;
}
}


Expand Down
1 change: 1 addition & 0 deletions tuya_mqtt.net/Resources/EMPTY.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 9 additions & 0 deletions tuya_mqtt.net/tuya_mqtt.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<ItemGroup>
<None Remove="README.md" />
<None Remove="Resources\BuildDate.txt" />
</ItemGroup>

<ItemGroup>
Expand All @@ -43,4 +44,12 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\BuildDate.txt" />
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo %25date%25 %25time%25 &gt; &quot;$(ProjectDir)\Resources\BuildDate.txt&quot;&#xD;&#xA;git describe --tags &gt;&gt; &quot;$(ProjectDir)\Resources\BuildDate.txt&quot;" />
</Target>

</Project>

0 comments on commit f312f2f

Please sign in to comment.