Beispiel #1
0
        /// <summary>
        /// Ensure that a branch exists.
        /// </summary>
        /// <param name="m">The monitor.</param>
        /// <param name="r">The repository.</param>
        /// <param name="branchName">The name of the branch.</param>
        /// <param name="noWarnOnCreate">Log as warning if the branch is created.</param>
        /// <param name="repoDisplayName">Name of the repo displayed in the logs.</param>
        /// <returns>The Branch.</returns>
        static Branch DoEnsureBranch(IActivityMonitor m, Repository r, string branchName, bool noWarnOnCreate, string repoDisplayName)
        {
            if (String.IsNullOrWhiteSpace(branchName))
            {
                throw new ArgumentNullException(nameof(branchName));
            }
            var b = DoGetBranch(m, r, branchName, logErrorMissingLocalAndRemote: false, repoDisplayName: repoDisplayName);

            if (b == null)
            {
                m.Log(noWarnOnCreate ? Core.LogLevel.Info : Core.LogLevel.Warn, $"Branch '{branchName}' does not exist. Creating local branch.");;
                b = r.CreateBranch(branchName);
            }
            return(b);
        }
 void DumpSources(IActivityMonitor monitor, LogLevel level)
 {
     if (Sources != null && Sources.Count > 0)
     {
         using (monitor.OpenGroup(level, $"Processed {Sources.Count} source tree(s):"))
         {
             for (int i = 0; i < Sources.Count; ++i)
             {
                 using (monitor.OpenGroup(level, $"Source n°{i}"))
                 {
                     monitor.Log(level, Sources[i].ToString());
                 }
             }
         }
     }
 }
Beispiel #3
0
        public void ApplySettings(IActivityMonitor m)
        {
            if (!this.CheckCurrentBranch(m))
            {
                return;
            }
            YamlMapping firstMapping = GetFirstMapping(m, true);

            if (firstMapping == null)
            {
                m.Error("First mapping should not return null !");
                return;
            }
            // We don't use GitLab for public repositories
            if (GitFolder.IsPublic || GitFolder.KnownGitProvider != KnownGitProvider.GitLab)
            {
                if (TextContent != null)
                {
                    m.Log(LogLevel.Info, "The project is public or the repository is not on GitLab, so we don't use GitLab and the .gitlab-ci.yml is not needed.");
                    Delete(m);
                }
                return;
            }
            // We use GitLab when the repository is private.
            YamlMapping codeCakeJob = FindOrCreateYamlElement(m, firstMapping, "codecakebuilder");

            SetSequence(codeCakeJob, "tags", new YamlValue("windows"));
            SetSequence(codeCakeJob, "script",
                        new YamlValue("dotnet run --project CodeCakeBuilder -nointeraction")
                        );
            codeCakeJob["artifacts"] =
                new YamlMapping()
            {
                ["paths"] = new YamlSequence()
                {
                    new YamlValue(@"'**\*.log'"),
                    new YamlValue(@"'**\*.trx'"),
                    new YamlValue(@"'**\Tests\**\TestResult*.xml'"),
                    new YamlValue(@"'**Tests\**\Logs\**\*'"),
                },
                ["when"]      = new YamlValue("always"),
                ["expire_in"] = new YamlValue("6 month")
            };
            CreateOrUpdate(m, YamlMappingToString(m));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        /// <summary>
        /// Retrieves a <see cref="IStObjAttribute"/> from (potentially multiple) attributes on a type.
        /// If multiple attributes are defined, <see cref="IStObjAttribute.Requires"/>, <see cref="IStObjAttribute.Children"/>, and <see cref="IStObjAttribute.RequiredBy"/>
        /// are merged, but if their <see cref="IStObjAttribute.Container"/> are not null or if <see cref="IStObjAttribute.ItemKind"/> is not <see cref="DependentItemKind.Unknown"/> and differ, the
        /// first one is kept and a log is emitted in the <paramref name="monitor"/>.
        /// </summary>
        /// <param name="objectType">The type for which the attribute must be found.</param>
        /// <param name="monitor">Logger that will receive the warning.</param>
        /// <param name="multipleContainerLogLevel"><see cref="CK.Core.LogLevel"/> when different containers are detected. By default a warning is emitted.</param>
        /// <returns>
        /// Null if no <see cref="IStObjAttribute"/> is set.
        /// </returns>
        static internal IStObjAttribute?GetStObjAttributeForExactType(Type objectType, IActivityMonitor monitor, LogLevel multipleContainerLogLevel = LogLevel.Warn)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }
            if (monitor == null)
            {
                throw new ArgumentNullException("monitor");
            }

            var a = (IStObjAttribute[])objectType.GetCustomAttributes(typeof(IStObjAttribute), false);

            if (a.Length == 0)
            {
                return(null);
            }
            if (a.Length == 1)
            {
                return(a[0]);
            }

            IList <Type>?         requires   = null;
            IList <Type>?         requiredBy = null;
            IList <Type>?         children   = null;
            IList <Type>?         group      = null;
            DependentItemKindSpec itemKind   = DependentItemKindSpec.Unknown;
            Type?           container        = null;
            IStObjAttribute?containerDefiner = null;

            foreach (IStObjAttribute attr in a)
            {
                if (attr.Container != null)
                {
                    if (container == null)
                    {
                        containerDefiner = attr;
                        container        = attr.Container;
                    }
                    else
                    {
                        Debug.Assert(containerDefiner != null && containerDefiner.Container != null);
                        monitor.Log(multipleContainerLogLevel, $"Attribute {attr.GetType().Name} for type {objectType} specifies Container type '{attr.Container.Name}' but attribute {containerDefiner.GetType().Name} specifies Container type '{containerDefiner.Container.Name}'. Container remains '{containerDefiner.Container.Name}'.");
                    }
                }
                if (attr.ItemKind != DependentItemKindSpec.Unknown)
                {
                    if (itemKind != DependentItemKindSpec.Unknown)
                    {
                        monitor.Warn($"ItemKind is already set to '{itemKind}'. Value '{attr.ItemKind}' set by {attr.GetType().Name} is ignored.");
                    }
                    else
                    {
                        itemKind = attr.ItemKind;
                    }
                }
                CombineTypes(ref requires, attr.Requires);
                CombineTypes(ref requiredBy, attr.RequiredBy);
                CombineTypes(ref children, attr.Children);
                CombineTypes(ref group, attr.Groups);
            }
            var r = new StObjAttribute()
            {
                Container = container, ItemKind = itemKind
            };

            if (requires != null)
            {
                r.Requires = requires.ToArray();
            }
            if (requiredBy != null)
            {
                r.RequiredBy = requiredBy.ToArray();
            }
            if (children != null)
            {
                r.Children = children.ToArray();
            }
            if (group != null)
            {
                r.Groups = group.ToArray();
            }
            return(r);
        }