Skip to content

Commit 0b9a16b

Browse files
Refactor GitHub Pages deployment workflow for Blazor
1 parent e5d8abd commit 0b9a16b

File tree

1 file changed

+74
-28
lines changed

1 file changed

+74
-28
lines changed

.github/workflows/pages.yml

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to GitHub Pages
1+
name: Deploy Blazor to GitHub Pages
22

33
on:
44
push:
@@ -19,51 +19,97 @@ concurrency:
1919
cancel-in-progress: false
2020

2121
jobs:
22-
build:
22+
build-and-deploy:
2323
runs-on: ubuntu-latest
2424

25+
environment:
26+
name: github-pages
27+
url: ${{ steps.deployment.outputs.page_url }}
28+
2529
steps:
26-
- name: Checkout
30+
# ========================================
31+
# 1️⃣ Checkout Repository
32+
# ========================================
33+
- name: 📥 Checkout repository
2734
uses: actions/checkout@v4
2835

29-
- name: Setup .NET
36+
# ========================================
37+
# 2️⃣ Setup .NET SDK
38+
# ========================================
39+
- name: 🔧 Setup .NET 8.0
3040
uses: actions/setup-dotnet@v4
3141
with:
3242
dotnet-version: '8.0.x'
3343

34-
- name: Restore
44+
# ========================================
45+
# 3️⃣ Restore NuGet packages
46+
# ========================================
47+
- name: 📦 Restore dependencies
3548
run: dotnet restore samples/BlazorWasm.NET8/BlazorWasm.NET8.csproj
3649

37-
- name: Publish
38-
run: dotnet publish samples/BlazorWasm.NET8/BlazorWasm.NET8.csproj -c Release -o release
50+
# ========================================
51+
# 4️⃣ Publish Blazor WASM
52+
# ========================================
53+
- name: 🏗️ Publish Blazor WASM
54+
run: |
55+
dotnet publish samples/BlazorWasm.NET8/BlazorWasm.NET8.csproj \
56+
-c Release \
57+
-o publish \
58+
-p:GHPages=true \
59+
-p:BlazorEnableCompression=false
3960
40-
- name: Change base-tag
41-
run: sed -i 's/<base href="\/" \/>/<base href="\/blazor\/" \/>/g' release/wwwroot/index.html
61+
# ========================================
62+
# 5️⃣ Fix base href for GitHub Pages
63+
# ========================================
64+
- name: 🔧 Update base href
65+
run: |
66+
sed -i 's|<base href="/" />|<base href="/Blazor/" />|g' publish/wwwroot/index.html
67+
echo "✅ Base href updated to /Blazor/"
4268
43-
- name: Add .nojekyll
44-
run: touch release/wwwroot/.nojekyll
69+
# ========================================
70+
# 6️⃣ Add .nojekyll file
71+
# ========================================
72+
- name: 📝 Add .nojekyll
73+
run: |
74+
touch publish/wwwroot/.nojekyll
75+
echo "✅ .nojekyll file created"
4576
46-
- name: Setup Pages
77+
# ========================================
78+
# 7️⃣ Add 404 fallback for SPA routing
79+
# ========================================
80+
- name: 🔄 Create 404.html
81+
run: |
82+
cp publish/wwwroot/index.html publish/wwwroot/404.html
83+
echo "✅ 404.html created for SPA routing"
84+
85+
# ========================================
86+
# 8️⃣ List published files (for debugging)
87+
# ========================================
88+
- name: 📋 List published files
89+
run: |
90+
echo "📂 Contents of publish/wwwroot:"
91+
ls -lah publish/wwwroot/
92+
echo ""
93+
echo "📄 index.html base href:"
94+
grep "<base" publish/wwwroot/index.html
95+
96+
# ========================================
97+
# 9️⃣ Setup GitHub Pages
98+
# ========================================
99+
- name: ⚙️ Setup Pages
47100
uses: actions/configure-pages@v4
48101

49-
- name: Upload artifact
102+
# ========================================
103+
# 🔟 Upload artifact
104+
# ========================================
105+
- name: 📤 Upload Pages artifact
50106
uses: actions/upload-pages-artifact@v3
51107
with:
52-
path: release/wwwroot
53-
54-
deploy:
55-
needs: build
56-
runs-on: ubuntu-latest
57-
58-
permissions:
59-
pages: write
60-
id-token: write
108+
path: 'publish/wwwroot'
61109

62-
environment:
63-
name: github-pages
64-
url: ${{ steps.deployment.outputs.page_url }}
65-
66-
steps:
67-
- name: Deploy to GitHub Pages
110+
# ========================================
111+
# 1️⃣1️⃣ Deploy to GitHub Pages
112+
# ========================================
113+
- name: 🚀 Deploy to GitHub Pages
68114
id: deployment
69115
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)