public void ApplySettings(IActivityMonitor m) { if (!this.CheckCurrentBranch(m)) { return; } var solution = _solutionDriver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } var csprojs = solution.Projects.Select <IProject, (IProject project, MSProject msproject)>(p => (p, p.Tag <MSProject>())).Where(p => p.Item2 != null); foreach ((IProject project, MSProject msproject) in csprojs) { if (project.IsPublished) { // For test projects we want the IsPackable element to be explicit. msproject.SetIsPackable(m, project.IsTestProject ? true : (bool?)null); } else { msproject.SetIsPackable(m, false); } // Saves the project. msproject.Save(m); } }
public void ApplySettings(IActivityMonitor m) { if (!_f.EnsureDirectory(m)) { return; } var solution = _solutionDriver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } var slnFile = solution.Tag <SolutionFile>(); MSProject ccbProject = slnFile.MSProjects.SingleOrDefault(p => p.ProjectName == "CodeCakeBuilder"); if (ccbProject == null) { m.Error($"Missing CodeCakeBuilder project in '{slnFile.FilePath}'."); return; } // This is the baseline of CCB. // This should be modeled in the world xml. var framework = MSProject.Savors.FindOrCreate("netcoreapp3.1"); var dependencies = new[] {
public void ApplySettings(IActivityMonitor m) { if (!_f.EnsureDirectory(m)) { return; } var s = _driver.GetSolution(m, allowInvalidSolution: true); if (s == null) { return; } if (_driver.BuildRequiredSecrets.Count == 0) { m.Warn("No build secrets collected for this solution. Skipping KeyVault configuration."); return; } var passPhrase = _secretStore.GetSecretKey(m, SolutionDriver.CODECAKEBUILDER_SECRET_KEY, true); // Opens the actual current vault: if more secrets are defined we keep them. Dictionary <string, string> current = KeyVault.DecryptValues(TextContent, passPhrase); current.Clear(); // The central CICDKeyVault is protected with the same CODECAKEBUILDER_SECRET_KEY secret. Dictionary <string, string> centralized = KeyVault.DecryptValues(_sharedState.CICDKeyVault, passPhrase); bool complete = true; foreach (var name in _driver.BuildRequiredSecrets.Select(x => x.SecretKeyName)) { if (!centralized.TryGetValue(name, out var secret)) { m.Error($"Missing required build secret '{name}' in central CICDKeyVault. It must be added."); complete = false; } else { current[name] = secret; } } if (complete) { Updating?.Invoke(this, new CodeCakeBuilderKeyVaultUpdatingArgs(m, _solutionSpec, s, current)); string result = KeyVault.EncryptValuesToString(current, passPhrase); CreateOrUpdate(m, result); } }
protected override void DoApplySettings(IActivityMonitor m) { var solution = _driver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } var projects = _npmDriver.GetNPMProjects(m); if (projects == null) { return; } bool useNpm = projects.Any(); if (useNpm) { //CakeExtensions SetTextResource(m, "CakeExtensions/NpmDistTagRunner.cs"); SetTextResource(m, "CakeExtensions/NpmView.cs"); SetTextResource(m, "CakeExtensions/NpmGetNpmVersion.cs"); //npm itself SetTextResource(m, "npm/Build.NPMArtifactType.cs", text => AdaptBuildNPMArtifactForPushFeeds(text, solution)); SetTextResource(m, "npm/Build.NPMFeed.cs"); SetTextResource(m, "npm/NPMProject.cs"); SetTextResource(m, "npm/NPMPublishedProject.cs"); SetTextResource(m, "npm/NPMSolution.cs"); SetTextResource(m, "npm/NPMProjectContainer.cs"); SetTextResource(m, "npm/TempFileTextModification.cs"); SetTextResource(m, "npm/SimplePackageJsonFile.cs"); SetTextResource(m, "npm/AngularWorkspace.cs"); } else { m.Info("Removing build files related to NPM handling."); DeleteFile(m, "CakeExtensions/NpmDistTagRunner.cs"); DeleteFile(m, "CakeExtensions/NpmView.cs"); DeleteFile(m, "CakeExtensions/NpmGetNpmVersion.cs"); DeleteFile(m, "npm/Build.NPMArtifactType.cs"); DeleteFile(m, "npm/Build.NPMFeed.cs"); DeleteFile(m, "npm/NPMProject.cs"); DeleteFile(m, "npm/NPMPublishedProject.cs"); DeleteFile(m, "npm/NPMSolution.cs"); } }
public void ApplySettings(IActivityMonitor m) { if (_solutionSpec.NoSharedPropsFile) { Delete(m); return; } if (!_commonFolder.EnsureDirectory(m)) { return; } var s = _driver.GetSolution(m, false); if (s == null) { return; } bool useCentralPackage = s.Projects.Select(p => p.Tag <MSBuildSln.MSProject>()) .Where(p => p != null) .Any(p => p.UseMicrosoftBuildCentralPackageVersions); // If Shared.props exists, we make sure there is no xml namespace defined. if (Document == null) { Document = new XDocument(new XElement("Project")); } else { Document.Root.RemoveAllNamespaces(); } HandleBasicDefinitions(m, useCentralPackage); HandleStandardProperties(m); XCommentSection.FindOrCreate(Document.Root, "ReproducibleBuilds", false)?.Remove(); HandleZeroVersion(m); HandleGenerateDocumentation(m); HandleSourceLink(m, useCentralPackage); Document.Root.Elements("PropertyGroup") .Where(e => !e.HasElements) .Select(e => e.ClearCommentsBeforeAndNewLineAfter()) .Remove(); Save(m); }
protected override void DoApplySettings(IActivityMonitor m) { var s = _driver.GetSolution(m, allowInvalidSolution: true); if (s == null) { return; } bool dotNet = s.Projects.Any(p => !p.IsBuildProject && p.Type == ".Net"); if (_settings.NoStrongNameSigning || !dotNet) { DeleteFile(m, "SharedKey.snk"); } else { SetBinaryResource(m, "SharedKey.snk"); } }
protected override void DoApplySettings(IActivityMonitor m) { var s = _driver.GetSolution(m, allowInvalidSolution: true); if (s == null) { return; } bool produceCKSetupComponents = s.GeneratedArtifacts.Any(g => g.Artifact.Type == CKSetupClient.CKSetupType); if (produceCKSetupComponents == true) { m.Info("Adding Build.StandardPushCKSetupComponents.cs since CKSetup components are produced."); SetTextResource(m, "Build.StandardPushCKSetupComponents.cs", text => AdaptStandardStandardPushCKSetupComponents(m, s, text)); } else { DeleteFile(m, "Build.StandardPushCKSetupComponents.cs"); } }
public void ApplySettings(IActivityMonitor m) { if (!_f.EnsureDirectory(m)) { return; } var solution = _solutionDriver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } var slnFile = solution.Tag <SolutionFile>(); MSProject ccbProject = slnFile.MSProjects.SingleOrDefault(p => p.ProjectName == "CodeCakeBuilder"); if (ccbProject == null) { m.Error($"Missing CodeCakeBuilder project in '{slnFile.FilePath}'."); return; } //slnFile.Save( m );//TODO }
protected override void DoApplySettings(IActivityMonitor m) { var solution = _driver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } bool hasDotNetPackages = solution.GeneratedArtifacts.Any(g => g.Artifact.Type == NuGetClient.NuGetType); if (hasDotNetPackages) { SetTextResource(m, "dotnet/Build.NuGetArtifactType.cs", text => AdaptBuildNugetRepositoryForPushFeeds(text, solution)); SetTextResource(m, "dotnet/Build.NuGetHelper.cs"); } else { m.Info("Removing build files related to NuGet packaging."); DeleteFile(m, "dotnet/Build.NuGetArtifactType.cs"); DeleteFile(m, "dotnet/Build.NuGetHelper.cs"); DeleteFile(m, "dotnet/Build.StandardCreateNuGetPackages.cs"); } }
protected override void DoApplySettings(IActivityMonitor m) { var s = _driver.GetSolution(m, allowInvalidSolution: true); if (s == null) { return; } bool needDotNetBuild = s.Projects.Any(p => p.Type == ".Net" && p != s.BuildProject); // Clean old CodeCakeBuilders files DeleteFile(m, "Build.NuGetHelper.cs"); DeleteFile(m, "Build.StandardCheckRepository.cs"); DeleteFile(m, "Build.StandardCreateNuGetPackages.cs"); DeleteFile(m, "Build.StandardPushNuGetPackages.cs"); DeleteFile(m, "Build.StandardSolutionBuild.cs"); DeleteFile(m, "Build.StandardUnitTests.cs"); DeleteFile(m, "Build.StandardCheckRepositoryWithoutNuGet.cs"); DeleteFile(m, "CakeExtensions/NpmGetPackagesToPublish.cs"); DeleteFile(m, "Build.SetCIVersionOnRunner.cs"); DeleteFile(m, "npm/Build.NpmHelper.cs"); DeleteFile(m, "Abstractions/ArtifactRepository.cs"); DeleteFile(m, "dotnet/Build.NugetRepository.cs"); DeleteFile(m, "dotnet/Build.StandardCheckRepository.cs"); DeleteFile(m, "dotnet/Build.StandardPushNuGetPackages.cs"); DeleteFile(m, "CakeExtensions/NpmGet.cs"); DeleteFile(m, "npm/Build.NpmRepository.cs"); DeleteFile(m, "npm/Build.StandardNpmBuild.cs"); DeleteFile(m, "npm/Build.StandardNpmUnitTests.cs"); DeleteFile(m, "Abstractions/ISolutionProducingArtifact.cs"); DeleteFile(m, "Abstractions/ISolution.cs"); // Root files SetTextResource(m, "InstallCredentialProvider.ps1"); SetTextResource(m, "Program.cs"); SetTextResource(m, "StandardGlobalInfo.cs"); SetTextResource(m, "Build.CreateStandardGlobalInfo.cs"); UpdateTextResource(m, "Build.cs", t => AdaptBuild(m, s, t)); // Abstractions files SetTextResource(m, "Abstractions/Artifact.cs"); SetTextResource(m, "Abstractions/ArtifactFeed.cs"); SetTextResource(m, "Abstractions/ArtifactInstance.cs"); SetTextResource(m, "Abstractions/ArtifactPush.cs"); SetTextResource(m, "Abstractions/ArtifactType.cs"); SetTextResource(m, "Abstractions/ILocalArtifact.cs"); SetTextResource(m, "Abstractions/ICIPublishWorkflow.cs"); SetTextResource(m, "Abstractions/ICIWorkflow.cs"); if (needDotNetBuild) { SetTextResource(m, "dotnet/DotnetSolution.cs"); } else { m.Info("Removing all files for .Net projects."); DeleteFile(m, "dotnet/DotnetSolution.cs"); DeleteFile(m, "dotnet/Build.StandardSolutionBuild.cs"); DeleteFile(m, "dotnet/Build.NuGetArtifactType.cs"); DeleteFile(m, "dotnet/Build.NuGetHelper.cs"); DeleteFile(m, "dotnet/Build.StandardCreateNuGetPackages.cs"); DeleteFile(m, "dotnet/Build.StandardUnitTests.cs"); } }
public IReadOnlyList <NPMProject> GetNPMProjects(IActivityMonitor m) { return(_driver.GetSolution(m, allowInvalidSolution: true) != null ? _npmProjects : null); }
public void ApplySettings(IActivityMonitor m) { if (!this.CheckCurrentBranch(m)) { return; } var solution = _solutionDriver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } EnsureDocument(); PackageSources.EnsureFirstElement("clear"); foreach (var s in solution.ArtifactSources.OfType <INuGetFeed>()) { EnsureFeed(m, s.Name, s.Url); if (s.Credentials != null) { string password = s.Credentials.IsSecretKeyName ? _secretStore.GetSecretKey(m, s.Credentials.PasswordOrSecretKeyName, throwOnUnavailable: false) : s.Credentials.PasswordOrSecretKeyName; if (password != null) { EnsureFeedCredentials(m, s.Name, s.Credentials.UserName, password); } else { if (s.Credentials.IsSecretKeyName) { m.Warn($"Secret '{s.Credentials.PasswordOrSecretKeyName}' is not known. Configuration for feed '{s.Name}' skipped."); } else { m.Warn($"Empty feed password. Configuration for feed '{s.Name}' skipped."); } } } else { DeleteFeedCredentials(m, s.Name); } } var packages = EnsureDocument().Root.Element("packageSourceCredentials"); if (!packages?.Nodes().Any() ?? false) { packages.Remove(); } foreach (var name in _solutionSpec.RemoveNuGetSourceNames) { RemoveFeed(m, name, withCredentials: true); } // Cleanup if ever needed. RemoveFeed(m, "ZeroBuild-Feed"); if (IsOnLocalBranch) { EnsureLocalFeeds(m); } else { RemoveLocalFeeds(m); } Save(m); }
public void ApplySettings(IActivityMonitor m) { if (!this.CheckCurrentBranch(m)) { return; } YamlMapping firstMapping = GetFirstMapping(m, true); if (firstMapping == null) { return; } var solution = _driver.GetSolution(m, allowInvalidSolution: true); if (solution == null) { return; } // We don't use AppVeyor for private repositories. if (!GitFolder.IsPublic) { if (TextContent != null) { m.Log(LogLevel.Info, "The project is private, so we don't use Appveyor and the Appveyor.yml is not needed."); Delete(m); } return; } // We currently always use AppVeyor when the repository is public. YamlMapping env = FindOrCreateYamlElement(m, firstMapping, "environment"); if (env == null) { return; } var passphrase = _keyStore.GetSecretKey(m, SolutionDriver.CODECAKEBUILDER_SECRET_KEY, false); if (passphrase != null) { var central = KeyVault.DecryptValues(_sharedState.CICDKeyVault, passphrase); if (central.TryGetValue(APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY, out var appveyorSecure)) { env[SolutionDriver.CODECAKEBUILDER_SECRET_KEY] = CreateKeyValue("secure", appveyorSecure); } else { m.Warn($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure key has been skipped: {APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY} key should be defined in CICDKeyVault."); } } else { m.Info($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure skipped."); } // Remove obsolete environment variables definitions. env.Remove("NUGET_API_KEY"); env.Remove("MYGET_RELEASE_API_KEY"); env.Remove("MYGET_PREVIEW_API_KEY"); env.Remove("MYGET_CI_API_KEY"); env.Remove("CK_DB_TEST_MASTER_CONNECTION_STRING"); env.Remove("AZURE_FEED_SIGNATURE_OPENSOURCE_PAT"); env.Remove("AZURE_FEED_PAT"); env.Remove("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS"); if (_solutionSpec.SqlServer != null) { env["SqlServer/MasterConnectionString"] = new YamlValue($"Server=(local)\\SQL{_solutionSpec.SqlServer.ToUpperInvariant()};Database=master;User ID=sa;Password=Password12!"); } // firstMapping.Remove(new YamlValue("init")); if (_solutionSpec.SqlServer != null) { firstMapping["services"] = new YamlValue("mssql" + _solutionSpec.SqlServer.ToLowerInvariant()); } var install = new YamlSequence(); // Temporary: installs the 6.9.0 of npm. if (solution.GeneratedArtifacts.Any(g => g.Artifact.Type.Name == "NPM")) { install.Add(CreateKeyValue("cmd", "npm install -g [email protected]")); install.Add(CreateKeyValue("ps", "Install-Product node 12")); } firstMapping["install"] = install; firstMapping["version"] = new YamlValue("build{build}"); firstMapping["image"] = new YamlValue("Visual Studio 2019"); firstMapping["clone_folder"] = new YamlValue("C:\\CKli-World\\" + GitFolder.SubPath.Path.Replace('/', '\\')); EnsureDefaultBranches(firstMapping); SetSequence(firstMapping, "build_script", new YamlValue("dotnet run --project CodeCakeBuilder -nointeraction")); firstMapping["test"] = new YamlValue("off"); firstMapping["artifacts"] = new YamlSequence() { new YamlMapping() { ["path"] = new YamlValue(@"'**\*.log'"), ["name"] = new YamlValue("Log file") }, new YamlMapping() { ["path"] = new YamlValue(@"'**\*.trx'"), ["name"] = new YamlValue("Visual studio test results file") }, new YamlMapping() { ["path"] = new YamlValue(@"'**\Tests\**\TestResult*.xml'"), ["name"] = new YamlValue("NUnit tests result files") }, new YamlMapping() { ["path"] = new YamlValue(@"'**Tests\**\Logs\**\*'"), ["name"] = new YamlValue("Log files") } }; CreateOrUpdate(m, YamlMappingToString(m)); }
void DoApplySettings(IActivityMonitor m, NormalizedPath f) { var s = _solutionDriver.GetSolution(m, allowInvalidSolution: true); if (s == null) { return; } string text = GitFolder.FileSystem.GetFileInfo(f).AsTextFileInfo(ignoreExtension: true)?.TextContent ?? String.Empty; List <Line> lines = _rLine.Matches(text) .Cast <Match>() .Select(l => l.Groups[2].Length > 0 ? new Line(l.Groups[1].Value, l.Groups[2].Value) : new Line(l.Value)) .ToList(); lines.RemoveAll(p => p.FullKey == "scope"); //remove all keyvalues scopes. foreach (var p in s.ArtifactSources.OfType <INPMFeed>()) { if (p.Url.StartsWith("file:")) { m.Info("Npm does not support file repository. Skipping."); continue; } EnsureLine(lines, p.Scope, "registry", p.Url); // Scope doesn't carry auth info: lines.RemoveAll(line => line.FullKey == p.Scope + ":username"); lines.RemoveAll(line => line.FullKey == p.Scope + ":always-auth"); lines.RemoveAll(line => line.FullKey == p.Scope + ":_password"); Uri uri = new Uri(p.Url); if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) { throw new Exception($"NPM registry url must start with 'https://': {p.Url}"); } // Auth is carried by registry url (from which 'http(s):' prefix is removed). var scopeUrl = p.Url.Substring("https:".Length); if (p.Credentials != null) { EnsureLine(lines, scopeUrl, "username", p.Credentials.UserName); EnsureLine(lines, scopeUrl, "always-auth", "true"); string password = p.Credentials.IsSecretKeyName ? _secretStore.GetSecretKey(m, p.Credentials.PasswordOrSecretKeyName, false) : p.Credentials.PasswordOrSecretKeyName; if (password == null) { if (p.Credentials.IsSecretKeyName) { m.Warn($"Secret '{p.Credentials.PasswordOrSecretKeyName}' is not known. Configuration for feed '{s.Name}' skipped."); } else { m.Warn($"Empty feed password. Configuration for feed '{s.Name}' skipped."); } continue; } if (p.Url.IndexOf("dev.azure.com", StringComparison.OrdinalIgnoreCase) >= 0) { password = Convert.ToBase64String(Encoding.UTF8.GetBytes(password)); } EnsureLine(lines, scopeUrl, "_password", password); } else { // Cleanup any auth info. lines.RemoveAll(line => line.FullKey == scopeUrl + ":username"); lines.RemoveAll(line => line.FullKey == scopeUrl + ":always-auth"); lines.RemoveAll(line => line.FullKey == scopeUrl + ":_password"); } } ; EnsureLine(lines, "git-tag-version", "false"); lines.RemoveAll(line => line.Scope != null && _solutionSpec.RemoveNPMScopeNames.Contains(line.Scope)); GitFolder.FileSystem.CopyTo(m, lines.Select(l => l.ToString()).Concatenate("\r\n"), f); }