Update: Update the README #98
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: DeployToGitHubPages | |
env: | |
PUBLISH_DIR: bin/Release/net6.0/publish/wwwroot | |
# Controls when the action will run | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Publish app | |
run: dotnet publish -c Release | |
- name: Rewrite base href | |
uses: SteveSandersonMS/ghaction-rewrite-base-href@v1 | |
with: | |
html_path: ${{ env.PUBLISH_DIR }}/index.html | |
base_href: /PearlCalculatorBlazor/ | |
- name: Fix service-worker-assets.js hashes | |
working-directory: bin/Release/net6.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: GitHub Pages | |
if: success() | |
uses: crazy-max/[email protected] | |
with: | |
target_branch: gh-pages | |
build_dir: ${{ env.PUBLISH_DIR }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |