Disable service-worker hash integrity check #12
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: .NET | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'zulu' | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: 8.0.x | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Setup sonarcloud analysis | |
run: | | |
dotnet tool install --global dotnet-sonarscanner | |
dotnet sonarscanner begin \ | |
/k:"Phoenox_sidequest" /o:"phoenox" \ | |
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ | |
/d:sonar.host.url="https://sonarcloud.io" \ | |
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml | |
- name: Build | |
run: dotnet build --no-restore | |
- name: Test with code coverage | |
run: | | |
dotnet tool install --global dotnet-coverage | |
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" | |
- name: Publish sonarcloud report | |
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | |
- name: Install .NET WASM Build Tools | |
run: dotnet workload install wasm-tools | |
- name: Publish to release folder | |
run: dotnet publish SideQuest/SideQuest.csproj -c:Release -p:GHPages=true -o release --nologo | |
- name: Fix service-worker-assets.js hashes | |
working-directory: release/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: Commit wwwroot to GitHub Pages | |
uses: JamesIves/[email protected] | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BRANCH: gh-pages | |
FOLDER: release/wwwroot |