Skip to content

Commit d213119

Browse files
Copilotmattleibow
andcommitted
refactor: use AssemblyMetadata for build info instead of sed on index.html
- SkiaSharpDemo.Blazor.csproj: add BuildInfo MSBuild property (defaults to "local") and an AssemblyAttribute item that bakes it into the assembly as AssemblyMetadataAttribute("BuildInfo", ...) - Layout/MainLayout.razor: add @code block that reads BuildInfo from the executing assembly at runtime; renders it in a <footer class="build-info"> - Layout/MainLayout.razor.css: add .build-info footer style (right-aligned, monospace, muted, with top border) - docs-deploy.yml: pass -p:BuildInfo="SOURCE_LABEL · SHA" to dotnet publish so CI bakes the correct label into the assembly; remove sed BUILD_INFO_PLACEHOLDER step and its env vars from the copy step - wwwroot/index.html: remove BUILD_INFO_PLACEHOLDER div (no longer needed) - wwwroot/css/app.css: remove #build-info fixed-position badge style Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
1 parent 841b7ce commit d213119

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

.github/workflows/docs-deploy.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ jobs:
8282
run: dotnet build scripts/SkiaSharp.Extended-Pack.slnf -c Release -f net10.0
8383

8484
- name: Publish Blazor sample
85-
run: dotnet publish samples/SkiaSharpDemo.Blazor/SkiaSharpDemo.Blazor.csproj -c Release -o publish/sample
85+
env:
86+
SOURCE_LABEL: ${{ steps.vars.outputs.source_label }}
87+
run: |
88+
COMMIT_SHORT="${GITHUB_SHA:0:7}"
89+
BUILD_INFO="${SOURCE_LABEL} · ${COMMIT_SHORT}"
90+
dotnet publish samples/SkiaSharpDemo.Blazor/SkiaSharpDemo.Blazor.csproj \
91+
-c Release -o publish/sample \
92+
-p:BuildInfo="$BUILD_INFO"
8693
8794
- name: Build docs
8895
env:
@@ -99,11 +106,7 @@ jobs:
99106
env:
100107
BASE_HREF: ${{ steps.vars.outputs.sample_base_href }}
101108
SEGMENT_COUNT: ${{ steps.vars.outputs.sample_segment_count }}
102-
SOURCE_LABEL: ${{ steps.vars.outputs.source_label }}
103109
run: |
104-
COMMIT_SHORT="${GITHUB_SHA:0:7}"
105-
BUILD_INFO="${SOURCE_LABEL} · ${COMMIT_SHORT}"
106-
107110
mkdir -p docs/_site/sample
108111
cp -r publish/sample/wwwroot/. docs/_site/sample/
109112
@@ -115,9 +118,6 @@ jobs:
115118
sed -i "s|var segmentCount = [0-9]*;|var segmentCount = $SEGMENT_COUNT;|" docs/_site/sample/404.html
116119
fi
117120
118-
# Inject build info
119-
sed -i "s|BUILD_INFO_PLACEHOLDER|$BUILD_INFO|" docs/_site/sample/index.html
120-
121121
- name: Upload site artifact
122122
uses: actions/upload-artifact@v4
123123
with:

samples/SkiaSharpDemo.Blazor/Layout/MainLayout.razor

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@inherits LayoutComponentBase
1+
@inherits LayoutComponentBase
2+
@using System.Reflection
23
<div class="page">
34
<div class="sidebar">
45
<NavMenu />
@@ -13,5 +14,13 @@
1314
<article class="content px-4">
1415
@Body
1516
</article>
17+
18+
<footer class="build-info">@_buildInfo</footer>
1619
</main>
1720
</div>
21+
22+
@code {
23+
private string _buildInfo = typeof(App).Assembly
24+
.GetCustomAttributes<AssemblyMetadataAttribute>()
25+
.FirstOrDefault(a => a.Key == "BuildInfo")?.Value ?? "local";
26+
}

samples/SkiaSharpDemo.Blazor/Layout/MainLayout.razor.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,16 @@ main {
4545
margin-left: 0;
4646
}
4747
}
48+
49+
.build-info {
50+
text-align: right;
51+
padding: 0.25rem 1.5rem;
52+
font-size: 0.65rem;
53+
font-family: monospace;
54+
color: #999;
55+
border-top: 1px solid #eee;
56+
}
4857

49-
@media (min-width: 641px) {
5058
.page {
5159
flex-direction: row;
5260
}

samples/SkiaSharpDemo.Blazor/SkiaSharpDemo.Blazor.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@
1212
<!-- Do not make NuGet packages or include in tests -->
1313
<IsPackable>false</IsPackable>
1414
<IsTestProject>false</IsTestProject>
15+
16+
<!-- Build info shown in the app footer; overridden by CI via -p:BuildInfo="..." -->
17+
<BuildInfo Condition="'$(BuildInfo)' == ''">local</BuildInfo>
1518
</PropertyGroup>
1619

20+
<ItemGroup>
21+
<!-- Expose BuildInfo as an assembly-level attribute so the Blazor app can read it at runtime -->
22+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
23+
<_Parameter1>BuildInfo</_Parameter1>
24+
<_Parameter2>$(BuildInfo)</_Parameter2>
25+
</AssemblyAttribute>
26+
</ItemGroup>
27+
1728
<ItemGroup>
1829
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.3" />
1930
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.3" PrivateAssets="all" />

samples/SkiaSharpDemo.Blazor/wwwroot/css/app.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,3 @@ code {
109109
text-align: end;
110110
}
111111

112-
#build-info {
113-
position: fixed;
114-
bottom: 0.4rem;
115-
right: 0.5rem;
116-
background: rgba(0, 0, 0, 0.45);
117-
color: rgba(255, 255, 255, 0.85);
118-
font-size: 0.65rem;
119-
font-family: monospace;
120-
padding: 0.15rem 0.4rem;
121-
border-radius: 0.2rem;
122-
z-index: 9998;
123-
pointer-events: none;
124-
}

samples/SkiaSharpDemo.Blazor/wwwroot/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<a href="." class="reload">Reload</a>
3939
<span class="dismiss">🗙</span>
4040
</div>
41-
<div id="build-info">BUILD_INFO_PLACEHOLDER</div>
4241
<script src="_framework/blazor.webassembly.js"></script>
4342
</body>
4443

0 commit comments

Comments
 (0)