Skip to content

Deploy to GitHub Pages #46

Deploy to GitHub Pages

Deploy to GitHub Pages #46

name: Deploy to GitHub Pages
on:
push:
branches:
- main
schedule:
# Run daily at 3 AM UTC for content updates
- cron: '0 3 * * *'
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
env:
DOTNET_VERSION: '10.0.x'
NODE_VERSION: '20.x'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: JdhPro.Web/package-lock.json
- name: Install WASM workload
run: dotnet workload install wasm-tools
- name: Cache .NET dependencies
uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore .NET dependencies
working-directory: JdhPro.Web
run: dotnet restore
- name: Install npm packages
working-directory: JdhPro.Web
run: npm ci
- name: Build Tailwind CSS
working-directory: JdhPro.Web
run: npm run build:css
- name: Publish Blazor WASM with AOT
working-directory: JdhPro.Web
run: |
dotnet publish -c Release -o ../publish --nologo
- name: Add .nojekyll file
run: touch publish/wwwroot/.nojekyll
- name: Update base href for GitHub Pages
run: |
REPO_NAME="${{ github.event.repository.name }}"
sed -i 's|<base href="/" />|<base href="/'$REPO_NAME'/" />|g' publish/wwwroot/index.html
sed -i "s|location.replace('/');|location.replace('/$REPO_NAME/');|g" publish/wwwroot/404.html
echo "Updated base href to /$REPO_NAME/"
echo "Updated 404.html redirect to /$REPO_NAME/"
- name: Verify build output
run: |
echo "Build completed successfully"
ls -la publish/wwwroot
cat publish/wwwroot/index.html | grep "base href"
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: publish/wwwroot
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Deployment summary
run: |
echo "### ✅ Deployment Successful!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**URL:** ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY
echo "**Time:** $(date -u)" >> $GITHUB_STEP_SUMMARY