diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dce44f28..cc94a875 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,19 +1,29 @@ name: Pure.DI check -on: [push] +on: [ push ] jobs: build: runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - name: Build and check - run: dotnet run --project ./build -- check + steps: + - uses: actions/checkout@v4 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + #- name: Build and check + #run: dotnet run --project ./build -- check + + - 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 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: samples/BlazorWebAssemblyApp/bin/publish diff --git a/.gitignore b/.gitignore index b6ba230c..ec2c6cdd 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ benchmarks/data/results/*.md _ReSharper.Caches/ .idea .logs + diff --git a/.run/Publish Blazor example.run.xml b/.run/Publish Blazor example.run.xml new file mode 100644 index 00000000..a10e319e --- /dev/null +++ b/.run/Publish Blazor example.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs index e3795940..45dc9e32 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -2,20 +2,24 @@ DI.Setup(nameof(Composition)) .Root("RootTarget") + .DefaultLifetime(Lifetime.PerBlock) - .Bind().To() - .Bind().To() + + .Bind().To() + .Bind().To() .Bind().To(_ => GetService()) - .Bind().To(_ => GetService()) + .Bind().To(_ => GetService()) + // Targets - .Bind>(typeof(GeneratorTarget)).To() - .Bind>>(typeof(LibrariesTarget)).To() - .Bind>>(typeof(CompatibilityCheckTarget)).To() - .Bind>>(typeof(PackTarget)).To() - .Bind(typeof(ReadmeTarget)).To() - .Bind>(typeof(BenchmarksTarget)).To() - .Bind(typeof(DeployTarget)).To() - .Bind(typeof(TemplateTarget)).To() - .Bind(typeof(UpdateTarget)).To(); + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To(); return await new Composition().RootTarget.RunAsync(CancellationToken.None); \ No newline at end of file diff --git a/build/PublishBlazorTarget.cs b/build/PublishBlazorTarget.cs new file mode 100644 index 00000000..c23af42a --- /dev/null +++ b/build/PublishBlazorTarget.cs @@ -0,0 +1,53 @@ +// ReSharper disable StringLiteralTypo +// ReSharper disable HeapView.DelegateAllocation +// ReSharper disable HeapView.ClosureAllocation +// ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable ReturnTypeCanBeEnumerable.Local +// ReSharper disable InvertIf + +namespace Build; + +internal class PublishBlazorTarget( + Commands commands) + : IInitializable, ITarget +{ + public Task InitializeAsync() => commands.Register( + this, + "Publish balazor web sssembly example", + "publish", + "pb"); + + [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] + public async Task RunAsync(CancellationToken cancellationToken) + { + var projectPath = Path.Combine("samples", "BlazorWebAssemblyApp"); + var publishPath = Path.Combine(projectPath, "bin", "publish"); + if (Directory.Exists(publishPath)) + { + Directory.Delete(publishPath, true); + } + + var result = await new DotNetPublish() + .WithProject(projectPath) + .WithConfiguration("Release") + .WithOutput(publishPath) + .RunAsync(cancellationToken: cancellationToken); + + var rootPath = Path.Combine(publishPath, "root"); + Directory.Move(Path.Combine(publishPath, "wwwroot"), rootPath); + + // Change the base-tag in index.html from '/' to 'BlazorWebAssemblyApp' to match GitHub Pages repository subdirectory + var indexFile = Path.Combine(rootPath, "index.html"); + var indexContent = await File.ReadAllTextAsync(indexFile, cancellationToken); + 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(rootPath, "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(rootPath, ".nojekyll"), "", cancellationToken); + + return result ?? 1; + } +} \ No newline at end of file