Skip to content

Commit

Permalink
Publish Blazor example 2
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 8, 2024
1 parent 5c24f61 commit fca6cbb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
43 changes: 37 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
name: Pure.DI check

on: [ push ]
on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
Expand All @@ -21,9 +33,28 @@ jobs:
- name: Publish Blazor example
run: dotnet run --project ./build -- publish

- name: Commit wwwroot to GitHub Pages
uses: JamesIves/[email protected]
- name: Setup Pages
uses: actions/configure-pages@v4

- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: root
source: ./root/wwwroot
destination: ./_site

- name: Upload artifact
uses: actions/upload-pages-artifact@v3

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
needs: build

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ benchmarks/data/results/*.md
_ReSharper.Caches/
.idea
.logs

root
14 changes: 8 additions & 6 deletions build/PublishBlazorTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ public async Task<int> RunAsync(CancellationToken cancellationToken)
.RunAsync(cancellationToken: cancellationToken);

var wwwroot = Path.Combine("root", "wwwroot");
if (Directory.Exists(wwwroot))
{
Directory.Delete(wwwroot, true);
}

// Change the base-tag in index.html from '/' to 'BlazorWebAssemblyApp' to match GitHub Pages repository subdirectory
var indexFile = Path.Combine(wwwroot, "index.html");
var indexContent = await File.ReadAllTextAsync(indexFile, cancellationToken);
indexContent = indexContent.Replace("""<base href="/" />""", """<base href="/BlazorWebAssemblyApp" />""");
indexContent = indexContent
.Replace("""<base href="/" />""", """<base href="/Pure.DI/" />""")
.Replace("_framework", "framework");
await File.WriteAllTextAsync(indexFile, indexContent, cancellationToken);

// Copy index.html to 404.html to serve the same file when a file is not found
File.Copy(indexFile, Path.Combine(wwwroot, "404.html"));
Directory.Move(Path.Combine(wwwroot, "_framework"), Path.Combine(wwwroot, "framework"));

// Add .nojekyll file to tell GitHub pages to not treat this as a Jekyll project. (Allow files and folders starting with an underscore)
await File.AppendAllTextAsync(Path.Combine(wwwroot, ".nojekyll"), "", cancellationToken);

return result ?? 1;
}
}
2 changes: 1 addition & 1 deletion samples/BlazorWebAssemblyApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>BlazorWebAssemblyApp</title>
<title>Pure.DI Blazor WebAssembly App</title>
<base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" />
Expand Down

0 comments on commit fca6cbb

Please sign in to comment.