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 8, 2024
1 parent 386215b commit 33b9d99
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ jobs:

- name: Build and check
run: dotnet run --project ./build -- check

- name: Publish Blazor example
run: dotnet run --project ./build -- 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
wwwroot
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);
31 changes: 31 additions & 0 deletions build/PublishBlazorTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 result = await new DotNetPublish()
.WithProject(Path.Combine("samples", "BlazorWebAssemblyApp", "BlazorWebAssemblyApp.csproj"))
.WithConfiguration("Release")
.WithOutput("wwwroot")
.RunAsync(cancellationToken: cancellationToken);

return result ?? 1;
}
}

0 comments on commit 33b9d99

Please sign in to comment.