Exemplo n.º 1
0
        public NuGetPackerFixture()
        {
            NuSpecFilePath = "./existing.nuspec";
            Settings       = new NuGetPackSettings();

            FileSystem.GetCreatedFile("/Working/existing.nuspec", Resources.Nuspec_NoMetadataValues);
        }
Exemplo n.º 2
0
        public static Version ParseAndUpdateVersion(
            this ICakeContext context,
            FilePath pathToFile,
            AssemblyInfoSettings assemblyInfoSettings           = null,
            DotNetCoreMSBuildSettings dotNetCoreMSBuildSettings = null,
            NuGetPackSettings nuGetPackSettings       = null,
            ReleaseNotesSettings releaseNotesSettings = null)
        {
            var version = context.ParseVersionFrom(pathToFile);

            if (!(assemblyInfoSettings is null))
            {
                context.UpdateAssemblyInfoVersion(version, assemblyInfoSettings);
            }

            if (!(dotNetCoreMSBuildSettings is null))
            {
                context.UpdateDotNetCoreBuildVersion(version, dotNetCoreMSBuildSettings);
            }

            if (!(nuGetPackSettings is null))
            {
                context.UpdateNuGetPackVersion(version, nuGetPackSettings);
            }

            if (!(releaseNotesSettings is null))
            {
                context.UpdateReleaseNotesVersion(version, releaseNotesSettings);
            }

            return(version);
        }
Exemplo n.º 3
0
        public static ICollection <string> UpdateReleaseNotes(
            this ICakeContext context,
            ReleaseNotesSettings releaseNotesSettings,
            NuGetPackSettings nuGetPackSettings = null)
        {
            var releaseNotes =
                FilterLines(File.ReadLines(releaseNotesSettings.ReleaseNotesVNext.FullPath)).ToList();

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"## {releaseNotesSettings.Version}");
            stringBuilder.AppendLine();

            foreach (var line in releaseNotes)
            {
                stringBuilder.AppendLine($"- {line}");
            }

            stringBuilder.AppendLine();
            stringBuilder.Append(File.ReadAllText(releaseNotesSettings.ReleaseNotes.FullPath));
            File.WriteAllText(releaseNotesSettings.ReleaseNotes.FullPath, stringBuilder.ToString());

            var nextVersion = releaseNotesSettings.Version.Bump(BumpMethod.Patch);

            File.WriteAllText(releaseNotesSettings.ReleaseNotesVNext.FullPath, $"## {nextVersion}");

            if (!(nuGetPackSettings is null))
            {
                nuGetPackSettings.ReleaseNotes = releaseNotes;
            }

            return(releaseNotes);
        }
Exemplo n.º 4
0
        /// <inheritdoc/>
        public override void Run(Context context)
        {
            // look for solutions and start building them
            var nuspecFiles = context.GetFiles("./Build/Tools/NuGet/*.nuspec");

            context.Information("Found {0} nuspec files.", nuspecFiles.Count);

            // basic nuget package configuration
            var nuGetPackSettings = new NuGetPackSettings
            {
                Version                   = context.GetBuildNumber(),
                OutputDirectory           = @"./Artifacts/",
                IncludeReferencedProjects = true,
                Symbols                   = true,
                Properties                = new Dictionary <string, string> {
                    { "Configuration", "Release" }
                },
            };

            // loop through each nuspec file and create the package
            foreach (var spec in nuspecFiles)
            {
                var specPath = spec.ToString();

                context.Information("Starting to pack: {0}", specPath);
                context.NuGetPack(specPath, nuGetPackSettings);
            }
        }
Exemplo n.º 5
0
            public void Should_Set_NoPackageAnalysis_To_False_By_Default()
            {
                // Given, When
                var settings = new NuGetPackSettings();

                // Then
                Assert.False(settings.NoPackageAnalysis);
            }
            public void Should_Set_OutputToToolFolder_To_False_By_Default()
            {
                // Given, When
                var settings = new NuGetPackSettings();

                // Then
                Assert.False(settings.OutputToToolFolder);
            }
Exemplo n.º 7
0
            public void Should_Set_IncludeReferencedProjects_To_False_By_Default()
            {
                // Given, When
                var settings = new NuGetPackSettings();

                // Then
                Assert.False(settings.IncludeReferencedProjects);
            }
Exemplo n.º 8
0
            public void Should_Set_Symbols_To_False_By_Default()
            {
                // Given, When
                var settings = new NuGetPackSettings();

                // Then
                Assert.False(settings.Symbols);
            }
Exemplo n.º 9
0
    public static void BuildPackages()
    {
        foreach (var p in AdditionalPackages)
        {
            NuGetXPackSettings settings;
            if (p.Value == null)
            {
                settings = new NuGetXPackSettings(PackSettings);
            }
            else
            {
                settings = new NuGetXPackSettings(p.Value);
            }

            if (!string.IsNullOrEmpty(Version))
            {
                settings.Properties["version"] = Version;
            }

            var targetPath = Context.Directory(string.Format("{0}/{1}/{2}",
                                                             BuildConfig.TargetDirectory,
                                                             "user-packages",
                                                             BuildConfig.Config.Configuration));

            var nugetSettings = new NuGetPackSettings();
            XBuildHelper.ApplyToolSettings(nugetSettings, settings);
            nugetSettings.Symbols               = settings.Symbols.GetValueOrDefault();
            nugetSettings.Properties            = new Dictionary <string, string>(settings.Properties);
            nugetSettings.ArgumentCustomization = settings.ArgumentCustomization;

            Context.CreateDirectory(targetPath);
            nugetSettings.WorkingDirectory            = targetPath;
            nugetSettings.Properties["Configuration"] = BuildConfig.Configuration;
            if (!string.IsNullOrEmpty(Version))
            {
                nugetSettings.Properties["version"] = Version;
            }

            if (settings.Tool.GetValueOrDefault())
            {
                var argCustomization = nugetSettings.ArgumentCustomization;
                nugetSettings.ArgumentCustomization = args =>
                {
                    if (argCustomization != null)
                    {
                        args = argCustomization.Invoke(args);
                    }
                    args.Append("-Tool");
                    return(args);
                };
            }

            Context.NuGetPack(p.Key, nugetSettings);
        }
    }
Exemplo n.º 10
0
        public static void UpdateNuGetPackVersion(
            this ICakeContext context,
            Version verson,
            NuGetPackSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            settings.Version = verson.ToString();
        }
Exemplo n.º 11
0
        public static void NuGetPack(this ICakeContext context, FilePath filePath, NuGetPackSettings settings)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var resolver = new NuGetToolResolver(context.FileSystem, context.Environment, context.Tools);
            var packer   = new NuGetPacker(context.FileSystem, context.Environment, context.ProcessRunner, context.Log, context.Tools, resolver);

            packer.Pack(filePath, settings);
        }
