Skip to content

Commit

Permalink
Merge branch 'release/0.21.0'
Browse files Browse the repository at this point in the history
* release/0.21.0:
  (#103) Adds WiX Tool Dependency
  (#103) Adds MsiUsedWithinNupkg
  (#98) Adds Optional Docker Steps
  (#96) Adds Optional SonarQube Step
  (maint) Add full stop to each entry
  • Loading branch information
gep13 committed Mar 10, 2023
2 parents 6d5736b + 2915722 commit 206526a
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Chocolatey.Cake.Recipe/Content/addins.cake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
///////////////////////////////////////////////////////////////////////////////

#addin nuget:?package=Cake.Coverlet&version=2.5.4
#addin nuget:?package=Cake.Docker&version=1.0.0
#addin nuget:?package=Cake.Eazfuscator.Net&version=0.1.0
#addin nuget:?package=Cake.Figlet&version=1.2.0
#addin nuget:?package=Cake.FileHelpers&version=3.2.0
Expand All @@ -34,6 +35,7 @@
#addin nuget:?package=Cake.Npm&version=0.16.0
#addin nuget:?package=Cake.PowerShell&version=0.4.8
#addin nuget:?package=Cake.ReSharperReports&version=0.10.0
#addin nuget:?package=Cake.Sonar&version=1.1.26
#addin nuget:?package=Cake.StrongNameSigner&version=0.1.0
#addin nuget:?package=Cake.StrongNameTool&version=0.0.5
#addin nuget:?package=Cake.Transifex&version=1.0.1
Expand Down
15 changes: 12 additions & 3 deletions Chocolatey.Cake.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ BuildParameters.Tasks.BuildMsiTask = Task("Build-MSI")
.IsDependentOn("Sign-Assemblies")
.IsDependeeOf("Sign-Msis")
.WithCriteria(() => BuildParameters.ShouldBuildMsi, "Skipping because building of MSI has been disabled")
.Does(() => RequireTool(ToolSettings.MSBuildExtensionPackTool, () => {
.Does(() => RequireTool(ToolSettings.WixTool, () => RequireTool(ToolSettings.MSBuildExtensionPackTool, () => {
Information("Building MSI from the following solution: {0}", BuildParameters.SolutionFilePath);

var msbuildSettings = new MSBuildSettings
Expand All @@ -473,7 +473,7 @@ BuildParameters.Tasks.BuildMsiTask = Task("Build-MSI")

MSBuild(BuildParameters.SolutionFilePath, msbuildSettings);
})
);
));

BuildParameters.Tasks.DefaultTask = Task("Default")
.IsDependentOn("Package");
Expand Down Expand Up @@ -551,7 +551,6 @@ public class Builder
BuildParameters.Tasks.CreateNuGetPackagesTask.IsDependentOn("Sign-PowerShellScripts");
BuildParameters.Tasks.CreateNuGetPackagesTask.IsDependentOn("Sign-Assemblies");
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn("Sign-PowerShellScripts");
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn("Sign-Msis");
BuildParameters.Tasks.SignMsisTask.IsDependentOn("Sign-Assemblies");
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.ObfuscateAssembliesTask.IsDependeeOf("Sign-Assemblies");
Expand All @@ -562,6 +561,16 @@ public class Builder
BuildParameters.Tasks.ConfigurationBuilderTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Build");

if (BuildParameters.MsiUsedWithinNupkg)
{
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn("Sign-Msis");
}
else
{
BuildParameters.Tasks.BuildMsiTask.IsDependentOn("Create-Chocolatey-Packages");
BuildParameters.Tasks.PackageTask.IsDependentOn("Sign-Msis");
}

if (!isDotNetBuild)
{
if (BuildParameters.ShouldRunTransifex)
Expand Down
45 changes: 45 additions & 0 deletions Chocolatey.Cake.Recipe/Content/credentials.cake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ public class PackageSourceCredentials
}
}

public class SonarQubeCredentials
{
public string Token { get; private set; }

public SonarQubeCredentials(string token)
{
Token = token;
}
}

public class DockerCredentials
{
public string Server { get; private set; }
public string User { get; private set; }
public string Password { get; private set; }

public bool HasCredentials
{
get { return !string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Password); }
}

public DockerCredentials(string user, string password, string server = null)
{
Server = server;
User = user;
Password = password;
}
}

public static GitHubCredentials GetGitHubCredentials(ICakeContext context)
{
string token = null;
Expand All @@ -74,4 +103,20 @@ public static TransifexCredentials GetTransifexCredentials(ICakeContext context)
return new TransifexCredentials(
context.EnvironmentVariable(Environment.TransifexApiTokenVariable)
);
}

public static SonarQubeCredentials GetSonarQubeCredentials(ICakeContext context)
{
return new SonarQubeCredentials(
context.EnvironmentVariable(Environment.SonarQubeTokenVariable)
);
}

public static DockerCredentials GetDockerCredentials(ICakeContext context)
{
return new DockerCredentials(
context.EnvironmentVariable(Environment.DockerUserVariable),
context.EnvironmentVariable(Environment.DockerPasswordVariable),
context.EnvironmentVariable(Environment.DockerServerVariable)
);
}
123 changes: 123 additions & 0 deletions Chocolatey.Cake.Recipe/Content/docker.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright © 2023 Chocolatey Software, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

BuildParameters.Tasks.DockerLogin = Task("DockerLogin")
.WithCriteria(() => BuildParameters.DockerCredentials.HasCredentials, "Skipping because Docker Credentials were not provided.")
.Does(() =>
{
DockerLogin(
BuildParameters.DockerCredentials.User,
BuildParameters.DockerCredentials.Password,
BuildParameters.DockerCredentials.Server
);
});

BuildParameters.Tasks.DockerBuild = Task("DockerBuild")
.Does(() =>
{
var platform = BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows ? "windows" : "linux";

var dockerBuildSettings = new DockerImageBuildSettings();
dockerBuildSettings.Tag = new string[] {
string.Format("{0}/{1}:v{2}-{3}", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.MajorMinorPatch, platform)
};
dockerBuildSettings.File = string.Format("docker/Dockerfile.{0}", platform);

if (platform == "linux")
{
dockerBuildSettings.BuildArg = new string[] {
"buildscript=build.official.sh"
};
}

DockerBuild(
dockerBuildSettings,
BuildParameters.RootDirectoryPath.ToString()
);
});

BuildParameters.Tasks.DockerPush = Task("DockerPush")
.WithCriteria(() => BuildParameters.IsTagged && BuildParameters.Version.MajorMinorPatch == BuildParameters.Version.FullSemVersion, "Skipping because this isn't a tagged full release build.")
.WithCriteria(() => BuildParameters.DockerCredentials.HasCredentials, "Skipping because Docker Credentials were not provided.")
.IsDependentOn("DockerLogin")
.IsDependentOn("DockerBuild")
.Does(() =>
{
var platform = BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows ? "windows" : "linux";

DockerPush(
string.Format("{0}/{1}:v{2}-{3}", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.MajorMinorPatch, platform)
);
});

BuildParameters.Tasks.DockerTagAsLatest = Task("DockerTagAsLatest")
.WithCriteria(() => BuildParameters.IsTagged && BuildParameters.Version.MajorMinorPatch == BuildParameters.Version.FullSemVersion, "Skipping because this isn't a tagged full release build.")
.WithCriteria(() => BuildParameters.DockerCredentials.HasCredentials, "Skipping because Docker Credentials were not provided.")
.IsDependentOn("DockerLogin")
.IsDependentOn("DockerBuild")
.IsDependentOn("DockerPush")
.Does(() =>
{
var platform = BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows ? "windows" : "linux";
var latestPlatformTag = string.Format("{0}/{1}:latest-{2}", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, platform);

DockerTag(
string.Format("{0}/{1}:v{2}-{3}", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.MajorMinorPatch, platform),
latestPlatformTag
);

DockerPush(
latestPlatformTag
);
});

BuildParameters.Tasks.Docker = Task("Docker")
.IsDependentOn("DockerLogin")
.IsDependentOn("DockerBuild")
.IsDependentOn("DockerPush")
.IsDependentOn("DockerTagAsLatest");

BuildParameters.Tasks.DockerManifest = Task("DockerManifest")
.WithCriteria(() => BuildParameters.IsTagged && BuildParameters.Version.MajorMinorPatch == BuildParameters.Version.FullSemVersion, "Skipping because this isn't a tagged full release build.")
.WithCriteria(() => BuildParameters.DockerCredentials.HasCredentials, "Skipping because Docker Credentials were not provided.")
.IsDependentOn("DockerLogin")
.Does(() =>
{
// Note: This will fail if one of the expected tags are not available, so it's important to ensure other builds have completed.

// Create the version manifest
var manifestListName = string.Format("{0}/{1}:v{2}", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.MajorMinorPatch);

DockerManifestCreate(
manifestListName,
string.Format("{0}-windows", manifestListName),
new string[] {
string.Format("{0}-linux", manifestListName)
}
);

DockerManifestPush(manifestListName);

// Create the latest manifest
DockerManifestCreate(
string.Format("{0}/{1}:latest", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName),
string.Format("{0}/{1}:latest-windows", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName),
new string[] {
string.Format("{0}/{1}:latest-linux", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName)
}
);

DockerManifestPush(string.Format("{0}/{1}:latest", BuildParameters.RepositoryOwner, BuildParameters.RepositoryName));
});
20 changes: 19 additions & 1 deletion Chocolatey.Cake.Recipe/Content/environment.cake
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,32 @@ public static class Environment
public static string DefaultPushSourceUrlVariable { get; private set; }
public static string GitHubTokenVariable { get; private set; }
public static string TransifexApiTokenVariable { get; private set; }
public static string SonarQubeTokenVariable { get; private set; }
public static string SonarQubeIdVariable { get; private set; }
public static string SonarQubeUrlVariable { get; private set; }
public static string DockerUserVariable { get; private set; }
public static string DockerPasswordVariable { get; private set; }
public static string DockerServerVariable { get; private set; }

public static void SetVariableNames(
string defaultPushSourceUrlVariable = null,
string gitHubTokenVariable = null,
string transifexApiTokenVariable = null)
string transifexApiTokenVariable = null,
string sonarQubeTokenVariable = null,
string sonarQubeIdVariable = null,
string sonarQubeUrlVariable = null,
string dockerUserVariable = null,
string dockerPasswordVariable = null,
string dockerServerVariable = null)
{
DefaultPushSourceUrlVariable = defaultPushSourceUrlVariable ?? "NUGETDEVPUSH_SOURCE";
GitHubTokenVariable = gitHubTokenVariable ?? "GITHUB_PAT";
TransifexApiTokenVariable = transifexApiTokenVariable ?? "TRANSIFEX_API_TOKEN";
SonarQubeTokenVariable = sonarQubeTokenVariable ?? "SONARQUBE_TOKEN";
SonarQubeIdVariable = sonarQubeIdVariable ?? "SONARQUBE_ID";
SonarQubeUrlVariable = sonarQubeUrlVariable ?? "SONARQUBE_URL";
DockerUserVariable = dockerUserVariable ?? "DOCKER_USER";
DockerPasswordVariable = dockerPasswordVariable ?? "DOCKER_PASSWORD";
DockerServerVariable = dockerServerVariable ?? "DOCKER_SERVER";
}
}
33 changes: 32 additions & 1 deletion Chocolatey.Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static class BuildParameters
public static string Configuration { get; private set; }
public static string DeploymentEnvironment { get; private set; }
public static string DevelopBranchName { get; private set; }
public static DockerCredentials DockerCredentials { get; private set; }
public static bool ForceContinuousIntegration { get; private set; }
public static FilePath FullReleaseNotesFilePath { get; private set; }
public static Func<FilePathCollection> GetFilesToObfuscate { get; private set; }
Expand All @@ -61,6 +62,7 @@ public static class BuildParameters
public static bool IsTagged { get; private set; }
public static string MasterBranchName { get; private set; }
public static FilePath MilestoneReleaseNotesFilePath { get; private set; }
public static bool MsiUsedWithinNupkg { get; private set; }
public static string NuGetNupkgGlobbingPattern { get; private set; }
public static string NuGetNuspecGlobbingPattern { get; private set; }
public static ICollection<string> NuGetSources { get; private set; }
Expand Down Expand Up @@ -109,12 +111,16 @@ public static class BuildParameters
public static bool ShouldRunOpenCover { get; private set; }
public static bool ShouldRunReportGenerator { get; private set; }
public static bool ShouldRunReportUnit { get; private set; }
public static bool ShouldRunSonarQube { get; private set; }
public static bool ShouldRunTransifex { get; set; }
public static bool ShouldRunxUnit { get; private set; }
public static bool ShouldStrongNameOutputAssemblies { get; private set; }
public static bool ShouldStrongNameSignDependentAssemblies { get; private set; }
public static DirectoryPath SolutionDirectoryPath { get; private set; }
public static FilePath SolutionFilePath { get; private set; }
public static string SonarQubeId { get; private set; }
public static string SonarQubeToken { get; private set; }
public static string SonarQubeUrl { get; private set; }
public static DirectoryPath SourceDirectoryPath { get; private set; }
public static string StrongNameDependentAssembliesInputPath { get; private set; }
public static string StrongNameKeyPath { get; private set; }
Expand Down Expand Up @@ -224,12 +230,15 @@ public static class BuildParameters
context.Information("ShouldRunOpenCover: {0}", BuildParameters.ShouldRunOpenCover);
context.Information("ShouldRunReportGenerator: {0}", BuildParameters.ShouldRunReportGenerator);
context.Information("ShouldRunReportUnit: {0}", BuildParameters.ShouldRunReportUnit);
context.Information("ShouldRunSonarQube: {0}", BuildParameters.ShouldRunSonarQube);
context.Information("ShouldRunTransifex: {0}", BuildParameters.ShouldRunTransifex);
context.Information("ShouldRunxUnit: {0}", BuildParameters.ShouldRunxUnit);
context.Information("ShouldStrongNameOutputAssemblies: {0}", BuildParameters.ShouldStrongNameOutputAssemblies);
context.Information("ShouldStrongNameSignDependentAssemblies: {0}", BuildParameters.ShouldStrongNameSignDependentAssemblies);
context.Information("SolutionFilePath: {0}", context.MakeAbsolute((FilePath)SolutionFilePath));
context.Information("SolutionDirectoryPath: {0}", context.MakeAbsolute((DirectoryPath)SolutionDirectoryPath));
context.Information("SolutionFilePath: {0}", context.MakeAbsolute((FilePath)SolutionFilePath));
context.Information("SonarQubeId: {0}", BuildParameters.SonarQubeId);
context.Information("SonarQubeUrl: {0}", BuildParameters.SonarQubeUrl);
context.Information("SourceDirectoryPath: {0}", context.MakeAbsolute(SourceDirectoryPath));
context.Information("StrongNameDependentAssembliesInputPath: {0}", StrongNameDependentAssembliesInputPath);
context.Information("Target: {0}", Target);
Expand Down Expand Up @@ -270,6 +279,7 @@ public static class BuildParameters
string integrationTestScriptPath = null,
string masterBranchName = "master",
FilePath milestoneReleaseNotesFilePath = null,
bool msiUsedWithinNupkg = true,
string nuGetNupkgGlobbingPattern = "/**/*.nupkg",
string nuGetNuspecGlobbingPattern = "/**/*.nuspec",
ICollection<string> nuGetSources = null,
Expand Down Expand Up @@ -316,12 +326,15 @@ public static class BuildParameters
bool shouldRunOpenCover = true,
bool shouldRunReportGenerator = true,
bool shouldRunReportUnit = true,
bool shouldRunSonarQube = false,
bool? shouldRunTransifex = null,
bool shouldRunxUnit = true,
bool shouldStrongNameOutputAssemblies = true,
bool shouldStrongNameSignDependentAssemblies = true,
DirectoryPath solutionDirectoryPath = null,
FilePath solutionFilePath = null,
string sonarQubeId = null,
string sonarQubeUrl = null,
string strongNameDependentAssembliesInputPath = null,
DirectoryPath testDirectoryPath = null,
TransifexMode transifexPullMode = TransifexMode.OnlyTranslated,
Expand Down Expand Up @@ -368,6 +381,7 @@ public static class BuildParameters
ChocolateyNupkgGlobbingPattern = chocolateyNupkgGlobbingPattern;
ChocolateyNuspecGlobbingPattern = chocolateyNuspecGlobbingPattern;
Configuration = context.Argument("configuration", "Release");
DockerCredentials = GetDockerCredentials(context);
DeploymentEnvironment = context.Argument("environment", "Release");
DevelopBranchName = developBranchName;
ForceContinuousIntegration = context.Argument("forceContinuousIntegration", false);
Expand All @@ -389,6 +403,7 @@ public static class BuildParameters
IsTagged = BuildProvider.Repository.Tag.IsTag;
MasterBranchName = masterBranchName;
MilestoneReleaseNotesFilePath = milestoneReleaseNotesFilePath ?? RootDirectoryPath.CombineWithFilePath("CHANGELOG.md");
MsiUsedWithinNupkg = msiUsedWithinNupkg;
NuGetNupkgGlobbingPattern = nuGetNupkgGlobbingPattern;
NuGetNuspecGlobbingPattern = nuGetNuspecGlobbingPattern;
NuGetSources = nuGetSources;
Expand Down Expand Up @@ -440,12 +455,28 @@ public static class BuildParameters

ShouldRunReportGenerator = shouldRunReportGenerator;
ShouldRunReportUnit = shouldRunReportUnit;

if (context.HasArgument("shouldRunSonarQube"))
{
ShouldRunSonarQube = context.Argument<bool>("shouldRunSonarQube");
}
else
{
if (BuildParameters.IsTagged && !BuildParameters.IsLocalBuild)
{
ShouldRunSonarQube = true;
}
}

ShouldRunTransifex = shouldRunTransifex ?? TransifexIsConfiguredForRepository(context);
ShouldRunxUnit = shouldRunxUnit;
ShouldStrongNameOutputAssemblies = shouldStrongNameOutputAssemblies;
ShouldStrongNameSignDependentAssemblies = shouldStrongNameSignDependentAssemblies;
SolutionDirectoryPath = solutionDirectoryPath ?? sourceDirectoryPath.Combine(title);
SolutionFilePath = solutionFilePath ?? sourceDirectoryPath.CombineWithFilePath(title + ".sln");
SonarQubeId = sonarQubeId ?? context.EnvironmentVariable(Environment.SonarQubeIdVariable) ?? RootDirectoryPath.GetDirectoryName().ToLower();
SonarQubeToken = GetSonarQubeCredentials(context).Token;
SonarQubeUrl = sonarQubeUrl ?? context.EnvironmentVariable(Environment.SonarQubeUrlVariable) ?? null;
SourceDirectoryPath = sourceDirectoryPath;
StrongNameDependentAssembliesInputPath = strongNameDependentAssembliesInputPath ?? sourceDirectoryPath.Combine("packages").FullPath;
Target = context.Argument("target", "Default");
Expand Down
Loading

0 comments on commit 206526a

Please sign in to comment.