diff --git a/Build.cs b/Build.cs index 4dbfb65..d68217e 100644 --- a/Build.cs +++ b/Build.cs @@ -47,7 +47,6 @@ internal partial class Build : NukeBuild private static readonly HttpClient _httpClient = new HttpClient(); private static int? _exitCode; - private static bool ClearTempBeforeExit { get; set; } = false; public static int Main() @@ -75,7 +74,7 @@ public static int Main() { FileSystemTasks.DeleteDirectory(TemporaryDirectory); } - + var exitCode = Execute(x => x.Compile); return _exitCode ?? exitCode; } @@ -197,8 +196,9 @@ public static int Main() // TODO: Convert to a method because GitRepository.FromLocalDirectory() is a heavy method and it should not be used as a property protected GitRepository GitRepository => GitRepository.FromLocalDirectory(RootDirectory / ".git"); - protected AbsolutePath SourceDirectory => RootDirectory / "src"; - protected AbsolutePath TestsDirectory => RootDirectory / "tests"; + protected static AbsolutePath SourceDirectory => RootDirectory / "src"; + protected static AbsolutePath TestsDirectory => RootDirectory / "tests"; + protected static AbsolutePath SamplesDirectory => RootDirectory / "samples"; protected AbsolutePath ModulesLocalDirectory => ArtifactsDirectory / ModulesJsonDirectoryName; protected Project WebProject => Solution?.AllProjects.FirstOrDefault(x => x.Name.EndsWith(".Web") && !x.Path.ToString().Contains("samples") || x.Name.EndsWith("VirtoCommerce.Storefront")); @@ -237,6 +237,7 @@ private void SonarLogger(OutputType type, string text) case OutputType.Err: Logger.Error(text); break; + case OutputType.Std: Logger.Info(text); break; @@ -247,11 +248,24 @@ private void SonarLogger(OutputType type, string text) .Before(Restore) .Executes(() => { - SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory); + var searchPattern = new string[] { "**/bin", "**/obj" }; + if (DirectoryExists(SourceDirectory)) + { + SourceDirectory.GlobDirectories(searchPattern).ForEach(DeleteDirectory); + + if (DirectoryExists(TestsDirectory)) + { + TestsDirectory.GlobDirectories(searchPattern).ForEach(DeleteDirectory); + } - if (DirectoryExists(TestsDirectory)) + if (DirectoryExists(SamplesDirectory)) + { + SamplesDirectory.GlobDirectories(searchPattern).ForEach(DeleteDirectory); + } + } + else { - TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory); + RootDirectory.GlobDirectories(searchPattern).ForEach(DeleteDirectory); } EnsureCleanDirectory(ArtifactsDirectory); @@ -267,28 +281,28 @@ private void SonarLogger(OutputType type, string text) ); }); - Target Pack => _ => _ - .DependsOn(Test) - .Executes(() => - { + public Target Pack => _ => _ + .DependsOn(Test) + .Executes(() => + { //For platform take nuget package description from Directory.Build.props var settings = new DotNetPackSettings() - .SetProject(Solution) - .EnableNoBuild() - .SetConfiguration(Configuration) - .EnableIncludeSymbols() - .SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg) - .SetOutputDirectory(ArtifactsDirectory) - .SetVersion(ReleaseVersion) - .When(IsModule, modulePackSettings => modulePackSettings - .SetPackageLicenseUrl(ModuleManifest.LicenseUrl) - .SetPackageProjectUrl(ModuleManifest.ProjectUrl) - .SetPackageIconUrl(ModuleManifest.IconUrl) - .SetPackageRequireLicenseAcceptance(false) - .SetDescription(ModuleManifest.Description) - .SetCopyright(ModuleManifest.Copyright)); - DotNetPack(settings); - }); + .SetProject(Solution) + .EnableNoBuild() + .SetConfiguration(Configuration) + .EnableIncludeSymbols() + .SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg) + .SetOutputDirectory(ArtifactsDirectory) + .SetVersion(ReleaseVersion) + .When(IsModule, modulePackSettings => modulePackSettings + .SetPackageLicenseUrl(ModuleManifest.LicenseUrl) + .SetPackageProjectUrl(ModuleManifest.ProjectUrl) + .SetPackageIconUrl(ModuleManifest.IconUrl) + .SetPackageRequireLicenseAcceptance(false) + .SetDescription(ModuleManifest.Description) + .SetCopyright(ModuleManifest.Copyright)); + DotNetPack(settings); + }); public Target Test => _ => _ .DependsOn(Compile) @@ -916,7 +930,6 @@ private async Task SendSwaggerSchemaToValidator(HttpClient httpClient, s Logger.Normal("Sonar validation done."); }); - public Target MassPullAndBuild => _ => _ .Requires(() => ModulesFolderPath) .Executes(() => @@ -954,6 +967,7 @@ private void GitLogger(OutputType type, string text) case OutputType.Err: Logger.Error(text); break; + case OutputType.Std: Logger.Info(text); break; @@ -1035,5 +1049,4 @@ private async Task PublishRelease(string owner, string repo, string token, strin { ClearTempBeforeExit = true; }); - }