From f1d43b120d2eb0c4df602a2057f93f6ae3121cc3 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Fri, 8 Mar 2024 14:24:53 +0300 Subject: [PATCH] Publish Blazor example 2 --- .github/workflows/main.yml | 46 ++++++++++++++++--- .gitignore | 2 +- _config.yml | 2 + build/PublishBlazorTarget.cs | 16 +++---- .../BlazorWebAssemblyApp/wwwroot/index.html | 2 +- 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 _config.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1b312cf6..189be9b2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -21,9 +33,31 @@ jobs: - name: Publish Blazor example run: dotnet run --project ./build -- publish - - name: Commit wwwroot to GitHub Pages - uses: JamesIves/github-pages-deploy-action@3.7.1 + - 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: Copy framework + run: cp -a ./root/wwwroot/_framework ./_site/_framework + + - 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 diff --git a/.gitignore b/.gitignore index ec2c6cdd..9854261a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ benchmarks/data/results/*.md _ReSharper.Caches/ .idea .logs - +root diff --git a/_config.yml b/_config.yml new file mode 100644 index 00000000..1cf29686 --- /dev/null +++ b/_config.yml @@ -0,0 +1,2 @@ +include: + - _framework diff --git a/build/PublishBlazorTarget.cs b/build/PublishBlazorTarget.cs index f5a9e208..fafedd28 100644 --- a/build/PublishBlazorTarget.cs +++ b/build/PublishBlazorTarget.cs @@ -20,26 +20,24 @@ public Task InitializeAsync() => commands.Register( [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] public async Task RunAsync(CancellationToken cancellationToken) { + var wwwroot = Path.Combine("root", "wwwroot"); + if (Directory.Exists(wwwroot)) + { + Directory.Delete(wwwroot, true); + } + var result = await new DotNetPublish() .WithProject(Path.Combine("samples", "BlazorWebAssemblyApp", "BlazorWebAssemblyApp.csproj")) .WithConfiguration("Release") .WithOutput("root") .RunAsync(cancellationToken: cancellationToken); - - var wwwroot = Path.Combine("root", "wwwroot"); // 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("""""", """"""); + indexContent = indexContent.Replace("""""", """"""); 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")); - - // 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; } } \ No newline at end of file diff --git a/samples/BlazorWebAssemblyApp/wwwroot/index.html b/samples/BlazorWebAssemblyApp/wwwroot/index.html index d9f7633d..ddd4ff90 100644 --- a/samples/BlazorWebAssemblyApp/wwwroot/index.html +++ b/samples/BlazorWebAssemblyApp/wwwroot/index.html @@ -4,7 +4,7 @@ - BlazorWebAssemblyApp + Pure.DI Blazor WebAssembly App