Skip to content

Commit

Permalink
VCI-98: Fix bin and obj directories search in Clean target (#10)
Browse files Browse the repository at this point in the history
* VCI-98: Fix bin and obj directories search in Clean target

* VCI-98: Fix codesmells
  • Loading branch information
krankenbro authored Aug 13, 2021
1 parent 5b14c7c commit 1f71c51
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -75,7 +74,7 @@ public static int Main()
{
FileSystemTasks.DeleteDirectory(TemporaryDirectory);
}

var exitCode = Execute<Build>(x => x.Compile);
return _exitCode ?? exitCode;
}
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -916,7 +930,6 @@ private async Task<string> SendSwaggerSchemaToValidator(HttpClient httpClient, s
Logger.Normal("Sonar validation done.");
});


public Target MassPullAndBuild => _ => _
.Requires(() => ModulesFolderPath)
.Executes(() =>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1035,5 +1049,4 @@ private async Task PublishRelease(string owner, string repo, string token, strin
{
ClearTempBeforeExit = true;
});

}

0 comments on commit 1f71c51

Please sign in to comment.