Skip to content

Publish .NET Blazor WASM app to GitHub Pages #7

Publish .NET Blazor WASM app to GitHub Pages

Publish .NET Blazor WASM app to GitHub Pages #7

name: Publish .NET Blazor WASM app to GitHub Pages
on:
# push:
# branches:
# - master
workflow_dispatch:
env:
#VERSION: "2022.11.19"
VERSION_SUFFIX: "-alpha"
CONFIGURATION: "Release"
PROJECT_FILE: "src/apps/Highbyte.DotNet6502.App.SkiaWASM/Highbyte.DotNet6502.App.SkiaWASM.csproj"
PROJECT_GH_PAGES_DIR: "app"
BUILD_OUTPUT_WORKING_DIR: "build"
GH_PAGES_WORKING_DIR: "ghpages"
GH_PAGES_BRANCH_NAME: "gh-pages"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Checkout the code
- uses: actions/checkout@v2
# Set version number (major.minor.revision) as current Year.Month.Day. Ex: 2022.11.19
- name: Set current date as env variable
run: echo "VERSION=$(date +'%Y.%m.%d')" >> $GITHUB_ENV
# Install .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Install DotNet workload - WASM tools
run: |
dotnet workload install wasm-tools
# Create GitHub Pages root folder contents
- name: Create GH root folder and add .nojekyll file do disable built-in Jekyll CMS
run: |
mkdir ${{ env.GH_PAGES_WORKING_DIR }}
echo '' > ${{ env.GH_PAGES_WORKING_DIR }}/.nojekyll
# Publish the Blazor WASM site to a build working folder
- name: Publish
# Note: Could not get -p:GHPagesInjectBrotliLoader=true to work. Gets error "Uncaught ReferenceError: Blazor is not defined" from "brotliloader.min.js"
run: dotnet publish ${{ env.PROJECT_FILE }} -p:Version=${{ env.VERSION }}.${{ github.run_number }}${{ env.VERSION_SUFFIX }} -c:${{ env.CONFIGURATION }} -p:GHPages=true -p:GHPagesBase="/${{ github.event.repository.name }}/${{ env.PROJECT_GH_PAGES_DIR }}/" -p:GHPagesInjectBrotliLoader=false -o:${{ env.BUILD_OUTPUT_WORKING_DIR }}/${{ env.PROJECT_GH_PAGES_DIR }}
# Copy the published Blazor WASM site from wwwroot folder in publish output dir
- name: Copy published wwwroot contents to a subdirectory in GH pages working dir root
run: |
cp -r ${{ env.BUILD_OUTPUT_WORKING_DIR }}/${{ env.PROJECT_GH_PAGES_DIR }}/wwwroot/ ${{ env.GH_PAGES_WORKING_DIR }}/${{ env.PROJECT_GH_PAGES_DIR }}/
# Deploy the Blazor WASM site
- name: Deploy to Github Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
# token: ${{ secrets.ACCESS_TOKEN }} # Use if custom token needed to another repo
branch: ${{ env.GH_PAGES_BRANCH_NAME }} # The branch the action should deploy to.
folder: ${{ env.GH_PAGES_WORKING_DIR }} # The folder the action should deploy.
#target-folder: app #If not specified, the contents for folder above is copied to the root of the GH pages branch.
single-commit: true