Skip to content

Commit

Permalink
Publish Blazor example
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 9, 2024
1 parent 386215b commit 89a2ef9
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 23 deletions.
32 changes: 21 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: samples/BlazorWebAssemblyApp/bin/publish
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ benchmarks/data/results/*.md
_ReSharper.Caches/
.idea
.logs

20 changes: 20 additions & 0 deletions .run/Publish Blazor example.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Publish Blazor example" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/roslyn4.3/Debug/net8.0/build.exe" />
<option name="PROGRAM_PARAMETERS" value="publish" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/build/build.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net8.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
28 changes: 16 additions & 12 deletions build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

DI.Setup(nameof(Composition))
.Root<RootTarget>("RootTarget")

.DefaultLifetime(Lifetime.PerBlock)
.Bind<RootCommand>().To<RootCommand>()
.Bind<Settings>().To<Settings>()

.Bind().To<RootCommand>()
.Bind().To<Settings>()
.Bind<ITeamCityArtifactsWriter>().To(_ => GetService<ITeamCityWriter>())
.Bind<INuGet>().To(_ => GetService<INuGet>())
.Bind().To(_ => GetService<INuGet>())

// Targets
.Bind<IInitializable, ITarget<Package>>(typeof(GeneratorTarget)).To<GeneratorTarget>()
.Bind<IInitializable, ITarget<IReadOnlyCollection<Library>>>(typeof(LibrariesTarget)).To<LibrariesTarget>()
.Bind<IInitializable, ITarget<IReadOnlyCollection<Package>>>(typeof(CompatibilityCheckTarget)).To<CompatibilityCheckTarget>()
.Bind<IInitializable, ITarget<IReadOnlyCollection<Package>>>(typeof(PackTarget)).To<PackTarget>()
.Bind<IInitializable>(typeof(ReadmeTarget)).To<ReadmeTarget>()
.Bind<IInitializable, ITarget<int>>(typeof(BenchmarksTarget)).To<BenchmarksTarget>()
.Bind<IInitializable>(typeof(DeployTarget)).To<DeployTarget>()
.Bind<IInitializable>(typeof(TemplateTarget)).To<TemplateTarget>()
.Bind<IInitializable>(typeof(UpdateTarget)).To<UpdateTarget>();
.Bind(Tag.Type).To<GeneratorTarget>()
.Bind(Tag.Type).To<LibrariesTarget>()
.Bind(Tag.Type).To<CompatibilityCheckTarget>()
.Bind(Tag.Type).To<PackTarget>()
.Bind(Tag.Type).To<ReadmeTarget>()
.Bind(Tag.Type).To<BenchmarksTarget>()
.Bind(Tag.Type).To<DeployTarget>()
.Bind(Tag.Type).To<TemplateTarget>()
.Bind(Tag.Type).To<UpdateTarget>()
.Bind(Tag.Type).To<PublishBlazorTarget>();

return await new Composition().RootTarget.RunAsync(CancellationToken.None);
53 changes: 53 additions & 0 deletions build/PublishBlazorTarget.cs
Original file line number Diff line number Diff line change
@@ -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<int>
{
public Task InitializeAsync() => commands.Register(
this,
"Publish balazor web sssembly example",
"publish",
"pb");

[SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")]
public async Task<int> 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("""<base href="/" />""", """<base href="/Pure.DI/" />""");
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;
}
}

0 comments on commit 89a2ef9

Please sign in to comment.