Skip to content

Commit

Permalink
Update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Sep 1, 2023
1 parent 4be5018 commit 9897d32
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/githubpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ jobs:
run: sed -i 's/<base href="\/" \/>/<base href="\/${{github.event.repository.name}}\/" \/>/g' src/WebConverter/bin/Release/net7.0/publish/wwwroot/index.html
- name: Create .nojekyll file
run: touch src/WebConverter/bin/Release/net7.0/publish/wwwroot/.nojekyll
- name: Update service-worker-assets.js hashes
working-directory: src/WebConverter/bin/Release/net7.0/publish/wwwroot
run: |
jsFile=$(<service-worker-assets.js)
# remove JavaScript from contents so it can be interpreted as JSON
json=$(echo "$jsFile" | sed "s/self.assetsManifest = //g" | sed "s/;//g")
# grab the assets JSON array
assets=$(echo "$json" | jq '.assets[]' -c)
for asset in $assets
do
oldHash=$(echo "$asset" | jq '.hash')
#remove leading and trailing quotes
oldHash="${oldHash:1:-1}"
path=$(echo "$asset" | jq '.url')
#remove leading and trailing quotes
path="${path:1:-1}"
newHash="sha256-$(openssl dgst -sha256 -binary $path | openssl base64 -A)"
if [ $oldHash != $newHash ]; then
# escape slashes for json
oldHash=$(echo "$oldHash" | sed 's;/;\\/;g')
newHash=$(echo "$newHash" | sed 's;/;\\/;g')
echo "Updating hash for $path from $oldHash to $newHash"
# escape slashes second time for sed
oldHash=$(echo "$oldHash" | sed 's;/;\\/;g')
jsFile=$(echo -n "$jsFile" | sed "s;$oldHash;$newHash;g")
fi
done
echo -n "$jsFile" > service-worker-assets.js
- name: Upload pages artifact
uses: actions/upload-pages-artifact@main
with:
Expand Down
11 changes: 7 additions & 4 deletions src/WebConverter/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
<div class="nav-item px-3">
<NavLink class="nav-link" href="@ReleaseUrl" target="_blank">@SemanticVersion</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="@CommitUrl" title="@CommitId" target="_blank">@CommitIdShort</NavLink>
</div>
@if (!string.IsNullOrEmpty(CommitId))
{
<div class="nav-item px-3">
<NavLink class="nav-link" href="@CommitUrl" title="@CommitId" target="_blank">@CommitIdShort</NavLink>
</div>
}
</nav>
</div>

Expand All @@ -47,7 +50,7 @@
private static string? ProductVersion { get; set; }
private static string? SemanticVersion => $"v{ProductVersion?.Split('+', StringSplitOptions.RemoveEmptyEntries)?.First()}";
private static string? ReleaseUrl => SemanticVersion != null ? $"{GitHubUrl}/releases/tag/{SemanticVersion}" : GitHubUrl;
private static string? CommitId => ProductVersion?.Split('+', StringSplitOptions.RemoveEmptyEntries)?.Last();
private static string? CommitId => ProductVersion != null && ProductVersion.Contains('+') ? ProductVersion?.Split('+', StringSplitOptions.RemoveEmptyEntries)?.Last() : null;
private static string? CommitIdShort => CommitId?.Substring(0, Math.Min(7, CommitId.Length));
private static string CommitUrl => CommitId != null ? $"{GitHubUrl}/commit/{CommitId}" : GitHubUrl;

Expand Down
4 changes: 4 additions & 0 deletions src/WebConverter/WebConverter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.10" PrivateAssets="all" />
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.5" />
<PackageReference Include="Thinktecture.Blazor.FileHandling" Version="2.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 9897d32

Please sign in to comment.