public static string DetectProjectVersion(DirectoryPath projectPath = null) { if (projectPath == null) { projectPath = Arguments.ProjectPath ?? Context.Environment.WorkingDirectory; } var path = projectPath.MakeAbsolute(Context.Environment); var projectVersion = path.Combine(DirectoryPath.FromString("ProjectSettings")).CombineWithFilePath("ProjectVersion.txt"); if (!Context.FileSystem.GetFile(projectVersion).Exists) { throw new ArgumentException("Project path " + projectPath + " is not a valid Unity project."); } var file = Context.FileSystem.GetFile(projectVersion); var projectVersionText = string.Join("\n", file.ReadLines(Encoding.UTF8)); if (!projectVersionText.StartsWith("m_EditorVersion: ")) { throw new ArgumentException("Project does not contain valid version information."); } return(projectVersionText.Substring("m_EditorVersion: ".Length).Trim()); }
public async Task Should_Download(string workingDirectory, string testPath) { // Given var gitHubActionsCommandsFixture = new GitHubActionsCommandsFixture() .WithWorkingDirectory(workingDirectory); var testDirectoryPath = DirectoryPath.FromString(testPath); var artifactName = "artifact"; var directory = DirectoryPath.FromString("/src/artifacts"); var filePath = directory.CombineWithFilePath("test.txt"); gitHubActionsCommandsFixture .FileSystem .CreateDirectory(directory); var commands = gitHubActionsCommandsFixture.CreateGitHubActionsCommands(); // When await commands.DownloadArtifact(artifactName, testDirectoryPath); var file = gitHubActionsCommandsFixture .FileSystem .GetFile(filePath); // Then Assert.True(file.Exists, $"{filePath.FullPath} doesn't exist."); Assert.Equal("Cake", file.GetTextContent()); }
public Task Should_Shallow_Clone_All_Properties() { var expected = new MinVerSettings { AutoIncrement = MinVerAutoIncrement.Minor, BuildMetadata = "123", DefaultPreReleasePhase = "preview", MinimumMajorMinor = "1.2", Repo = DirectoryPath.FromString("/repo/custom"), TagPrefix = "v", PreferGlobalTool = true, NoFallback = true, Verbosity = MinVerVerbosity.Trace, ToolVerbosity = DotNetVerbosity.Detailed, DiagnosticOutput = true, ToolPath = FilePath.FromString("/tools/custom/minver.exe"), ToolTimeout = TimeSpan.FromMinutes(5), WorkingDirectory = DirectoryPath.FromString("/working/folder"), NoWorkingDirectory = true, ArgumentCustomization = s => s, EnvironmentVariables = new Dictionary <string, string> { { "MINVERTESTVAR", "SOMEVALUE" } }, HandleExitCode = i => false, }; return(Verifier.Verify(expected.Clone())); }
public async Task Should_Upload(string workingDirectory, string testPath) { // Given var gitHubActionsCommandsFixture = new GitHubActionsCommandsFixture() .WithWorkingDirectory(workingDirectory); var testDirectoryPath = DirectoryPath.FromString(testPath); var artifactName = "artifacts"; var directory = DirectoryPath.FromString("/src/artifacts"); gitHubActionsCommandsFixture .FileSystem .CreateFile(directory.CombineWithFilePath("artifact.txt")) .SetContent(artifactName); gitHubActionsCommandsFixture .FileSystem .CreateFile(directory.Combine("folder_a").CombineWithFilePath("artifact.txt")) .SetContent(artifactName); gitHubActionsCommandsFixture .FileSystem .CreateFile(directory.Combine("folder_b").CombineWithFilePath("artifact.txt")) .SetContent(artifactName); gitHubActionsCommandsFixture .FileSystem .CreateFile(directory.Combine("folder_b").Combine("folder_c").CombineWithFilePath("artifact.txt")) .SetContent(artifactName); var commands = gitHubActionsCommandsFixture.CreateGitHubActionsCommands(); // When await commands.UploadArtifact(testDirectoryPath, artifactName); }
internal static DirectoryPath GetOutputPath(this IEnumerable <XElement> configPropertyGroups, XNamespace ns, DirectoryPath rootPath) { return(configPropertyGroups .Elements(ns + ProjectXElement.OutputPath) .Select(outputPath => rootPath.Combine(DirectoryPath.FromString(outputPath.Value))) .FirstOrDefault()); }
public void OneOrMoreDirectoryPath_has_implicit_conversion_from_DirectoryPath() { OneOrMoreDirectoryPaths target = DirectoryPath.FromString("folder"); target.Should().NotBeNull(); target.Count.Should().Be(1); target[0].FullPath.Should().Be("folder"); }
public void Should_Convert_Directory_Path_To_String_Value_Using_FullPath() { var converter = new DirectoryPathConverter(); var result = converter.ConvertTo(DirectoryPath.FromString("c:/data/work"), typeof(string)); Assert.IsType <string>(result); Assert.Equal("c:/data/work", result); }
public void Should_Throw_NotSupportedException_When_Destination_Type_Is_Not_String() { var converter = new DirectoryPathConverter(); var result = Record.Exception(() => converter.ConvertTo(DirectoryPath.FromString("c:/data/work"), typeof(DateTime))); Assert.IsType <NotSupportedException>(result); }
public void OneOrMoreDirectoryPath_has_implicit_conversion_from_DirectoryPath_array() { OneOrMoreDirectoryPaths target = new [] { DirectoryPath.FromString("folder1"), DirectoryPath.FromString("folder2") }; target.Should().NotBeNull(); target.Count.Should().Be(2); target[0].FullPath.Should().Be("folder1"); target[1].FullPath.Should().Be("folder2"); }
public void Should_Shallow_Clone_All_Properties() { var expected = new MinVerSettings { AutoIncrement = MinVerAutoIncrement.Minor, BuildMetadata = "123", DefaultPreReleasePhase = "preview", MinimumMajorMinor = "1.2", Repo = DirectoryPath.FromString("/repo/custom"), TagPrefix = "v", PreferGlobalTool = true, NoFallback = true, Verbosity = MinVerVerbosity.Trace, ToolVerbosity = DotNetCoreVerbosity.Detailed, DiagnosticOutput = true, ToolPath = FilePath.FromString("/tools/custom/minver.exe"), ToolTimeout = TimeSpan.FromMinutes(5), WorkingDirectory = DirectoryPath.FromString("/working/folder"), NoWorkingDirectory = true, ArgumentCustomization = s => s, EnvironmentVariables = new Dictionary <string, string> { { "MINVERTESTVAR", "SOMEVALUE" } }, HandleExitCode = i => false, }; var actual = expected.Clone(); actual.AutoIncrement.Should().Be(expected.AutoIncrement); actual.BuildMetadata.Should().Be(expected.BuildMetadata); actual.DefaultPreReleasePhase.Should().Be(expected.DefaultPreReleasePhase); actual.MinimumMajorMinor.Should().Be(expected.MinimumMajorMinor); actual.Repo.Should().Be(expected.Repo); actual.TagPrefix.Should().Be(expected.TagPrefix); actual.PreferGlobalTool.Should().Be(expected.PreferGlobalTool); actual.NoFallback.Should().Be(expected.NoFallback); actual.Verbosity.Should().Be(expected.Verbosity); actual.ToolVerbosity.Should().Be(expected.ToolVerbosity); actual.DiagnosticOutput.Should().Be(expected.DiagnosticOutput); actual.ToolPath.Should().Be(expected.ToolPath); actual.ToolTimeout.Should().Be(expected.ToolTimeout); actual.WorkingDirectory.Should().Be(expected.WorkingDirectory); actual.NoWorkingDirectory.Should().Be(expected.NoWorkingDirectory); actual.ArgumentCustomization.Should().Be(expected.ArgumentCustomization); actual.EnvironmentVariables.Should().BeEquivalentTo(expected.EnvironmentVariables); actual.HandleExitCode.Should().BeEquivalentTo(expected.HandleExitCode); var properties = typeof(MinVerSettings) .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy) .Select(p => p.Name) .ToList(); // Sanity check & alarm to detect changes in properties that need to be considered in the cloning properties.Should().HaveCount(18); }
static async Task Main(string[] args) { var target = CakeBridge.Context.Argument <string>("target", null); var dbConnectionString = CakeBridge.Context.Argument <string>("dbc", null); Console.WriteLine(target); CakeBridge.Setup(context => { context.Information("Setting up..."); var buildPath = AppDomain.CurrentDomain.BaseDirectory; var rootPath = context.Directory(".").Path.MakeAbsolute(DirectoryPath.FromString(buildPath)).Combine(@"..\.."); /* * * var buildSettingsConfigBuilder = new ConfigurationBuilder().SetBasePath(buildPath) * .AddJsonFile(Path.Combine(buildPath, "buildsettings.json"))*/ return(new BuildData { RootPath = rootPath, ApplicationsSourcePath = rootPath.Combine(@"MergenAPI"), ApplicationsBinPath = rootPath.Combine(@"Projects\Application\Bin"), ApplicationsPublishPath = rootPath.Combine(@"Bin\Publish"), DatabaseSourcePath = rootPath.Combine(@"Database"), DatabaseBinPath = rootPath.Combine(@"Database\Bin"), DatabasePublishPath = rootPath.Combine(@"Database\Bin\Publish"), }); }); CakeBridge.Teardown(context => { context.Information("Tearing down..."); }); var projects = new List <IProject> { new GameApi(), new AdminApi() }; foreach (var project in projects) { project.AddTasks(); } if (string.IsNullOrWhiteSpace(target)) { Console.Error.WriteLine("No targets specified. available targets are: {0}", string.Join(", ", CakeBridge.Tasks.Select(q => q.Name))); return; } await Task.WhenAll(target.Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(CakeBridge.RunTargetAsync)); }
public override void Run(Context context) { var toDelete = context.GetDirectories("./**/obj") - context.MakeAbsolute(DirectoryPath.FromString("./_build/obj")) + context.GetDirectories("./**/bin") - context.MakeAbsolute(DirectoryPath.FromString("./_build/bin")) + context.GetDirectories("./**/packages"); context.CleanDirectories(toDelete); }
public static DirectoryPath GetRootDirectory() { var currentPath = DirectoryPath.FromString(Directory.GetCurrentDirectory()); while (!Directory.Exists(currentPath.Combine(".git").FullPath)) { currentPath = DirectoryPath.FromString(Directory.GetParent(currentPath.FullPath)?.FullName); } return(currentPath); }
public async Task Should_Throw_If_ArtifactName_Is_Null() { // Given var commands = new GitHubActionsCommandsFixture().CreateGitHubActionsCommands(); var path = DirectoryPath.FromString("/artifacts"); // When var result = await Record.ExceptionAsync(() => commands.DownloadArtifact(null, path)); // Then AssertEx.IsArgumentNullException(result, "artifactName"); }
public static void DeleteDirectory(string relativePath) { try { var fullPath = DirectoryPath.FromString(relativePath); Directory.Delete(fullPath.FullPath, true); } catch (Exception) { // We simply swallow the exception } }
public void Should_Set_BaseDirectory() { // Given var fixture = new GitLink3Fixture(); fixture.Settings.BaseDir = DirectoryPath.FromString("pdb/"); // Then var result = fixture.Run(); // Then Assert.Equal("--baseDir \"/Working/pdb\" \"c:/temp/my.pdb\"", result.Args); }
public void Should_Upload_Directory_As_Container() { // Given var fixture = new TFBuildFixture(); var service = fixture.CreateTFBuildService(); var path = DirectoryPath.FromString("./artifacts/Packages").MakeAbsolute(fixture.Environment).FullPath; // When service.Commands.UploadArtifactDirectory("./artifacts/Packages"); // Then Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[artifact.upload containerfolder=Packages;artifactname=Packages;]{path}"); }
public void Should_Upload_Directory_As_Container_Artifact() { // Given var fixture = new AzurePipelinesFixture(); var service = fixture.CreateAzurePipelinesService(); var path = DirectoryPath.FromString("./artifacts/Packages").MakeAbsolute(fixture.Environment).FullPath; // When service.Commands.UploadArtifactDirectory("./artifacts/Packages", "NuGet"); // Then Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[artifact.upload containerfolder=NuGet;artifactname=NuGet;]{path}"); }
public void Should_Set_Source_Directories() { // Given var fixture = new ReportGeneratorRunnerFixture(); fixture.Settings.SourceDirectories = new[] { DirectoryPath.FromString("source1"), DirectoryPath.FromString("/source2") }; // When var result = fixture.Run(); // Then Assert.Equal("\"-reports:/Working/report.xml\" \"-targetdir:/Working/output\" \"-sourcedirs:/Working/source1;/source2\"", result.Args); }
public void Should_Set_PdbDirectory() { // Given var fixture = new GitLinkFixture(); fixture.Settings.PdbDirectoryPath = DirectoryPath.FromString("pdb/"); // Then var result = fixture.Run(); // Then Assert.Equal("\"c:/temp\" -d \"/Working/pdb\"", result.Args); }
public void Should_Set_Caches_Home() { // Given var fixture = new DupFinderRunnerFixture(); fixture.Settings.CachesHome = DirectoryPath.FromString("caches/"); // Then var result = fixture.Run(); // Then Assert.Equal("\"/caches-home=/Working/caches\" \"/Working/Test.sln\"", result.Args); }
public async Task Should_Throw_If_Directory_Missing() { // Given var commands = new GitHubActionsCommandsFixture().CreateGitHubActionsCommands(); var path = DirectoryPath.FromString("/artifacts"); var artifactName = "artifact"; // When var result = await Record.ExceptionAsync(() => commands.DownloadArtifact(artifactName, path)); // Then AssertEx.IsExceptionWithMessage <DirectoryNotFoundException>(result, "Local directory /artifacts not found."); }
public void DirectoryIsCreatedIfItDoesNotExist() { // arrange var logDummy = new CakeLogFixture(); var directory = Guid.NewGuid().ToString(); var directoryPath = DirectoryPath.FromString(directory); Directory.Exists(directory).Should().BeFalse(); // act directoryPath.CheckAndCreateDirectory(logDummy); // assert Directory.Exists(directory).Should().BeTrue(); DirectoryHelper.DeleteDirectory(directory); }
public void Should_Set_Caches_Home() { // Given var fixture = new DupFinderRunnerFixture(); var runner = fixture.CreateRunner(); // Then runner.Run(new[] { FilePath.FromString("./Test.sln") }, new DupFinderSettings { CachesHome = DirectoryPath.FromString("caches/") }); // Then fixture.ProcessRunner.Received(1).Start( Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()); Assert.Equal("\"/caches-home=/Working/caches\" \"/Working/Test.sln\"", fixture.ProcessArguments); }
/// <summary> /// Clones the coverlet settings to a new instance /// </summary> /// <returns></returns> public CoverletSettings Clone() { return(new CoverletSettings { CollectCoverage = CollectCoverage, CoverletOutputFormat = CoverletOutputFormat, Threshold = Threshold, ThresholdType = ThresholdType, CoverletOutputDirectory = CoverletOutputDirectory == null ? null : DirectoryPath.FromString(CoverletOutputDirectory.FullPath), CoverletOutputName = CoverletOutputName, Include = new List <string>(Include), ExcludeByFile = new List <string>(ExcludeByFile), ExcludeByAttribute = new List <string>(ExcludeByAttribute), Exclude = new List <string>(Exclude), MergeWithFile = MergeWithFile == null ? null : FilePath.FromString(MergeWithFile.FullPath), OutputTransformer = OutputTransformer }); }
public void Should_Return_Empty_If_Package_Directory_Does_Not_Exist() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); var log = Substitute.For <ICakeLog>(); var assemblyCompatibilityFilter = Substitute.For <INuGetAssemblyCompatibilityFilter>(); var locator = new NuGetPackageAssembliesLocator(fileSystem, log, assemblyCompatibilityFilter, environment); var addinDirectory = DirectoryPath.FromString("/NonExistentDir"); // When var result = locator.FindAssemblies(addinDirectory); // Then Assert.Empty(result); }
public void Should_Throw_If_Package_Directory_Is_Not_Absolute() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fileSystem = new FakeFileSystem(environment); var log = Substitute.For <ICakeLog>(); var assemblyCompatibilityFilter = Substitute.For <INuGetAssemblyCompatibilityFilter>(); var locator = new NuGetPackageAssembliesLocator(fileSystem, log, assemblyCompatibilityFilter, environment); var addinDirectory = DirectoryPath.FromString("RelativeDirPath"); Assert.True(addinDirectory.IsRelative); // When var result = Record.Exception(() => locator.FindAssemblies(addinDirectory)); // Then Assert.IsCakeException(result, "Package directory (RelativeDirPath) must be an absolute path."); }
/// <summary> /// Gets the alternative tool paths. /// </summary> /// <param name="settings">The settings.</param> /// <returns></returns> protected override IEnumerable <FilePath> GetAlternativeToolPaths(TSettings settings) { var iisExpressRegistryKey = _registry.LocalMachine.OpenKey(@"SOFTWARE\Microsoft\IISExpress"); if (iisExpressRegistryKey == null) { throw new CakeException("IIS Express is not installed on this machine."); } var latestVersion = iisExpressRegistryKey.GetSubKeyNames().OrderByDescending(decimal.Parse).First(); var installPath = iisExpressRegistryKey.OpenKey(latestVersion).GetValue("InstallPath").ToString(); var toolPath = DirectoryPath.FromString(installPath).CombineWithFilePath("iisexpress.exe"); yield return(toolPath); }
public void Should_Publish_Code_Coverage() { // Given var fixture = new TFBuildFixture(); var service = fixture.CreateTFBuildService(); var data = new TFBuildPublishCodeCoverageData { CodeCoverageTool = TFCodeCoverageToolType.Cobertura, SummaryFileLocation = FilePath.FromString("./coverage/cobertura-coverage.xml").ToString(), ReportDirectory = DirectoryPath.FromString("./coverage/report").ToString() }; // When service.Commands.PublishCodeCoverage(data); // Then const string expected = @"##vso[codecoverage.publish codecoveragetool=Cobertura;summaryfile=C:\build\CAKE-CAKE-JOB1\coverage\cobertura-coverage.xml;reportdirectory=C:\build\CAKE-CAKE-JOB1\coverage\report;]"; var actual = fixture.Log.Entries.FirstOrDefault(); Assert.Equal(expected, actual?.Message); }
private static DirectoryPath GetFromGroup(DirectoryPath path, PackageReference package) { const string mainGroup = "main"; const string key = "group"; const string packages = "packages"; var parameters = package.Parameters; if (parameters.ContainsKey(key)) { var group = parameters[key].Single(); var folders = path.Segments; var newFolders = new List <string>(); foreach (var f in folders) { if (f.Equals(packages)) { break; } newFolders.Add(f); } newFolders.Add(packages); var packageDirectory = DirectoryPath.FromString(string.Join("/", newFolders)); if (group.Equals(mainGroup)) { return(packageDirectory); } var groupDirectory = DirectoryPath.FromString(group); return(packageDirectory.Combine(groupDirectory)); } return(null); }