Skip to content

Commit

Permalink
Update githubpages.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila authored Sep 2, 2023
1 parent b6dec82 commit 9042527
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion .github/workflows/githubpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,45 @@ jobs:
sed -i 's/"start_url": "\/"/"start_url": "\/${{github.event.repository.name}}\/"/g' manifest.webmanifest
sed -i 's/"action": "\/"/"action": "\/${{github.event.repository.name}}\/"/g' manifest.webmanifest
sed -i 's/"action": "\/receive-webshare"/"action": "\/${{github.event.repository.name}}\/receive-webshare"/g' manifest.webmanifest
sed -i "s/return Response.redirect(\'\/\', 303);/return Response.redirect(\'\/${{github.event.repository.name}}\/\', 303);/g" service-worker.published.js
- name: Restore
run: dotnet restore src/PDFtoImage.sln
- name: Publish
run: dotnet publish src/WebConverter/WebConverter.csproj -c Release -p:PublishProfile=src/WebConverter/Properties/PublishProfiles/PublishSite.pubxml --no-restore
- name: Create .nojekyll file
run: touch src/WebConverter/bin/Release/net7.0/publish/wwwroot/.nojekyll
- name: Update relative paths
working-directory: src/WebConverter/bin/Release/net7.0/publish/wwwroot
run: |
sed -i "s/return Response.redirect(\'\/\', 303);/return Response.redirect(\'\/${{github.event.repository.name}}\/\', 303);/g" service-worker.js
- 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

0 comments on commit 9042527

Please sign in to comment.