Exemplo n.º 12
0
        public static void PublishMultipleTasks(ICakeContext context, string jsonPath)
        {
            try
            {
                if (!string.IsNullOrEmpty(jsonPath))
                {
                    ProcessPath lstprocessPath = JsonConvert.DeserializeObject <ProcessPath>(jsonPath);

                    if (lstprocessPath != null)
                    {
                        foreach (var path in lstprocessPath.lstPaths)
                        {
                            context.DeleteFiles(path.Deletepath);



                            string publishDirectory = path.PublishPath;



                            var publishSettings = new DotNetCorePublishSettings
                            {
                                Configuration   = "Release",
                                OutputDirectory = publishDirectory,
                                Runtime         = "win-x64"
                            };



                            context.DotNetCorePublish(path.CSprojPath, publishSettings);



                            var nuGetPackSettings = new NuGetPackSettings
                            {
                                OutputDirectory = "./publishpackage/",
                                Version         = BuildNumber
                            };



                            context.NuGetPack(path.nuspecPath, nuGetPackSettings);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 13
0
        internal static void PackNuGets(ICakeContext cake, NuGetInfo[] nugets)
        {
            if (nugets == null || !nugets.Any())
            {
                return;
            }

            // NuGet messes up path on mac, so let's add ./ in front twice
            var basePath = cake.IsRunningOnUnix() ? "././" : "./";

            foreach (var n in nugets)
            {
                if (!BuildPlatformUtil.BuildsOnCurrentPlatform(cake, n.BuildsOn))
                {
                    cake.Warning("Nuspec is not marked to build on current platform: {0}", n.NuSpec.FullPath);
                    continue;
                }

                var outputDir = n.OutputDirectory ?? "./output";

                if (!cake.DirectoryExists(outputDir))
                {
                    cake.CreateDirectory(outputDir);
                }

                var settings = new NuGetPackSettings
                {
                    Verbosity       = NuGetVerbosity.Detailed,
                    OutputDirectory = outputDir,
                    BasePath        = basePath
                };

                if (!string.IsNullOrEmpty(n.Version))
                {
                    settings.Version = n.Version;
                }

                if (n.RequireLicenseAcceptance)
                {
                    settings.RequireLicenseAcceptance = n.RequireLicenseAcceptance;
                }

                cake.NuGetPack(n.NuSpec, settings);
            }
        }
Exemplo n.º 14
0
        public void CreatePackagesForAllNuSpecOutputToArtifactsFolder(string fullVersion)
        {
            var files = _globber.GetFiles("./**/*.nuspec").ToList();

            if (files.Count == 0)
            {
                throw new Exception("No .nuspec files found to create packages from");
            }

            var nuGetToolResolver = new NuGetToolResolver(_fileSystem, _environment, _tools);
            var packer            = new NuGetPacker(_fileSystem, _environment, _processRunner, _log, _tools, nuGetToolResolver);

            var output    = new DirectoryPath("./Artifacts");
            var directory = _fileSystem.GetDirectory(output);

            if (!directory.Exists)
            {
                directory.Create();
            }

            var nuGetPackSettings = new NuGetPackSettings
            {
                Version                   = fullVersion,
                OutputDirectory           = output.FullPath,
                IncludeReferencedProjects = true,
                Properties                = new Dictionary <string, string> {
                    { "Configuration", Configuration }
                },
            };

            foreach (var nuspec in files)
            {
                _log.Information(nuspec.FullPath);
                var csproj = nuspec.ChangeExtension(".csproj");
                _log.Information(csproj.FullPath);
                packer.Pack(csproj.FullPath, nuGetPackSettings);
            }
        }
Exemplo n.º 15
0
    private static void PackageUsingNuspec(BuildContextBase context)
    {
        var cmdlineNuspecFile = Paths.Nuspec.CombineWithFilePath("GitVersion.CommandLine.nuspec");

        if (!context.FileExists(cmdlineNuspecFile))
        {
            return;
        }

        var artifactPath  = context.MakeAbsolute(Paths.ArtifactsBinCmdline).FullPath;
        var version       = context.Version;
        var gitVersion    = version?.GitVersion;
        var nugetSettings = new NuGetPackSettings
        {
            // KeepTemporaryNuSpecFile = true,
            Version           = version?.NugetVersion,
            NoPackageAnalysis = true,
            OutputDirectory   = Paths.Nuget,
            Repository        = new NuGetRepository
            {
                Branch = gitVersion?.BranchName,
                Commit = gitVersion?.Sha
            },
            Files = context.GetFiles(artifactPath + "/**/*.*")
                    .Select(file => new NuSpecContent {
                Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "")
            })
                    .Concat(context.GetFiles("docs/**/package_icon.png").Select(file => new NuSpecContent {
                Source = file.FullPath, Target = "package_icon.png"
            }))
                    .Concat(context.GetFiles("build/nuspec/README.md").Select(file => new NuSpecContent {
                Source = file.FullPath, Target = "README.md"
            }))
                    .ToArray()
        };

        context.NuGetPack(cmdlineNuspecFile, nugetSettings);
    }
Exemplo n.º 16
0
        /// <inheritdoc/>
        public override void Run(Context context)
        {
            // look for solutions and start building them
            var nuspecFiles          = context.GetFiles("./Build/Tools/NuGet/*.nuspec");
            var noSymbolsNuspecFiles = context.GetFiles("./Build/Tools/NuGet/DotNetNuke.WebApi.nuspec");

            context.Information("Found {0} nuspec files.", nuspecFiles.Count);

            // basic nuget package configuration
            var nuGetPackSettings = new NuGetPackSettings
            {
                Version                   = context.GetBuildNumber(),
                OutputDirectory           = @"./Artifacts/",
                IncludeReferencedProjects = true,
                Symbols                   = true,
                SymbolPackageFormat       = "snupkg",
                Properties                = new Dictionary <string, string> {
                    { "Configuration", "Release" }
                },
            };

            nuspecFiles -= noSymbolsNuspecFiles;
            foreach (var spec in nuspecFiles)
            {
                context.Information("Starting to pack: {0}", spec);
                context.NuGetPack(spec.FullPath, nuGetPackSettings);
            }

            nuGetPackSettings.Symbols             = false;
            nuGetPackSettings.SymbolPackageFormat = null;
            foreach (var spec in noSymbolsNuspecFiles)
            {
                context.Information("Starting to pack: {0}", spec);
                context.NuGetPack(spec.FullPath, nuGetPackSettings);
            }
        }
Exemplo n.º 17
0
        public Build()
        {
            var releasesDir = Cake.Directory("CodeCakeBuilder/Releases");

            string configuration         = null;
            SimpleRepositoryInfo gitInfo = null;
            var    solution          = Cake.ParseSolution("CK-DB.sln");
            var    CKDBProjectNames  = new HashSet <string>(solution.Projects.Where(p => p.Name.StartsWith("CK.")).Select(pub => pub.Name));
            string VersionCKDatabase = null;
            string VersionMicrosoftAspNetCoreCryptographyKeyDerivation = null;
            Dictionary <string, string> DependentPackages            = null;
            Dictionary <string, string> IntegrationDependentPackages = null;

            Task("Check-Dependencies")
            .Does(() =>
            {
                var allPackages = solution.Projects
                                  .Where(p => p.Name.StartsWith("CK."))
                                  .Select(p => new
                {
                    Project       = p,
                    PackageConfig = p.Path.GetDirectory().CombineWithFilePath("packages.config").FullPath
                })
                                  .Where(p => System.IO.File.Exists(p.PackageConfig))
                                  .SelectMany(p => XDocument.Load(p.PackageConfig)
                                              .Root
                                              .Elements("package")
                                              .Select(e => { e.AddAnnotation(p.Project); return(e); }))
                                  .ToList();
                var byPackage = allPackages
                                .GroupBy(e => e.Attribute("id").Value,
                                         e => new
                {
                    ProjectName = e.Annotation <SolutionProject>().Name,
                    Version     = e.Attribute("version").Value
                });
                var multiVersions = byPackage.Where(g => g.GroupBy(x => x.Version).Count() > 1);
                if (multiVersions.Any())
                {
                    var conflicts = multiVersions.Select(e => Environment.NewLine + " - " + e.Key + ":" + Environment.NewLine + "    - " + string.Join(Environment.NewLine + "    - ", e.GroupBy(x => x.Version).Select(x => x.Key + " in " + string.Join(", ", x.Select(xN => xN.ProjectName)))));
                    Cake.TerminateWithError($"Dependency versions differ for:{Environment.NewLine}{string.Join( Environment.NewLine, conflicts )}");
                }
                // This is ugly... But it works.
                VersionCKDatabase = byPackage.Single(e => e.Key == "CK.StObj.Model").First().Version;
                VersionMicrosoftAspNetCoreCryptographyKeyDerivation = byPackage.Single(e => e.Key == "Microsoft.AspNetCore.Cryptography.KeyDerivation").First().Version;

                // Use Tests/CK.DB.Actor.Tests/packages.config for packages' versions that are not the CK-DB ones.
                XDocument aclPackagesConfig = XDocument.Load("Tests/CK.DB.Actor.Tests/packages.config");
                var pp            = aclPackagesConfig.Root.Descendants("package").Where(e => !CKDBProjectNames.Contains((string)e.Attribute("id")));
                DependentPackages = pp.ToDictionary(e => (string)e.Attribute("id"), e => (string)e.Attribute("version"));
            });

            Task("Check-Repository")
            .IsDependentOn("Check-Dependencies")
            .Does(() =>
            {
                gitInfo = Cake.GetSimpleRepositoryInfo();
                if (!gitInfo.IsValid)
                {
                    if (Cake.IsInteractiveMode() &&
                        Cake.ReadInteractiveOption("Repository is not ready to be published. Proceed anyway?", 'Y', 'N') == 'Y')
                    {
                        Cake.Warning("GitInfo is not valid, but you choose to continue...");
                    }
                    else
                    {
                        throw new Exception("Repository is not ready to be published.");
                    }
                }
                IntegrationDependentPackages = new Dictionary <string, string>(DependentPackages);
                foreach (var n in CKDBProjectNames)
                {
                    IntegrationDependentPackages.Add(n, gitInfo.NuGetVersion);
                }
                configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";
                Cake.Information("Publishing {0} in {1}.", gitInfo.SemVer, configuration);
            });

            Task("Clean")
            .IsDependentOn("Check-Repository")
            .Does(() =>
            {
                Cake.CleanDirectories("**/bin/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories("**/obj/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories(releasesDir);
            });

            Task("Restore-NuGet-Packages")
            .Does(() =>
            {
                Cake.NuGetRestore("CK-DB.sln");
            });


            Task("Build")
            .IsDependentOn("Clean")
            .IsDependentOn("Restore-NuGet-Packages")
            .IsDependentOn("Check-Repository")
            .Does(() =>
            {
                using (var tempSln = Cake.CreateTemporarySolutionFile("CK-DB.sln"))
                {
                    tempSln.ExcludeProjectsFromBuild("CodeCakeBuilder");
                    Cake.MSBuild(tempSln.FullPath, settings =>
                    {
                        settings.Configuration = configuration;
                        settings.Verbosity     = Verbosity.Minimal;
                        // Always generates Xml documentation. Relies on this definition in the csproj files:
                        //
                        // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                        //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                        // </PropertyGroup>
                        //
                        settings.Properties.Add("GenerateDocumentation", new[] { "true" });
                    });
                }
            });

            Task("Unit-Testing")
            .IsDependentOn("Build")
            .WithCriteria(() => gitInfo.IsValid)
            .WithCriteria(() => !Cake.IsInteractiveMode() ||
                          Cake.ReadInteractiveOption("Run unit tests?", 'Y', 'N') == 'Y')
            .Does(() =>
            {
                var testDlls = solution.Projects
                               .Where(p => p.Name.EndsWith(".Tests"))
                               .Select(p => p.Path.GetDirectory().CombineWithFilePath("bin/" + configuration + "/" + p.Name + ".dll"));
                Cake.Information("Testing: {0}", string.Join(", ", testDlls.Select(p => p.GetFilename().ToString())));
                Cake.NUnit(testDlls, new NUnitSettings()
                {
                    Framework = "v4.5"
                });
            });

            Task("Create-NuGet-Packages")
            .IsDependentOn("Unit-Testing")
            .Does(() =>
            {
                Cake.CreateDirectory(releasesDir);
                var settings = new NuGetPackSettings()
                {
                    Version         = gitInfo.NuGetVersion,
                    BasePath        = Cake.Environment.WorkingDirectory,
                    OutputDirectory = releasesDir
                };
                Cake.CopyFiles("CodeCakeBuilder/NuSpec/*.nuspec", releasesDir);
                foreach (var nuspec in Cake.GetFiles(releasesDir.Path + "/*.nuspec"))
                {
                    TransformText(nuspec, configuration, gitInfo, VersionCKDatabase, VersionMicrosoftAspNetCoreCryptographyKeyDerivation);
                    Cake.NuGetPack(nuspec, settings);
                }
                Cake.DeleteFiles(releasesDir.Path + "/*.nuspec");
            });

            Task("Run-IntegrationTests")
            .IsDependentOn("Create-NuGet-Packages")
            .WithCriteria(() => gitInfo.IsValid)
            .WithCriteria(() => !Cake.IsInteractiveMode() ||
                          Cake.ReadInteractiveOption("Run integration tests?", 'Y', 'N') == 'Y')
            .Does(() =>
            {
                var integrationSolution = "IntegrationTests/IntegrationTests.sln";
                var integration         = Cake.ParseSolution(integrationSolution);
                var projects            = integration.Projects
                                          .Where(p => p.Name != "CodeCakeBuilder")
                                          .Select(p => new
                {
                    CSProj     = p.Path.FullPath,
                    ConfigFile = p.Path.GetDirectory().CombineWithFilePath("packages.config").FullPath
                })
                                          .Where(p => System.IO.File.Exists(p.ConfigFile));
                // Cleans all the existing IntegrationTests/packages.
                // The CodeCakeBuilder restore will get them (from Release for CK-DB packages).
                Cake.CleanDirectory("IntegrationTests/packages");

                foreach (var config in projects.Select(p => p.ConfigFile))
                {
                    XDocument doc = XDocument.Load(config);
                    int countRef  = 0;
                    foreach (var p in doc.Root.Elements("package"))
                    {
                        string packageName = p.Attribute("id").Value;
                        if (IntegrationDependentPackages.ContainsKey(packageName))
                        {
                            string depVersion = IntegrationDependentPackages[packageName];
                            string curVersion = p.Attribute("version").Value;
                            if (curVersion != depVersion)
                            {
                                p.SetAttributeValue("version", depVersion);
                                Cake.Information($"=> package.config: {packageName}: {curVersion} -> {depVersion}.");
                                ++countRef;
                            }
                        }
                    }
                    if (countRef > 0)
                    {
                        Cake.Information($"Updated {countRef} in file {config}.");
                        doc.Save(config);
                    }
                }
                foreach (var csproj in projects.Select(p => p.CSProj))
                {
                    XDocument doc  = XDocument.Load(csproj);
                    int countRef   = 0;
                    var projection = doc.Root.Descendants(msBuild + "Reference")
                                     .Select(e => new
                    {
                        Reference       = e,
                        IncludeAttr     = e.Attribute("Include"),
                        HintPathElement = e.Element(msBuild + "HintPath"),
                    });
                    var filtered = projection.Where(e => e.HintPathElement != null &&
                                                    e.IncludeAttr != null &&
                                                    e.HintPathElement.Value.StartsWith(@"..\..\packages\"));
                    var final = filtered.Select(e => new
                    {
                        E           = e,
                        ProjectName = new AssemblyName(e.IncludeAttr.Value).Name
                    })
                                .Where(e => IntegrationDependentPackages.ContainsKey(e.ProjectName));

                    foreach (var p in final)
                    {
                        var version   = IntegrationDependentPackages[p.ProjectName];
                        var path      = p.E.HintPathElement.Value.Split('\\');
                        var newFolder = p.ProjectName + '.' + version;
                        var curFolder = path[3];
                        if (curFolder != newFolder)
                        {
                            path[3] = newFolder;
                            p.E.HintPathElement.Value = string.Join("\\", path);
                            Cake.Information($"=> cproj: {p.ProjectName}: {curFolder} -> {newFolder}.");
                            ++countRef;
                        }
                    }
                    if (countRef > 0)
                    {
                        Cake.Information($"Updated {countRef} references in file {csproj}.");
                        doc.Save(csproj);
                    }
                }

                Cake.NuGetRestore(integrationSolution);
                Cake.MSBuild("IntegrationTests/CodeCakeBuilder/CodeCakeBuilder.csproj", settings =>
                {
                    settings.Configuration = configuration;
                    settings.Verbosity     = Verbosity.Minimal;
                });
                if (Cake.StartProcess($"IntegrationTests/CodeCakeBuilder/bin/{configuration}/CodeCakeBuilder.exe", "-" + InteractiveAliases.NoInteractionArgument) != 0)
                {
                    Cake.TerminateWithError("Error in IntegrationTests.");
                }
            });


            Task("Push-NuGet-Packages")
            .IsDependentOn("Create-NuGet-Packages")
            .IsDependentOn("Run-IntegrationTests")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                IEnumerable <FilePath> nugetPackages = Cake.GetFiles(releasesDir.Path + "/*.nupkg");
                if (Cake.IsInteractiveMode())
                {
                    var localFeed = Cake.FindDirectoryAbove("LocalFeed");
                    if (localFeed != null)
                    {
                        Cake.Information("LocalFeed directory found: {0}", localFeed);
                        if (Cake.ReadInteractiveOption("Do you want to publish to LocalFeed?", 'Y', 'N') == 'Y')
                        {
                            Cake.CopyFiles(nugetPackages, localFeed);
                        }
                    }
                }
                if (gitInfo.IsValidRelease)
                {
                    if (gitInfo.PreReleaseName == "" ||
                        gitInfo.PreReleaseName == "rc" ||
                        gitInfo.PreReleaseName == "prerelease")
                    {
                        PushNuGetPackages("NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages);
                    }
                    else
                    {
                        // An alpha, beta, delta, epsilon, gamma, kappa goes to invenietis-preview.
                        PushNuGetPackages("MYGET_PREVIEW_API_KEY", "https://www.myget.org/F/invenietis-preview/api/v2/package", nugetPackages);
                    }
                }
                else
                {
                    Debug.Assert(gitInfo.IsValidCIBuild);
                    PushNuGetPackages("MYGET_CI_API_KEY", "https://www.myget.org/F/invenietis-ci/api/v2/package", nugetPackages);
                }
            });

            Task("Default").IsDependentOn("Push-NuGet-Packages");
        }
Exemplo n.º 18
0
        public Build()
        {
            // The configuration ("Debug", etc.) defaults to "Release".
            var configuration = Cake.Argument("configuration", "Release");

            // Git .ignore file should ignore this folder.
            // Here, we name it "Releases" (default , it could be "Artefacts", "Publish" or anything else,
            // but "Releases" is by default ignored in https://github.com/github/gitignore/blob/master/VisualStudio.gitignore.
            var releasesDir = Cake.Directory("CodeCakeBuilder/Releases");

            Task("Clean")
            .Does(() =>
            {
                // Avoids cleaning CodeCakeBuilder itself!
                Cake.CleanDirectories("**/bin/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories("**/obj/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories(releasesDir);
            });

            Task("Restore-NuGet-Packages")
            .Does(() =>
            {
                // Reminder for first run.
                // Bootstrap.ps1 ensures that Tools/nuget.exe exists
                // and compiles this CodeCakeBuilder application in Release mode.
                // It is the first thing that a CI should execute in the initialization phase and
                // once done bin/Release/CodeCakeBuilder.exe can be called to do its job.
                // (Of course, the following check can be removed and nuget.exe be conventionnaly located somewhere else.)
                if (!Cake.FileExists("CodeCakeBuilder/Tools/nuget.exe"))
                {
                    throw new Exception("Please execute Bootstrap.ps1 first.");
                }

                Cake.Information("Restoring nuget packages for existing .sln files at the root level.", configuration);
                foreach (var sln in Cake.GetFiles("*.sln"))
                {
                    Cake.NuGetRestore(sln);
                }
            });

            Task("Build")
            .IsDependentOn("Clean")
            .IsDependentOn("Restore-NuGet-Packages")
            .Does(() =>
            {
                Cake.Information("Building all existing .sln files at the root level with '{0}' configuration (excluding this builder application).", configuration);
                foreach (var sln in Cake.GetFiles("*.sln"))
                {
                    using (var tempSln = Cake.CreateTemporarySolutionFile(sln))
                    {
                        // Excludes "CodeCakeBuilder" itself from compilation!
                        tempSln.ExcludeProjectsFromBuild("CodeCakeBuilder");
                        Cake.MSBuild(tempSln.FullPath, new MSBuildSettings()
                                     .SetConfiguration(configuration)
                                     .SetVerbosity(Verbosity.Minimal)
                                     .SetMaxCpuCount(1));
                    }
                }
            });

            Task("Create-NuGet-Packages")
            .IsDependentOn("Build")
            .Does(() =>
            {
                Cake.CreateDirectory(releasesDir);
                var settings = new NuGetPackSettings()
                {
                    // Hard coded version!?
                    // Cake offers tools to extract the version number from a ReleaseNotes.txt.
                    // But other tools exist: have a look at SimpleGitVersion.Cake to easily
                    // manage Constrained Semantic Versions on Git repositories.
                    Version         = "1.0.0-alpha",
                    BasePath        = Cake.Environment.WorkingDirectory,
                    OutputDirectory = releasesDir
                };
                foreach (var nuspec in Cake.GetFiles("CodeCakeBuilder/NuSpec/*.nuspec"))
                {
                    Cake.NuGetPack(nuspec, settings);
                }
            });

            // We want to push on NuGet only the Release packages.
            Task("Push-NuGet-Packages")
            .IsDependentOn("Create-NuGet-Packages")
            .WithCriteria(() => configuration == "Release")
            .Does(() =>
            {
                // Resolve the API key: if the environment variable is not found
                // AND CodeCakeBuilder is running in interactive mode (ie. no -nointeraction parameter),
                // then the user is prompted to enter it.
                // This is specific to CodeCake (in Code.Cake.dll).
                var apiKey = Cake.InteractiveEnvironmentVariable("NUGET_API_KEY");
                if (string.IsNullOrEmpty(apiKey))
                {
                    throw new InvalidOperationException("Could not resolve NuGet API key.");
                }

                var settings = new NuGetPushSettings
                {
                    Source = "https://www.nuget.org/api/v2/package",
                    ApiKey = apiKey
                };

                foreach (var nupkg in Cake.GetFiles(releasesDir.Path + "/*.nupkg"))
                {
                    Cake.NuGetPush(nupkg, settings);
                }
            });

            Task("Default").IsDependentOn("Push-NuGet-Packages");
        }
Exemplo n.º 19
0
        public Build()
        {
            const string solutionName = "SGV-Net";
            const string solutionFileName = solutionName + ".sln";

            var releasesDir = Cake.Directory( "CodeCakeBuilder/Releases" );
            SimpleRepositoryInfo gitInfo = null;
            // Configuration is either "Debug" or "Release".
            string configuration = null;

            // We do not publish .Tests projects for this solution.
            var projectsToPublish = Cake.ParseSolution( solutionFileName )
                                        .Projects
                                        .Where( p => p.Name != "CodeCakeBuilder"
                                                     && !p.Path.Segments.Contains( "Tests" ) );

            Task( "Check-Repository" )
                .Does( () =>
                {
                    gitInfo = Cake.GetSimpleRepositoryInfo();

                    if( !gitInfo.IsValid )
                    {
                        if( Cake.IsInteractiveMode()
                            && Cake.ReadInteractiveOption( "Repository is not ready to be published. Proceed anyway?", 'Y', 'N' ) == 'Y' )
                        {
                            Cake.Warning( "GitInfo is not valid, but you choose to continue..." );
                        }
                        else throw new Exception( "Repository is not ready to be published." );
                    }
                    configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";

                    Cake.Information( "Publishing {0} projects with version={1} and configuration={2}: {3}",
                        projectsToPublish.Count(),
                        gitInfo.SemVer,
                        configuration,
                        string.Join( ", ", projectsToPublish.Select( p => p.Name ) ) );
                } );

            Task( "Clean" )
                .IsDependentOn( "Check-Repository" )
                .Does( () =>
                {
                    Cake.CleanDirectories( "**/bin/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( "**/obj/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( releasesDir );
                } );

            Task( "Restore-NuGet-Packages" )
                .Does( () =>
                {
                    Cake.NuGetRestore( "SGV-Net.sln" );
                } );

            Task( "Build" )
                .IsDependentOn( "Clean" )
                .IsDependentOn( "Restore-NuGet-Packages" )
                .IsDependentOn( "Check-Repository" )
                .Does( () =>
                {
                    using( var tempSln = Cake.CreateTemporarySolutionFile( "SGV-Net.sln" ) )
                    {
                        tempSln.ExcludeProjectsFromBuild( "CodeCakeBuilder" );
                        Cake.MSBuild( tempSln.FullPath, settings =>
                        {
                            settings.Configuration = configuration;
                            settings.Verbosity = Verbosity.Minimal;
                            // Always generates Xml documentation. Relies on this definition in the csproj files:
                            //
                            // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                            //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                            // </PropertyGroup>
                            //
                            settings.Properties.Add( "GenerateDocumentation", new[] { "true" } );
                        } );
                    }
                } );

            Task( "Unit-Testing" )
                .IsDependentOn( "Build" )
                .Does( () =>
                {
                    Cake.CreateDirectory( releasesDir );
                    var testDlls = Cake.ParseSolution( solutionFileName )
                         .Projects
                             .Where( p => p.Name.EndsWith( ".Tests" ) && p.Name != "CSProjTestProject" )
                             .Select( p => p.Path.GetDirectory().CombineWithFilePath( "bin/" + configuration + "/" + p.Name + ".dll" ) );

                    Cake.Information( "Testing: {0}", string.Join( ", ", testDlls.Select( p => p.GetFilename().ToString() ) ) );

                    Cake.NUnit( testDlls, new NUnitSettings()
                    {
                        Framework = "v4.5",
                        OutputFile = releasesDir.Path + "/TestResult.txt"
                    } );
                } );

            Task( "Create-NuGet-Packages" )
                .IsDependentOn( "Unit-Testing" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    Cake.CreateDirectory( releasesDir );
                    // Preparing SimpleGitVersion.DNXCommands/app folder.
                    var dnxAppPath = releasesDir.Path + "/SimpleGitVersion.DNXCommands/app";
                    Cake.CreateDirectory( dnxAppPath );
                    Cake.CopyFiles( "SimpleGitVersion.DNXCommands/NuGetAssets/app/*", dnxAppPath );
                    TransformText( dnxAppPath + "/project.json", configuration, gitInfo );
                    //
                    var settings = new NuGetPackSettings()
                    {
                        Version = gitInfo.NuGetVersion,
                        BasePath = Cake.Environment.WorkingDirectory,
                        OutputDirectory = releasesDir
                    };
                    Cake.CopyFiles( "CodeCakeBuilder/NuSpec/*.nuspec", releasesDir );
                    foreach( var nuspec in Cake.GetFiles( releasesDir.Path + "/*.nuspec" ) )
                    {
                        TransformText( nuspec, configuration, gitInfo );
                        Cake.NuGetPack( nuspec, settings );
                    }
                    Cake.DeleteFiles( releasesDir.Path + "/*.nuspec" );
                    Cake.DeleteDirectory( dnxAppPath, true );
                } );

            Task( "Push-NuGet-Packages" )
                .IsDependentOn( "Create-NuGet-Packages" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    IEnumerable<FilePath> nugetPackages = Cake.GetFiles( releasesDir.Path + "/*.nupkg" );
                    if( Cake.IsInteractiveMode() )
                    {
                        var localFeed = Cake.FindDirectoryAbove( "LocalFeed" );
                        if( localFeed != null )
                        {
                            Cake.Information( "LocalFeed directory found: {0}", localFeed );
                            if( Cake.ReadInteractiveOption( "Do you want to publish to LocalFeed?", 'Y', 'N' ) == 'Y' )
                            {
                                Cake.CopyFiles( nugetPackages, localFeed );
                            }
                        }
                    }
                    if( gitInfo.IsValidRelease )
                    {
                        if( gitInfo.PreReleaseName == ""
                            || gitInfo.PreReleaseName == "prerelease"
                            || gitInfo.PreReleaseName == "rc" )
                        {
                            PushNuGetPackages( "NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages );
                        }
                        else
                        {
                            // An alpha, beta, delta, epsilon, gamma, kappa goes to invenietis-preview.
                            PushNuGetPackages( "MYGET_PREVIEW_API_KEY", "https://www.myget.org/F/invenietis-preview/api/v2/package", nugetPackages );
                        }
                    }
                    else
                    {
                        Debug.Assert( gitInfo.IsValidCIBuild );
                        PushNuGetPackages( "MYGET_CI_API_KEY", "https://www.myget.org/F/invenietis-ci/api/v2/package", nugetPackages );
                    }
                } );

            Task( "Default" ).IsDependentOn( "Push-NuGet-Packages" );
        }
Exemplo n.º 20
0
        public Build()
        {
            var releasesDir = Cake.Directory( "CodeCakeBuilder/Releases" );
            string configuration = null;
            SimpleRepositoryInfo gitInfo = null;

            Task( "Check-Repository" )
                .Does( () =>
                {
                    gitInfo = Cake.GetSimpleRepositoryInfo();
                    if( !gitInfo.IsValid )
                    {
                        configuration = "Debug";
                        Cake.Warning( "Repository is not ready to be published. Setting configuration to {0}.", configuration );
                    }
                    {
                        configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";
                        Cake.Information( "Publishing {0} in {1}.", gitInfo.SemVer, configuration );
                    }
                } );

            Task( "Clean" )
                .IsDependentOn( "Check-Repository" )
                .Does( () =>
                {
                    Cake.CleanDirectories( "**/bin/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( "**/obj/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( releasesDir );
                } );

            Task( "Restore-NuGet-Packages" )
                .Does( () =>
                {
                    Cake.NuGetRestore( "SGV-Net.sln" );
                } );

            Task( "Build" )
                .IsDependentOn( "Clean" )
                .IsDependentOn( "Restore-NuGet-Packages" )
                .IsDependentOn( "Check-Repository" )
                .Does( () =>
                {
                    using( var tempSln = Cake.CreateTemporarySolutionFile( "SGV-Net.sln" ) )
                    {
                        tempSln.ExcludeProjectsFromBuild( "CodeCakeBuilder" );
                        Cake.MSBuild( tempSln.FullPath, settings => 
                        {
                            settings.Configuration = configuration;
                            settings.Verbosity = Verbosity.Minimal;
                            // Always generates Xml documentation. Relies on this definition in the csproj files:
                            //
                            // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                            //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                            // </PropertyGroup>
                            //
                            settings.Properties.Add( "GenerateDocumentation", new[] { "true" } );
                        } );
                    }
                } );

            Task( "Unit-Testing" )
                .IsDependentOn( "Build" )
                .Does( () => 
                {
                    Cake.NUnit( "Tests/*.Tests/bin/"+configuration+"/*.Tests.dll", new NUnitSettings() { Framework = "v4.5" } );
                } );

            Task( "Create-NuGet-Packages" )
                .IsDependentOn( "Unit-Testing" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    Cake.CreateDirectory( releasesDir );
                    // Preparing SimpleGitVersion.DNXCommands/app folder.
                    var dnxAppPath = releasesDir.Path + "/SimpleGitVersion.DNXCommands/app";
                    Cake.CreateDirectory( dnxAppPath );
                    Cake.CopyFiles( "SimpleGitVersion.DNXCommands/NuGetAssets/app/*", dnxAppPath );
                    TransformText( dnxAppPath + "/project.json", configuration, gitInfo );
                    // 
                    var settings = new NuGetPackSettings()
                    {
                        Version = gitInfo.NuGetVersion,
                        BasePath = Cake.Environment.WorkingDirectory,
                        OutputDirectory = releasesDir
                    };
                    Cake.CopyFiles( "CodeCakeBuilder/NuSpec/*.nuspec", releasesDir );
                    foreach( var nuspec in Cake.GetFiles( releasesDir.Path + "/*.nuspec" ) )
                    {
                        TransformText( nuspec, configuration, gitInfo );
                        Cake.NuGetPack( nuspec, settings );
                    }
                    Cake.DeleteFiles( releasesDir.Path + "/*.nuspec" );
                    Cake.DeleteDirectory( dnxAppPath, true );
                } );

            Task( "Push-NuGet-Packages" )
                .IsDependentOn( "Create-NuGet-Packages" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    IEnumerable<FilePath> nugetPackages = Cake.GetFiles( releasesDir.Path + "/*.nupkg" );
                    if( Cake.IsInteractiveMode() )
                    {
                        var localFeed = Cake.FindDirectoryAbove( "LocalFeed" );
                        if( localFeed != null )
                        {
                            Cake.Information( "LocalFeed directory found: {0}", localFeed );
                            if( Cake.ReadInteractiveOption( "Do you want to publish to LocalFeed?", 'Y', 'N' ) == 'Y' )
                            {
                                Cake.CopyFiles( nugetPackages, localFeed );
                            }
                        }
                    }
                    if( gitInfo.IsValidRelease )
                    {
                        PushNuGetPackages( "NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages );
                    }
                    else
                    {
                        Debug.Assert( gitInfo.IsValidCIBuild );
                        PushNuGetPackages( "MYGET_EXPLORE_API_KEY", "https://www.myget.org/F/invenietis-explore/api/v2/package", nugetPackages );
                    }
                } );

            Task( "Default" ).IsDependentOn( "Push-NuGet-Packages" );
        }
Exemplo n.º 21
0
 public static NuGetPackSettings SetConfiguration(this NuGetPackSettings toolSettings, string configuration)
 {
     return(toolSettings.SetProperty("configuration", configuration));
 }
        public void FastReportLocalization()
        {
            string packDir = Path.Combine(solutionDirectory, "Pack");
            string packFRLocalizationDir = Path.Combine(packDir, "FastReport.Localization");
            string localizationDir       = Path.Combine(solutionDirectory, "Localization");

            if (!Directory.Exists(localizationDir))
            {
                throw new Exception("'Localization' directory wasn't found on path: " + localizationDir);
            }

            string tempDir = Path.Combine(packFRLocalizationDir, "tmp");

            if (DirectoryExists(tempDir))
            {
                DeleteDirectory(tempDir, new DeleteDirectorySettings
                {
                    Force     = true,
                    Recursive = true
                });
            }
            CreateDirectory(tempDir);

            Information($"{Environment.NewLine}FastReport.Localization pack...", ConsoleColor.DarkMagenta);

            var packFiles = new[] {
                //new NuSpecContent{Source = Path.Combine(packDir, "FastReport .NET-license.md"), Target = ""},
                new NuSpecContent {
                    Source = Path.Combine(packDir, FRLOGO192PNG), Target = ""
                },
                new NuSpecContent {
                    Source = Path.Combine(packDir, MIT_LICENSE), Target = ""
                },
                new NuSpecContent {
                    Source = Path.Combine(packFRLocalizationDir, "**", "*.*"), Target = ""
                },
                new NuSpecContent {
                    Source = Path.Combine(localizationDir, "*.frl"),
                    Target = Path.Combine("build", "Localization")
                }
            };

            // generate nuspec
            var nuGetPackSettings = new NuGetPackSettings
            {
                Id          = "FastReport.Localization",
                Authors     = new[] { "Fast Reports Inc." },
                Owners      = new[] { "Fast Reports Inc." },
                Description = "FastReport.Localization includes localization files for FastReport .NET, FastReport.Core, FastReport.CoreWin, FastReport.Mono and FastReport.OpenSource",
                ProjectUrl  = new Uri("https://www.fast-report.com/en/product/fast-report-net"),
                Icon        = FRLOGO192PNG,
                //IconUrl = new Uri("https://www.fast-report.com/download/images/frlogo-big.png"),
                License = new NuSpecLicense {
                    Type = "file", Value = MIT_LICENSE
                },
                //LicenseUrl = new Uri(project.PackageLicenseUrl), // The licenseUrl and license elements cannot be used together.
                Tags = new[] { "fastreport", "localization", "frl" },
                //FrameworkAssemblies = frameworkAssemblies,
            };

            nuGetPackSettings.Version         = version;
            nuGetPackSettings.BasePath        = tempDir;
            nuGetPackSettings.OutputDirectory = outdir;
            nuGetPackSettings.Files           = packFiles;

            // pack
            NuGetPack(nuGetPackSettings);
        }
Exemplo n.º 23
0
        public static void NuGetPack(this ICakeContext context, IEnumerable <FilePath> filePaths, NuGetPackSettings settings)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("filePaths");
            }

            foreach (var filePath in filePaths)
            {
                NuGetPack(context, filePath, settings);
            }
        }
Exemplo n.º 24
0
        public Build()
        {
            var releasesDir = Cake.Directory( "CodeCakeBuilder/Releases" );
            string configuration = null;
            SimpleRepositoryInfo gitInfo = null;

            Task( "Check-Repository" )
                .Does( () =>
                {
                    gitInfo = Cake.GetSimpleRepositoryInfo();
                    if( !gitInfo.IsValid )
                    {
                        if( Cake.IsInteractiveMode()
                            && Cake.ReadInteractiveOption( "Repository is not ready to be published. Proceed anyway?", 'Y', 'N' ) == 'Y' )
                        {
                            Cake.Warning( "GitInfo is not valid, but you choose to continue..." );
                        }
                        else throw new Exception( "Repository is not ready to be published." );
                    }
                    configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";
                } );

            Task( "Clean" )
                .Does( () =>
                {
                    // Avoids cleaning CodeCakeBuilder itself!
                    Cake.CleanDirectories( "**/bin/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( "**/obj/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( releasesDir );
                } );

            Task( "Restore-NuGet-Packages" )
                .Does( () =>
                {
                    Cake.NuGetRestore( "CodeCake.sln" );
                } );

            Task( "AutoTests" )
               .Does( () =>
               {
                   if( System.IO.Directory.Exists( "CodeCakeBuilder/AutoTests" ) ) Cake.DeleteDirectory( "CodeCakeBuilder/AutoTests", true );

                   ShouldFindAutoTestFolderFromDynamicPaths( false );
                   ShouldFindTestTxtFileFromDynamicPaths( false );
                   Cake.CreateDirectory( "CodeCakeBuilder/AutoTests/TestDynamic0" );
                   ShouldFindAutoTestFolderFromDynamicPaths( true );
                   ShouldFindTestTxtFileFromDynamicPaths( false );
                   System.IO.File.WriteAllText( "CodeCakeBuilder/AutoTests/TestDynamic0/Test.txt", "c" );
                   ShouldFindAutoTestFolderFromDynamicPaths( true );
                   ShouldFindTestTxtFileFromDynamicPaths( true );
                   Cake.DeleteDirectory( "CodeCakeBuilder/AutoTests/TestDynamic0", true );
                   Cake.CreateDirectory( "CodeCakeBuilder/AutoTests/Sub/TestDynamicB" );
                   ShouldFindAutoTestFolderFromDynamicPaths( true );
                   ShouldFindTestTxtFileFromDynamicPaths( false );
                   System.IO.File.WriteAllText( "CodeCakeBuilder/AutoTests/Sub/TestDynamicB/Test.txt", "c" );
                   ShouldFindTestTxtFileFromDynamicPaths( true );
                   Cake.DeleteDirectory( "CodeCakeBuilder/AutoTests", true );
                   ShouldFindTestTxtFileFromDynamicPaths( false );
                   ShouldFindAutoTestFolderFromDynamicPaths( false );
               } );

            Task( "Build" )
                .IsDependentOn( "Clean" )
                .IsDependentOn( "Restore-NuGet-Packages" )
                .IsDependentOn( "Check-Repository" )
                .IsDependentOn( "AutoTests" )
                .Does( () =>
                {
                    Cake.Information( "Building CodeCake.sln with '{0}' configuration (excluding this builder application).", configuration );
                    using( var tempSln = Cake.CreateTemporarySolutionFile( "CodeCake.sln" ) )
                    {
                        tempSln.ExcludeProjectsFromBuild( "CodeCakeBuilder" );
                        Cake.MSBuild( tempSln.FullPath, new MSBuildSettings()
                                .SetConfiguration( configuration )
                                .SetVerbosity( Verbosity.Minimal )
                                .SetMaxCpuCount( 1 )
                                // Always generates Xml documentation. Relies on this definition in the csproj files:
                                //
                                // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                                //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                                // </PropertyGroup>
                                //
                                .WithProperty( "GenerateDocumentation", new[] { "true" } )
                            );
                    }
                } );

            Task( "Create-NuGet-Packages" )
                    .IsDependentOn( "Build" )
                    .WithCriteria( () => gitInfo.IsValid )
                    .Does( () =>
                    {
                        Cake.CreateDirectory( releasesDir );
                        var settings = new NuGetPackSettings()
                        {
                            Version = gitInfo.NuGetVersion,
                            BasePath = Cake.Environment.WorkingDirectory,
                            OutputDirectory = releasesDir
                        };
                        Cake.CopyFiles( "CodeCakeBuilder/NuSpec/*.nuspec", releasesDir );
                        foreach( var nuspec in Cake.GetFiles( releasesDir.Path + "/*.nuspec" ) )
                        {
                            Cake.TransformTextFile( nuspec, "{{", "}}" )
                                    .WithToken( "configuration", configuration )
                                    .WithToken( "CSemVer", gitInfo.SemVer )
                                    .Save( nuspec );
                            Cake.NuGetPack( nuspec, settings );
                        }
                        Cake.DeleteFiles( releasesDir.Path + "/*.nuspec" );
                    } );

            Task( "Push-NuGet-Packages" )
                .IsDependentOn( "Create-NuGet-Packages" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    IEnumerable<FilePath> nugetPackages = Cake.GetFiles( releasesDir.Path + "/*.nupkg" );
                    if( Cake.IsInteractiveMode() )
                    {
                        var localFeed = Cake.FindDirectoryAbove( "LocalFeed" );
                        if( localFeed != null )
                        {
                            Cake.Information( "LocalFeed directory found: {0}", localFeed );
                            if( Cake.ReadInteractiveOption( "Do you want to publish to LocalFeed?", 'Y', 'N' ) == 'Y' )
                            {
                                Cake.CopyFiles( nugetPackages, localFeed );
                            }
                        }
                    }
                    if( gitInfo.IsValidRelease )
                    {
                        if( gitInfo.PreReleaseName == ""
                            || gitInfo.PreReleaseName == "prerelease"
                            || gitInfo.PreReleaseName == "rc" )
                        {
                            PushNuGetPackages( "NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages );
                        }
                        else
                        {
                            // An alpha, beta, delta, epsilon, gamma, kappa goes to invenietis-preview.
                            PushNuGetPackages( "MYGET_PREVIEW_API_KEY", "https://www.myget.org/F/invenietis-preview/api/v2/package", nugetPackages );
                        }
                    }
                    else
                    {
                        Debug.Assert( gitInfo.IsValidCIBuild );
                        PushNuGetPackages( "MYGET_CI_API_KEY", "https://www.myget.org/F/invenietis-ci/api/v2/package", nugetPackages );
                    }
                } );

            Task( "Default" ).IsDependentOn( "Push-NuGet-Packages" );
        }
Exemplo n.º 25
0
        public Build()
        {
            // The configuration ("Debug", etc.) defaults to "Release".
            var configuration = Cake.Argument( "configuration", "Release" );

            // Git .ignore file should ignore this folder.
            // Here, we name it "Releases" (default , it could be "Artefacts", "Publish" or anything else,
            // but "Releases" is by default ignored in https://github.com/github/gitignore/blob/master/VisualStudio.gitignore.
            var releasesDir = Cake.Directory( "CodeCakeBuilder/Releases" );

            Task( "Clean" )
                .Does( () =>
                {
                    // Avoids cleaning CodeCakeBuilder itself!
                    Cake.CleanDirectories( "**/bin/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( "**/obj/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( releasesDir );
                } );

            Task( "Restore-NuGet-Packages" )
                .Does( () =>
                {
                    // Reminder for first run.
                    // Bootstrap.ps1 ensures that Tools/nuget.exe exists
                    // and compiles this CodeCakeBuilder application in Release mode.
                    // It is the first thing that a CI should execute in the initialization phase and
                    // once done bin/Release/CodeCakeBuilder.exe can be called to do its job.
                    // (Of course, the following check can be removed and nuget.exe be conventionnaly located somewhere else.)
                    if( !Cake.FileExists( "CodeCakeBuilder/Tools/nuget.exe" ) )
                    {
                        throw new Exception( "Please execute Bootstrap.ps1 first." );
                    }

                    Cake.Information( "Restoring nuget packages for existing .sln files at the root level.", configuration );
                    foreach( var sln in Cake.GetFiles( "*.sln" ) )
                    {
                        Cake.NuGetRestore( sln );
                    }
                } );

            Task( "Build" )
                .IsDependentOn( "Clean" )
                .IsDependentOn( "Restore-NuGet-Packages" )
                .Does( () =>
                {
                    Cake.Information( "Building all existing .sln files at the root level with '{0}' configuration (excluding this builder application).", configuration );
                    foreach( var sln in Cake.GetFiles( "*.sln" ) )
                    {
                        using( var tempSln = Cake.CreateTemporarySolutionFile( sln ) )
                        {
                            // Excludes "CodeCakeBuilder" itself from compilation!
                            tempSln.ExcludeProjectsFromBuild( "CodeCakeBuilder" );
                            Cake.MSBuild( tempSln.FullPath, new MSBuildSettings()
                                    .SetConfiguration( configuration )
                                    .SetVerbosity( Verbosity.Minimal )
                                    .SetMaxCpuCount( 1 ) );
                        }
                    }
                } );

            Task( "Create-NuGet-Packages" )
                .IsDependentOn( "Build" )
                .Does( () =>
                {
                    Cake.CreateDirectory( releasesDir );
                    var settings = new NuGetPackSettings()
                    {
                        // Hard coded version!?
                        // Cake offers tools to extract the version number from a ReleaseNotes.txt.
                        // But other tools exist: have a look at SimpleGitVersion.Cake to easily
                        // manage Constrained Semantic Versions on Git repositories.
                        Version = "1.0.0-alpha",
                        BasePath = Cake.Environment.WorkingDirectory,
                        OutputDirectory = releasesDir
                    };
                    foreach( var nuspec in Cake.GetFiles( "CodeCakeBuilder/NuSpec/*.nuspec" ) )
                    {
                        Cake.NuGetPack( nuspec, settings );
                    }

                } );

            // We want to push on NuGet only the Release packages.
            Task( "Push-NuGet-Packages" )
                .IsDependentOn( "Create-NuGet-Packages" )
                .WithCriteria( () => configuration == "Release" )
                .Does( () =>
                {
                    // Resolve the API key: if the environment variable is not found
                    // AND CodeCakeBuilder is running in interactive mode (ie. no -nointeraction parameter),
                    // then the user is prompted to enter it.
                    // This is specific to CodeCake (in Code.Cake.dll).
                    var apiKey = Cake.InteractiveEnvironmentVariable( "NUGET_API_KEY" );
                    if( string.IsNullOrEmpty( apiKey ) ) throw new InvalidOperationException( "Could not resolve NuGet API key." );

                    var settings = new NuGetPushSettings
                    {
                        Source = "https://www.nuget.org/api/v2/package",
                        ApiKey = apiKey
                    };

                    foreach( var nupkg in Cake.GetFiles( releasesDir.Path + "/*.nupkg" ) )
                    {
                        Cake.NuGetPush( nupkg, settings );
                    }
                } );

            Task( "Default" ).IsDependentOn( "Push-NuGet-Packages" );
        }
Exemplo n.º 26
0
        public Build()
        {
            var    releasesDir           = Cake.Directory("CodeCakeBuilder/Releases");
            string configuration         = "Debug";
            SimpleRepositoryInfo gitInfo = Cake.GetSimpleRepositoryInfo();

            Task("Check-Repository")
            .Does(() =>
            {
                if (!gitInfo.IsValid)
                {
                    if (Cake.IsInteractiveMode() &&
                        Cake.ReadInteractiveOption("Repository is not ready to be published. Proceed anyway?", 'Y', 'N') == 'Y')
                    {
                        Cake.Warning("GitInfo is not valid, but you choose to continue...");
                    }
                    else if (!Cake.AppVeyor().IsRunningOnAppVeyor)
                    {
                        throw new Exception("Repository is not ready to be published.");
                    }
                }
                configuration = gitInfo.IsValidRelease &&
                                (gitInfo.PreReleaseName.Length == 0 || gitInfo.PreReleaseName == "rc")
                                    ? "Release"
                                    : "Debug";
            });

            Task("Clean")
            .Does(() =>
            {
                // Avoids cleaning CodeCakeBuilder itself!
                Cake.CleanDirectories("**/bin/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories("**/obj/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories(releasesDir);
            });

            Task("Restore-NuGet-Packages")
            .Does(() =>
            {
                Cake.NuGetRestore("CodeCake.sln");
            });

            Task("AutoTests")
            .Does(() =>
            {
                if (System.IO.Directory.Exists("CodeCakeBuilder/AutoTests"))
                {
                    Cake.DeleteDirectory("CodeCakeBuilder/AutoTests", new DeleteDirectorySettings()
                    {
                        Recursive = true, Force = true
                    });
                }
                ShouldFindAutoTestFolderFromDynamicPaths(false);
                ShouldFindTestTxtFileFromDynamicPaths(false);
                Cake.CreateDirectory("CodeCakeBuilder/AutoTests/TestDynamic0");
                ShouldFindAutoTestFolderFromDynamicPaths(true);
                ShouldFindTestTxtFileFromDynamicPaths(false);
                System.IO.File.WriteAllText("CodeCakeBuilder/AutoTests/TestDynamic0/Test.txt", "c");
                ShouldFindAutoTestFolderFromDynamicPaths(true);
                ShouldFindTestTxtFileFromDynamicPaths(true);
                Cake.DeleteDirectory("CodeCakeBuilder/AutoTests/TestDynamic0", new DeleteDirectorySettings()
                {
                    Recursive = true, Force = true
                });
                Cake.CreateDirectory("CodeCakeBuilder/AutoTests/Sub/TestDynamicB");
                ShouldFindAutoTestFolderFromDynamicPaths(true);
                ShouldFindTestTxtFileFromDynamicPaths(false);
                System.IO.File.WriteAllText("CodeCakeBuilder/AutoTests/Sub/TestDynamicB/Test.txt", "c");
                ShouldFindTestTxtFileFromDynamicPaths(true);
                Cake.DeleteDirectory("CodeCakeBuilder/AutoTests", new DeleteDirectorySettings()
                {
                    Recursive = true, Force = true
                });
                ShouldFindTestTxtFileFromDynamicPaths(false);
                ShouldFindAutoTestFolderFromDynamicPaths(false);
            });

            Task("Build")
            .IsDependentOn("Clean")
            .IsDependentOn("Restore-NuGet-Packages")
            .IsDependentOn("Check-Repository")
            .IsDependentOn("AutoTests")
            .Does(() =>
            {
                Cake.Information("Building CodeCake.sln with '{0}' configuration (excluding this builder application).", configuration);
                using (var tempSln = Cake.CreateTemporarySolutionFile("CodeCake.sln"))
                {
                    tempSln.ExcludeProjectsFromBuild("CodeCakeBuilder");
                    Cake.MSBuild(tempSln.FullPath, new MSBuildSettings()
                                 .SetConfiguration(configuration)
                                 .SetVerbosity(Verbosity.Minimal)
                                 .SetMaxCpuCount(1)
                                 // Always generates Xml documentation. Relies on this definition in the csproj files:
                                 //
                                 // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                                 //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                                 // </PropertyGroup>
                                 //
                                 .WithProperty("GenerateDocumentation", new[] { "true" })
                                 );
                }
            });

            Task("Create-NuGet-Packages")
            .IsDependentOn("Build")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                Cake.CreateDirectory(releasesDir);
                var settings = new NuGetPackSettings()
                {
                    Version         = gitInfo.SafeNuGetVersion,
                    BasePath        = Cake.Environment.WorkingDirectory,
                    OutputDirectory = releasesDir
                };
                Cake.CopyFiles("CodeCakeBuilder/NuSpec/*.nuspec", releasesDir);
                foreach (var nuspec in Cake.GetFiles(releasesDir.Path + "/*.nuspec"))
                {
                    Cake.TransformTextFile(nuspec, "{{", "}}")
                    .WithToken("configuration", configuration)
                    .WithToken("CSemVer", gitInfo.SafeSemVersion)
                    .Save(nuspec);
                    Cake.NuGetPack(nuspec, settings);
                }
                Cake.DeleteFiles(releasesDir.Path + "/*.nuspec");
            });

            Task("Push-NuGet-Packages")
            .IsDependentOn("Create-NuGet-Packages")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                IEnumerable <FilePath> nugetPackages = Cake.GetFiles(releasesDir.Path + "/*.nupkg");
                if (Cake.IsInteractiveMode())
                {
                    var localFeed = Cake.FindDirectoryAbove("LocalFeed");
                    if (localFeed != null)
                    {
                        Cake.Information("LocalFeed directory found: {0}", localFeed);
                        if (Cake.ReadInteractiveOption("Do you want to publish to LocalFeed?", 'Y', 'N') == 'Y')
                        {
                            Cake.CopyFiles(nugetPackages, localFeed);
                        }
                    }
                }
                if (gitInfo.IsValidRelease)
                {
                    if (gitInfo.PreReleaseName == "" ||
                        gitInfo.PreReleaseName == "prerelease" ||
                        gitInfo.PreReleaseName == "rc")
                    {
                        PushNuGetPackages("NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages);
                    }
                    else
                    {
                        // An alpha, beta, delta, epsilon, gamma, kappa goes to invenietis-preview.
                        PushNuGetPackages("MYGET_PREVIEW_API_KEY", "https://www.myget.org/F/invenietis-preview/api/v2/package", nugetPackages);
                    }
                }
                else
                {
                    Debug.Assert(gitInfo.IsValidCIBuild);
                    PushNuGetPackages("MYGET_CI_API_KEY", "https://www.myget.org/F/invenietis-ci/api/v2/package", nugetPackages);
                }
                if (Cake.AppVeyor().IsRunningOnAppVeyor)
                {
                    Cake.AppVeyor().UpdateBuildVersion(gitInfo.SafeNuGetVersion);
                }
            });

            Task("Default").IsDependentOn("Push-NuGet-Packages");
        }
Exemplo n.º 27
0
        public Build()
        {
            const string solutionName = "CK-Core";
            const string solutionFileName = solutionName + ".sln";

            var releasesDir = Cake.Directory( "CodeCakeBuilder/Releases" );
            SimpleRepositoryInfo gitInfo = null;
            // Configuration is either "Debug" or "Release".
            string configuration = null;

            // We do not publish .Tests projects for this solution.
            var projectsToPublish = Cake.ParseSolution( solutionFileName )
                                        .Projects
                                        .Where( p => p.Name != "CodeCakeBuilder"
                                                     && !p.Path.Segments.Contains( "Tests" ) );

            Task( "Check-Repository" )
                .Does( () =>
                {
                    gitInfo = Cake.GetSimpleRepositoryInfo();

                    if( !gitInfo.IsValid )
                    {
                        if( Cake.IsInteractiveMode()
                            && Cake.ReadInteractiveOption( "Repository is not ready to be published. Proceed anyway?", 'Y', 'N' ) == 'Y' )
                        {
                            Cake.Warning( "GitInfo is not valid, but you choose to continue..." );
                        }
                        else throw new Exception( "Repository is not ready to be published." );
                    }
                    configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";

                    Cake.Information( "Publishing {0} projects with version={1} and configuration={2}: {3}",
                        projectsToPublish.Count(),
                        gitInfo.SemVer,
                        configuration,
                        projectsToPublish.Select( p => p.Name ).Concatenate() );
                } );

            Task( "Restore-NuGet-Packages" )
                .Does( () =>
                {
                    Cake.NuGetRestore( solutionFileName );
                } );

            Task( "Clean" )
                .IsDependentOn( "Check-Repository" )
                .Does( () =>
                {
                    Cake.CleanDirectories( "**/bin/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( "**/obj/" + configuration, d => !d.Path.Segments.Contains( "CodeCakeBuilder" ) );
                    Cake.CleanDirectories( releasesDir );
                    Cake.DeleteFiles( "Tests/**/TestResult.xml" );
                } );

            Task( "Build" )
                .IsDependentOn( "Clean" )
                .IsDependentOn( "Restore-NuGet-Packages" )
                .IsDependentOn( "Check-Repository" )
                .Does( () =>
                {
                    using( var tempSln = Cake.CreateTemporarySolutionFile( solutionFileName ) )
                    {
                        tempSln.ExcludeProjectsFromBuild( "CodeCakeBuilder" );
                        Cake.MSBuild( tempSln.FullPath, settings =>
                        {
                            settings.Configuration = configuration;
                            settings.Verbosity = Verbosity.Minimal;
                            // Always generates Xml documentation. Relies on this definition in the csproj files:
                            //
                            // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                            //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                            // </PropertyGroup>
                            //
                            settings.Properties.Add( "GenerateDocumentation", new[] { "true" } );
                        } );
                    }
                } );

            Task( "Unit-Testing" )
                .IsDependentOn( "Build" )
                .Does( () =>
                {
                    Cake.CreateDirectory( releasesDir );
                    var testDlls = Cake.ParseSolution( solutionFileName )
                     .Projects
                         .Where( p => p.Name.EndsWith( ".Tests" ) )
                         .Select( p => p.Path.GetDirectory().CombineWithFilePath( "bin/" + configuration + "/" + p.Name + ".dll" ) );
                    Cake.Information( "Testing: {0}", string.Join( ", ", testDlls.Select( p => p.GetFilename().ToString() ) ) );

                    Cake.NUnit( testDlls, new NUnitSettings()
                    {
                        Framework = "v4.5",
                        OutputFile = releasesDir.Path + "/TestResult.txt"
                    } );
                } );

            Task( "Create-NuGet-Packages" )
                .IsDependentOn( "Unit-Testing" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    Cake.CreateDirectory( releasesDir );
                    var settings = new NuGetPackSettings()
                    {
                        Version = gitInfo.NuGetVersion,
                        BasePath = Cake.Environment.WorkingDirectory,
                        OutputDirectory = releasesDir
                    };
                    Cake.CopyFiles( "CodeCakeBuilder/NuSpec/*.nuspec", releasesDir );
                    foreach( var nuspec in Cake.GetFiles( releasesDir.Path + "/*.nuspec" ) )
                    {
                        TransformText( nuspec, configuration, gitInfo );
                        Cake.NuGetPack( nuspec, settings );
                    }
                    Cake.DeleteFiles( releasesDir.Path + "/*.nuspec" );
                } );


            Task( "Push-NuGet-Packages" )
                .IsDependentOn( "Create-NuGet-Packages" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    IEnumerable<FilePath> nugetPackages = Cake.GetFiles( releasesDir.Path + "/*.nupkg" );
                    if( Cake.IsInteractiveMode() )
                    {
                        var localFeed = Cake.FindDirectoryAbove( "LocalFeed" );
                        if( localFeed != null )
                        {
                            Cake.Information( "LocalFeed directory found: {0}", localFeed );
                            if( Cake.ReadInteractiveOption( "Do you want to publish to LocalFeed?", 'Y', 'N' ) == 'Y' )
                            {
                                Cake.CopyFiles( nugetPackages, localFeed );
                            }
                        }
                    }
                    if( gitInfo.IsValidRelease )
                    {
                        if( gitInfo.PreReleaseName == "" 
                            || gitInfo.PreReleaseName == "prerelease" 
                            || gitInfo.PreReleaseName == "rc" )
                        {
                            PushNuGetPackages( "NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages );
                        }
                        else
                        {
                            // An alpha, beta, delta, epsilon, gamma, kappa goes to invenietis-preview.
                            PushNuGetPackages( "MYGET_PREVIEW_API_KEY", "https://www.myget.org/F/invenietis-preview/api/v2/package", nugetPackages );
                        }
                    }
                    else
                    {
                        Debug.Assert( gitInfo.IsValidCIBuild );
                        PushNuGetPackages( "MYGET_CI_API_KEY", "https://www.myget.org/F/invenietis-ci/api/v2/package", nugetPackages );
                    }
                } );

            Task( "Build-DocFX" )
                .IsDependentOn( "Check-Repository" )
                .WithCriteria( () => gitInfo.IsValid )
                .Does( () =>
                {
                    var settingsFile = Cake.File("DocFX/docfx.json");
                    var settingsFileCopy = Cake.File("DocFX/docfx.json.old");
                    try
                    {
                        // Create a copy restored in finally{}
                        Cake.Information( $"Backing up {settingsFile} to {settingsFileCopy}" );
                        Cake.CopyFile( settingsFile, settingsFileCopy );

                        // Edit the settings file
                        // TODO: A proper visitor & rewriter; target properties are:
                        //   o.build.globalMetadata._appVersion
                        //   o.build.globalMetadata._appShortVersion
                        Cake.Information( $"Writing {settingsFile}" );
                        Cake.Information( $"* _appVersion: {gitInfo.SemVer}" );
                        Cake.Information( $"* _appShortVersion: {gitInfo.NuGetVersion}" );
                        File.WriteAllText(
                            settingsFile,
                            File.ReadAllText( settingsFile )
                                .Replace( "%%VERSION%%", gitInfo.SemVer )
                                .Replace( "%%SHORTVERSION%%", gitInfo.NuGetVersion )
                            );

                        // Build DocFX project
                        var docFxProjectFile = Cake.File("DocFX/DocFX.csproj");

                        Cake.Information( $"Building {docFxProjectFile}" );

                        Cake.MSBuild( docFxProjectFile, settings =>
                        {
                            settings.Configuration = configuration;
                            settings.Verbosity = Verbosity.Minimal;
                        } );

                        // Pack output
                        var outDir = Cake.Directory("DocFX/_site");  // Configured in DocFX/docfx.json
                        var outZip = releasesDir.Path.CombineWithFilePath( $@"{solutionName}.{gitInfo.SemVer}.DocFX.zip" );

                        Cake.Information( $"Packing {outDir} to {outZip}" );
                        Cake.Zip( outDir, outZip );
                    }
                    finally
                    {
                        // Delete existing file and restore file copy
                        if( Cake.FileExists( settingsFileCopy ) )
                        {
                            Cake.Information( $"Restoring {settingsFile}" );
                            if( Cake.FileExists( settingsFile ) ) { Cake.DeleteFile( settingsFile ); }
                            Cake.MoveFile( settingsFileCopy, settingsFile );
                        }
                    }
                } );

            // The Default task for this script can be set here.
            Task( "Default" )
                .IsDependentOn( "Push-NuGet-Packages" );

        }
Exemplo n.º 28
0
        public Build()
        {
            const string solutionName     = "CK-Core";
            const string solutionFileName = solutionName + ".sln";

            var releasesDir = Cake.Directory("CodeCakeBuilder/Releases");
            SimpleRepositoryInfo gitInfo = null;
            // Configuration is either "Debug" or "Release".
            string configuration = null;

            // We do not publish .Tests projects for this solution.
            var projectsToPublish = Cake.ParseSolution(solutionFileName)
                                    .Projects
                                    .Where(p => p.Name != "CodeCakeBuilder" &&
                                           !p.Path.Segments.Contains("Tests"));

            Task("Check-Repository")
            .Does(() =>
            {
                gitInfo = Cake.GetSimpleRepositoryInfo();

                if (!gitInfo.IsValid)
                {
                    if (Cake.IsInteractiveMode() &&
                        Cake.ReadInteractiveOption("Repository is not ready to be published. Proceed anyway?", 'Y', 'N') == 'Y')
                    {
                        Cake.Warning("GitInfo is not valid, but you choose to continue...");
                    }
                    else
                    {
                        throw new Exception("Repository is not ready to be published.");
                    }
                }
                configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";

                Cake.Information("Publishing {0} projects with version={1} and configuration={2}: {3}",
                                 projectsToPublish.Count(),
                                 gitInfo.SemVer,
                                 configuration,
                                 projectsToPublish.Select(p => p.Name).Concatenate());
            });

            Task("Restore-NuGet-Packages")
            .Does(() =>
            {
                Cake.NuGetRestore(solutionFileName);
            });

            Task("Clean")
            .IsDependentOn("Check-Repository")
            .Does(() =>
            {
                Cake.CleanDirectories("**/bin/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories("**/obj/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories(releasesDir);
                Cake.DeleteFiles("Tests/**/TestResult.xml");
            });

            Task("Build")
            .IsDependentOn("Clean")
            .IsDependentOn("Restore-NuGet-Packages")
            .IsDependentOn("Check-Repository")
            .Does(() =>
            {
                using (var tempSln = Cake.CreateTemporarySolutionFile(solutionFileName))
                {
                    tempSln.ExcludeProjectsFromBuild("CodeCakeBuilder");
                    Cake.MSBuild(tempSln.FullPath, settings =>
                    {
                        settings.Configuration = configuration;
                        settings.Verbosity     = Verbosity.Minimal;
                        // Always generates Xml documentation. Relies on this definition in the csproj files:
                        //
                        // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                        //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                        // </PropertyGroup>
                        //
                        settings.Properties.Add("GenerateDocumentation", new[] { "true" });
                    });
                }
            });

            Task("Unit-Testing")
            .IsDependentOn("Build")
            .Does(() =>
            {
                Cake.CreateDirectory(releasesDir);
                var testDlls = Cake.ParseSolution(solutionFileName)
                               .Projects
                               .Where(p => p.Name.EndsWith(".Tests"))
                               .Select(p => p.Path.GetDirectory().CombineWithFilePath("bin/" + configuration + "/" + p.Name + ".dll"));
                Cake.Information("Testing: {0}", string.Join(", ", testDlls.Select(p => p.GetFilename().ToString())));

                Cake.NUnit(testDlls, new NUnitSettings()
                {
                    Framework  = "v4.5",
                    OutputFile = releasesDir.Path + "/TestResult.txt"
                });
            });

            Task("Create-NuGet-Packages")
            .IsDependentOn("Unit-Testing")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                Cake.CreateDirectory(releasesDir);
                var settings = new NuGetPackSettings()
                {
                    Version         = gitInfo.NuGetVersion,
                    BasePath        = Cake.Environment.WorkingDirectory,
                    OutputDirectory = releasesDir
                };
                Cake.CopyFiles("CodeCakeBuilder/NuSpec/*.nuspec", releasesDir);
                foreach (var nuspec in Cake.GetFiles(releasesDir.Path + "/*.nuspec"))
                {
                    TransformText(nuspec, configuration, gitInfo);
                    Cake.NuGetPack(nuspec, settings);
                }
                Cake.DeleteFiles(releasesDir.Path + "/*.nuspec");
            });


            Task("Push-NuGet-Packages")
            .IsDependentOn("Create-NuGet-Packages")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                IEnumerable <FilePath> nugetPackages = Cake.GetFiles(releasesDir.Path + "/*.nupkg");
                if (Cake.IsInteractiveMode())
                {
                    var localFeed = Cake.FindDirectoryAbove("LocalFeed");
                    if (localFeed != null)
                    {
                        Cake.Information("LocalFeed directory found: {0}", localFeed);
                        if (Cake.ReadInteractiveOption("Do you want to publish to LocalFeed?", 'Y', 'N') == 'Y')
                        {
                            Cake.CopyFiles(nugetPackages, localFeed);
                        }
                    }
                }
                if (gitInfo.IsValidRelease)
                {
                    if (gitInfo.PreReleaseName == "" ||
                        gitInfo.PreReleaseName == "prerelease" ||
                        gitInfo.PreReleaseName == "rc")
                    {
                        PushNuGetPackages("NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages);
                    }
                    else
                    {
                        // An alpha, beta, delta, epsilon, gamma, kappa goes to invenietis-preview.
                        PushNuGetPackages("MYGET_PREVIEW_API_KEY", "https://www.myget.org/F/invenietis-preview/api/v2/package", nugetPackages);
                    }
                }
                else
                {
                    Debug.Assert(gitInfo.IsValidCIBuild);
                    PushNuGetPackages("MYGET_CI_API_KEY", "https://www.myget.org/F/invenietis-ci/api/v2/package", nugetPackages);
                }
            });

            Task("Build-DocFX")
            .IsDependentOn("Check-Repository")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                var settingsFile     = Cake.File("DocFX/docfx.json");
                var settingsFileCopy = Cake.File("DocFX/docfx.json.old");
                try
                {
                    // Create a copy restored in finally{}
                    Cake.Information($"Backing up {settingsFile} to {settingsFileCopy}");
                    Cake.CopyFile(settingsFile, settingsFileCopy);

                    // Edit the settings file
                    // TODO: A proper visitor & rewriter; target properties are:
                    //   o.build.globalMetadata._appVersion
                    //   o.build.globalMetadata._appShortVersion
                    Cake.Information($"Writing {settingsFile}");
                    Cake.Information($"* _appVersion: {gitInfo.SemVer}");
                    Cake.Information($"* _appShortVersion: {gitInfo.NuGetVersion}");
                    File.WriteAllText(
                        settingsFile,
                        File.ReadAllText(settingsFile)
                        .Replace("%%VERSION%%", gitInfo.SemVer)
                        .Replace("%%SHORTVERSION%%", gitInfo.NuGetVersion)
                        );

                    // Build DocFX project
                    var docFxProjectFile = Cake.File("DocFX/DocFX.csproj");

                    Cake.Information($"Building {docFxProjectFile}");

                    Cake.MSBuild(docFxProjectFile, settings =>
                    {
                        settings.Configuration = configuration;
                        settings.Verbosity     = Verbosity.Minimal;
                    });

                    // Pack output
                    var outDir = Cake.Directory("DocFX/_site");      // Configured in DocFX/docfx.json
                    var outZip = releasesDir.Path.CombineWithFilePath($@"{solutionName}.{gitInfo.SemVer}.DocFX.zip");

                    Cake.Information($"Packing {outDir} to {outZip}");
                    Cake.Zip(outDir, outZip);
                }
                finally
                {
                    // Delete existing file and restore file copy
                    if (Cake.FileExists(settingsFileCopy))
                    {
                        Cake.Information($"Restoring {settingsFile}");
                        if (Cake.FileExists(settingsFile))
                        {
                            Cake.DeleteFile(settingsFile);
                        }
                        Cake.MoveFile(settingsFileCopy, settingsFile);
                    }
                }
            });

            // The Default task for this script can be set here.
            Task("Default")
            .IsDependentOn("Push-NuGet-Packages");
        }
Exemplo n.º 29
0
    /// <summary>
    ///     Thanks to NuGet being an extension of VisualStudio instead of a proper standalone
    ///     tool (just look at the tight binding of 'nuget pack .xxproj' into MSBuild internals
    ///     and the massive amount of code just to manage that stuff), we cannot build NuGet
    ///     packages from existing binaries by just looking at the project and nuspec files.
    ///     Therefore we preemtively produce nuget packages as soon as the compiler finished
    ///     building the project (and before any testing has been done). We then copy the
    ///     NuGet package into a safe place before eventually pushing it to a server or achiving
    ///     the files by other means.
    /// </summary>
    /// <param name="project"></param>
    public static void ProduceNuGetPackage(ParsedProject project)
    {
        var nuspec = project.ProjectFile.ChangeExtension(".nuspec");

        if (!Context.FileExists(nuspec))
        {
            Context.Log.Verbose("Skipping package as there is no *.nuspec file for project "
                                + BuildConfig.AsRelativePath(project.ProjectFile));
            return;
        }

        var settings = new NuGetXPackSettings(PackSettings);

        if (PackSettingsCustomisation != null)
        {
            settings = PackSettingsCustomisation.Invoke(settings, project);
        }

        var nugetSettings = new NuGetPackSettings();

        XBuildHelper.ApplyToolSettings(nugetSettings, settings);
        nugetSettings.Verbosity = settings.Verbosity;
        nugetSettings.Symbols   = settings.Symbols.GetValueOrDefault();
        nugetSettings.IncludeReferencedProjects = settings.IncludeReferencedProjects.GetValueOrDefault();
        nugetSettings.Properties            = new Dictionary <string, string>(settings.Properties);
        nugetSettings.ArgumentCustomization = settings.ArgumentCustomization;

        if (NuGetPackSettingsCustomisation != null)
        {
            nugetSettings = NuGetPackSettingsCustomisation.Invoke(nugetSettings, project);
            if (nugetSettings.Properties == null)
            {
                nugetSettings.Properties = new Dictionary <string, string>();
            }
        }

        var targetPath = BuildConfig.ComputeOutputPath("packages", project);

        Context.CreateDirectory(targetPath);
        nugetSettings.WorkingDirectory            = targetPath;
        nugetSettings.Properties["Configuration"] = BuildConfig.Configuration;
        nugetSettings.Properties["Platform"]      = BuildConfig.ConvertPlatformTargetToString(project.Platform);
        if (!string.IsNullOrEmpty(Version))
        {
            Context.Log.Information("Publishing package as version " + Version);
            nugetSettings.Properties["version"] = Version;
            nugetSettings.Version = Version;
        }

        if (settings.Tool.GetValueOrDefault())
        {
            var argCustomization = nugetSettings.ArgumentCustomization;
            nugetSettings.ArgumentCustomization = args =>
            {
                if (argCustomization != null)
                {
                    args = argCustomization.Invoke(args);
                }
                args.Append("-Tool");
                return(args);
            };
        }

        Context.NuGetPack(project.ProjectFile, nugetSettings);

        var assembly = LoadZipAssembly();

        if (assembly != null)
        {
            Context.Log.Information("Unzipping nuget package: " + targetPath.FullPath + "/*.nupkg");
            foreach (var file in Context.Globber.GetFiles(targetPath.FullPath + "/*.nupkg"))
            {
                Context.Log.Information("Unzipping " + file);
                Unzip(file, targetPath, assembly);
            }
        }
    }
Exemplo n.º 30
0
 public static void NuGetPack(NuGetPackSettings settings)
 => Context.NuGetPack(settings);
Exemplo n.º 31
0
        public Build()
        {
            var    releasesDir           = Cake.Directory("CodeCakeBuilder/Releases");
            string configuration         = null;
            SimpleRepositoryInfo gitInfo = null;

            Task("Check-Repository")
            .Does(() =>
            {
                gitInfo = Cake.GetSimpleRepositoryInfo();
                if (!gitInfo.IsValid)
                {
                    configuration = "Debug";
                    Cake.Warning("Repository is not ready to be published. Setting configuration to {0}.", configuration);
                }
                else
                {
                    configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";
                    Cake.Information("Publishing {0} in {1}.", gitInfo.SemVer, configuration);
                }
            });

            Task("Clean")
            .IsDependentOn("Check-Repository")
            .Does(() =>
            {
                Cake.CleanDirectories("**/bin/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories("**/obj/" + configuration, d => !d.Path.Segments.Contains("CodeCakeBuilder"));
                Cake.CleanDirectories(releasesDir);
            });

            Task("Restore-NuGet-Packages")
            .Does(() =>
            {
                Cake.NuGetRestore("SGV-Net.sln");
            });

            Task("Build")
            .IsDependentOn("Clean")
            .IsDependentOn("Restore-NuGet-Packages")
            .IsDependentOn("Check-Repository")
            .Does(() =>
            {
                using (var tempSln = Cake.CreateTemporarySolutionFile("SGV-Net.sln"))
                {
                    tempSln.ExcludeProjectsFromBuild("CodeCakeBuilder");
                    Cake.MSBuild(tempSln.FullPath, settings =>
                    {
                        settings.Configuration = configuration;
                        settings.Verbosity     = Verbosity.Minimal;
                        // Always generates Xml documentation. Relies on this definition in the csproj files:
                        //
                        // <PropertyGroup Condition=" $(GenerateDocumentation) != '' ">
                        //   <DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
                        // </PropertyGroup>
                        //
                        settings.Properties.Add("GenerateDocumentation", new[] { "true" });
                    });
                }
            });

            Task("Unit-Testing")
            .IsDependentOn("Build")
            .Does(() =>
            {
                Cake.NUnit("Tests/*.Tests/bin/" + configuration + "/*.Tests.dll", new NUnitSettings()
                {
                    Framework = "v4.5"
                });
            });

            Task("Create-NuGet-Packages")
            .IsDependentOn("Unit-Testing")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                Cake.CreateDirectory(releasesDir);
                // Preparing SimpleGitVersion.DNXCommands/app folder.
                var dnxAppPath = releasesDir.Path + "/SimpleGitVersion.DNXCommands/app";
                Cake.CreateDirectory(dnxAppPath);
                Cake.CopyFiles("SimpleGitVersion.DNXCommands/NuGetAssets/app/*", dnxAppPath);
                TransformText(dnxAppPath + "/project.json", configuration, gitInfo);
                //
                var settings = new NuGetPackSettings()
                {
                    Version         = gitInfo.NuGetVersion,
                    BasePath        = Cake.Environment.WorkingDirectory,
                    OutputDirectory = releasesDir
                };
                Cake.CopyFiles("CodeCakeBuilder/NuSpec/*.nuspec", releasesDir);
                foreach (var nuspec in Cake.GetFiles(releasesDir.Path + "/*.nuspec"))
                {
                    TransformText(nuspec, configuration, gitInfo);
                    Cake.NuGetPack(nuspec, settings);
                }
                Cake.DeleteFiles(releasesDir.Path + "/*.nuspec");
                Cake.DeleteDirectory(dnxAppPath, true);
            });

            Task("Push-NuGet-Packages")
            .IsDependentOn("Create-NuGet-Packages")
            .WithCriteria(() => gitInfo.IsValid)
            .Does(() =>
            {
                IEnumerable <FilePath> nugetPackages = Cake.GetFiles(releasesDir.Path + "/*.nupkg");
                if (Cake.IsInteractiveMode())
                {
                    var localFeed = Cake.FindDirectoryAbove("LocalFeed");
                    if (localFeed != null)
                    {
                        Cake.Information("LocalFeed directory found: {0}", localFeed);
                        if (Cake.ReadInteractiveOption("Do you want to publish to LocalFeed?", 'Y', 'N') == 'Y')
                        {
                            Cake.CopyFiles(nugetPackages, localFeed);
                        }
                    }
                }
                if (gitInfo.IsValidRelease)
                {
                    PushNuGetPackages("NUGET_API_KEY", "https://www.nuget.org/api/v2/package", nugetPackages);
                }
                else
                {
                    Debug.Assert(gitInfo.IsValidCIBuild);
                    PushNuGetPackages("MYGET_EXPLORE_API_KEY", "https://www.myget.org/F/invenietis-explore/api/v2/package", nugetPackages);
                }
            });

            Task("Default").IsDependentOn("Push-NuGet-Packages");
        }
Exemplo n.º 32
0
 public static void NuGetPack(FilePath filePath, NuGetPackSettings settings)
 => Context.NuGetPack(filePath, settings);
Exemplo n.º 33
0
        public static void NuGetPack(this ICakeContext context, FilePath nuspecFilePath, NuGetPackSettings settings)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var packer = new NuGetPacker(context.FileSystem, context.Environment,
                                         context.Globber, context.ProcessRunner, context.Log);

            packer.Pack(nuspecFilePath, settings);
        }