Skip to content

Commit

Permalink
Merge branch 'release/0.26.0'
Browse files Browse the repository at this point in the history
* release/0.26.0:
  (maint) Remove unused property
  (#129) Change credential name
  (#129) Update to latest GitReleaseManager
  (#129) Adjust tasks to know when running on GitLab
  (#129) Remove interaction between Tasks
  (#129) Remove unnecessary tasks
  (maint) Remove whitespace and fix formatting
  (#32) Add PSScriptAnalyzer
  (#127) Make Dependency-Check paths absolute
  (maint) Update GRM configuration
  • Loading branch information
gep13 committed Jan 5, 2024
2 parents 3594bf7 + 1fc8817 commit 775cf9b
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 75 deletions.
3 changes: 2 additions & 1 deletion Chocolatey.Cake.Recipe/Content/analyzing.cake
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ BuildParameters.Tasks.DotNetFormatTask = Task("Run-DotNetFormat")
{
dotNetFormatTool = Context.Tools.Resolve("dotnet-format");
}

StartProcess(dotNetFormatTool, new ProcessSettings{ Arguments = string.Format("{0} --report {1} --no-restore", MakeAbsolute(BuildParameters.SolutionFilePath), MakeAbsolute(BuildParameters.Paths.Files.DotNetFormatOutputFilePath)) });
})
);
Expand All @@ -123,4 +123,5 @@ BuildParameters.Tasks.AnalyzeTask = Task("Analyze")
.IsDependentOn("InspectCode")
.IsDependentOn("Run-DotNetFormatCheck")
.IsDependentOn("CreateIssuesReport")
.IsDependentOn("Run-PSScriptAnalyzer")
.WithCriteria(() => BuildParameters.ShouldRunAnalyze, "Skipping because running analysis tasks is not enabled");
6 changes: 1 addition & 5 deletions Chocolatey.Cake.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ BuildParameters.Tasks.ContinuousIntegrationTask = Task("CI")
.IsDependentOn("Publish-PreRelease-Packages")
.IsDependentOn("Publish-Release-Packages")
.IsDependentOn("Publish-AWS-Lambdas")
.IsDependentOn("Publish-GitHub-Release")
.Finally(() =>
{
if (publishingError)
Expand All @@ -521,9 +520,6 @@ BuildParameters.Tasks.ContinuousIntegrationTask = Task("CI")
BuildParameters.Tasks.ReleaseNotesTask = Task("ReleaseNotes")
.IsDependentOn("Create-Release-Notes");

BuildParameters.Tasks.LabelsTask = Task("Labels")
.IsDependentOn("Create-Default-Labels");

///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -631,7 +627,7 @@ public class Builder
BuildParameters.Tasks.TestTask.IsDependentOn("Generate-FriendlyCoverageReport");
BuildParameters.Tasks.TestTask.IsDependentOn("Report-UnitTestResults");
BuildParameters.Tasks.TestTask.IsDependentOn("Report-Code-Coverage-Metrics");

BuildParameters.Tasks.PublishAwsLambdasTask.IsDependentOn("DotNetBuild");

BuildParameters.Tasks.PackageTask.IsDependentOn(prefix + "Pack");
Expand Down
20 changes: 4 additions & 16 deletions Chocolatey.Cake.Recipe/Content/credentials.cake
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class DiscordCredentials
}
}

public class GitHubCredentials
public class GitReleaseManagerCredentials
{
public string Token { get; private set; }

public GitHubCredentials(string token)
public GitReleaseManagerCredentials(string token)
{
Token = token;
}
Expand Down Expand Up @@ -144,21 +144,9 @@ public static DiscordCredentials GetDiscordCredentials(ICakeContext context)
);
}

public static GitHubCredentials GetGitHubCredentials(ICakeContext context)
public static GitReleaseManagerCredentials GetGitReleaseManagerCredentials(ICakeContext context)
{
string token = null;
// if "GitHubTokenVariable" is not set, fallback to the gh-cli defaults of GH_TOKEN, GITHUB_TOKEN
var variableNames = new[]{ Environment.GitHubTokenVariable, "GH_TOKEN", "GITHUB_TOKEN" };
foreach (var name in variableNames)
{
token = context.EnvironmentVariable(name);
if (!string.IsNullOrEmpty(token))
{
break;
}
}

return new GitHubCredentials(token);
return new GitReleaseManagerCredentials(context.EnvironmentVariable(Environment.GitReleaseManagerTokenVariable));
}

public static MastodonCredentials GetMastodonCredentials(ICakeContext context)
Expand Down
10 changes: 5 additions & 5 deletions Chocolatey.Cake.Recipe/Content/environment.cake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class Environment
public static string DiscordWebHookUrlVariable { get; private set; }
public static string DiscordUserNameVariable { get; private set; }
public static string DiscordAvatarUrlVariable { get; private set; }
public static string GitHubTokenVariable { get; private set; }
public static string GitReleaseManagerTokenVariable { get; private set; }
public static string MastodonHostNameVariable { get; private set; }
public static string MastodonTokenVariable { get; private set; }
public static string SlackChannelVariable { get; private set; }
Expand All @@ -28,7 +28,7 @@ public static class Environment
public static string TwitterConsumerKeyVariable { get; private set; }
public static string TwitterConsumerSecretVariable { get; private set; }
public static string TwitterAccessTokenVariable { get; private set; }
public static string TwitterAccessTokenSecretVariable { get; private set; }
public static string TwitterAccessTokenSecretVariable { get; private set; }
public static string SonarQubeTokenVariable { get; private set; }
public static string SonarQubeIdVariable { get; private set; }
public static string SonarQubeUrlVariable { get; private set; }
Expand All @@ -41,7 +41,7 @@ public static class Environment
string discordWebHookUrlVariable = null,
string discordUserNameVariable = null,
string discordAvatarUrlVariable = null,
string gitHubTokenVariable = null,
string gitReleaseManagerTokenVariable = null,
string mastodonHostNameVariable = null,
string mastodonTokenVariable = null,
string slackChannelVariable = null,
Expand All @@ -62,7 +62,7 @@ public static class Environment
DiscordWebHookUrlVariable = discordWebHookUrlVariable ?? "DISCORD_WEBHOOKURL";
DiscordUserNameVariable = discordUserNameVariable ?? "DISCORD_USERNAME";
DiscordAvatarUrlVariable = discordAvatarUrlVariable ?? "DISCORD_AVATARURL";
GitHubTokenVariable = gitHubTokenVariable ?? "GITHUB_PAT";
GitReleaseManagerTokenVariable = gitReleaseManagerTokenVariable ?? "GITRELEASEMANAGER_PAT";
MastodonHostNameVariable = mastodonHostNameVariable ?? "MASTODON_HOSTNAME";
MastodonTokenVariable = mastodonTokenVariable ?? "MASTODON_TOKEN";
SlackChannelVariable = slackChannelVariable ?? "SLACK_CHANNEL";
Expand All @@ -71,7 +71,7 @@ public static class Environment
TwitterConsumerKeyVariable = twitterConsumerKeyVariable ?? "TWITTER_CONSUMER_KEY";
TwitterConsumerSecretVariable = twitterConsumerSecretVariable ?? "TWITTER_CONSUMER_SECRET";
TwitterAccessTokenVariable = twitterAccessTokenVariable ?? "TWITTER_ACCESS_TOKEN";
TwitterAccessTokenSecretVariable = twitterAccessTokenSecretVariable ?? "TWITTER_ACCESS_TOKEN_SECRET";
TwitterAccessTokenSecretVariable = twitterAccessTokenSecretVariable ?? "TWITTER_ACCESS_TOKEN_SECRET";
SonarQubeTokenVariable = sonarQubeTokenVariable ?? "SONARQUBE_TOKEN";
SonarQubeIdVariable = sonarQubeIdVariable ?? "SONARQUBE_ID";
SonarQubeUrlVariable = sonarQubeUrlVariable ?? "SONARQUBE_URL";
Expand Down
70 changes: 70 additions & 0 deletions Chocolatey.Cake.Recipe/Content/formatting-settings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@{
IncludeRules = @(
'PSUseBOMForUnicodeEncodedFile',
'PSMisleadingBacktick',
'PSAvoidUsingCmdletAliases',
'PSAvoidTrailingWhitespace',
'PSAvoidSemicolonsAsLineTerminators',
'PSUseCorrectCasing',
'PSPlaceOpenBrace',
'PSPlaceCloseBrace',
'PSAlignAssignmentStatement',
'PSUseConsistentWhitespace',
'PSUseConsistentIndentation'
)

Rules = @{

<#
PSAvoidUsingCmdletAliases = @{
'allowlist' = @('')
}#>

PSAvoidSemicolonsAsLineTerminators = @{
Enable = $true
}

PSUseCorrectCasing = @{
Enable = $true
}

PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
NewLineAfter = $true
IgnoreOneLineBlock = $false
}

PSPlaceCloseBrace = @{
Enable = $true
NewLineAfter = $true
IgnoreOneLineBlock = $false
NoEmptyLineBefore = $true
}

PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}

PSUseConsistentIndentation = @{
Enable = $true
Kind = 'space'
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
IndentationSize = 4
}

PSUseConsistentWhitespace = @{
Enable = $true
CheckInnerBrace = $true
CheckOpenBrace = $true
CheckOpenParen = $true
CheckOperator = $true
CheckPipe = $true
CheckPipeForRedundantWhitespace = $false
CheckSeparator = $true
CheckParameter = $false
IgnoreAssignmentOperatorInsideHashTable = $true
}
}
}
73 changes: 37 additions & 36 deletions Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ BuildParameters.Tasks.CreateReleaseNotesTask = Task("Create-Release-Notes")
TargetCommitish = BuildParameters.MasterBranchName,
Prerelease = Context.HasArgument("create-pre-release")
};

if (settings.Prerelease)
{
settings.TargetCommitish = BuildParameters.BuildProvider.Repository.Branch;
}

GitReleaseManagerCreate(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, settings);
if (BuildParameters.RepositoryHostedInGitLab)
{
settings.ArgumentCustomization = args => args.Append("--provider GitLab");
}

GitReleaseManagerCreate(BuildParameters.GitReleaseManager.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, settings);
}
else
{
Expand All @@ -51,19 +57,23 @@ BuildParameters.Tasks.ExportReleaseNotesTask = Task("Export-Release-Notes")
.Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => {
if (BuildParameters.CanRunGitReleaseManager)
{
var settings = new GitReleaseManagerExportSettings();

if (BuildParameters.RepositoryHostedInGitLab)
{
settings.ArgumentCustomization = args => args.Append("--provider GitLab");
}

if (BuildParameters.ShouldDownloadMilestoneReleaseNotes)
{
var settings = new GitReleaseManagerExportSettings
{
TagName = BuildParameters.Version.Milestone
};
settings.TagName = BuildParameters.Version.Milestone;

GitReleaseManagerExport(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.MilestoneReleaseNotesFilePath, settings);
GitReleaseManagerExport(BuildParameters.GitReleaseManager.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.MilestoneReleaseNotesFilePath, settings);
}

if (BuildParameters.ShouldDownloadFullReleaseNotes)
{
GitReleaseManagerExport(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.FullReleaseNotesFilePath);
GitReleaseManagerExport(BuildParameters.GitReleaseManager.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.FullReleaseNotesFilePath, settings);
}
}
else
Expand All @@ -74,47 +84,38 @@ BuildParameters.Tasks.ExportReleaseNotesTask = Task("Export-Release-Notes")
);

BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release")
.IsDependentOn("Package")
.WithCriteria(() => !BuildParameters.IsLocalBuild, "Skipping because this is a local build")
.WithCriteria(() => !BuildParameters.IsPullRequest, "Skipping because this is pull request")
.WithCriteria(() => BuildParameters.BranchType == BranchType.Master || BuildParameters.BranchType == BranchType.Release || BuildParameters.BranchType == BranchType.HotFix, "Skipping because this is not a releasable branch")
.WithCriteria(() => BuildParameters.IsTagged, "Skipping because this is not a tagged build")
.WithCriteria(() => BuildParameters.ShouldRunGitReleaseManager, "Skipping because this publishing running GitReleaseManager is disabled via parameters (perhaps the default value?")
.Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => {
if (BuildParameters.CanRunGitReleaseManager)
{
// Concatenating FilePathCollections should make sure we get unique FilePaths
foreach (var package in GetFiles(BuildParameters.Paths.Directories.Packages + "/*") +
GetFiles(BuildParameters.Paths.Directories.NuGetPackages + "/*") +
GetFiles(BuildParameters.Paths.Directories.ChocolateyPackages + "/*"))
// If we are running on GitLab, then we need to actually publish the Release,
// since it will have been created with a date in the future. When running on
// GitHub, this isn't required, since the Release is first created in Draft,
// and it is published this the GitHub UI.
if (BuildParameters.RepositoryHostedInGitLab)
{
GitReleaseManagerAddAssets(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.Milestone, package.ToString());
var publishSettings = new GitReleaseManagerPublishSettings {
ArgumentCustomization = args => args.Append("--provider GitLab")
};

GitReleaseManagerPublish(BuildParameters.GitReleaseManager.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.Milestone, publishSettings);
}

GitReleaseManagerClose(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.Milestone);
}
else
{
Warning("Unable to use GitReleaseManager, as necessary credentials are not available");
}
})
)
.OnError(exception =>
{
Error(exception.Message);
Information("Publish-GitHub-Release Task failed, but continuing with next Task...");
publishingError = true;
});
// Next up, we close the milestone, which based on configuration, may add comments
// to issues contained within the specified Milestone.
var closeSettings = new GitReleaseManagerCloseMilestoneSettings();

BuildParameters.Tasks.CreateDefaultLabelsTask = Task("Create-Default-Labels")
.Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => {
if (BuildParameters.CanRunGitReleaseManager)
{
GitReleaseManagerLabel(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName);
if (BuildParameters.RepositoryHostedInGitLab)
{
closeSettings.ArgumentCustomization = args => args.Append("--provider GitLab");
}

GitReleaseManagerClose(BuildParameters.GitReleaseManager.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName, BuildParameters.Version.Milestone, closeSettings);
}
else
{
Warning("Unable to use GitReleaseManager, as necessary credentials are not available");
}
})
);
);
34 changes: 34 additions & 0 deletions Chocolatey.Cake.Recipe/Content/install-module.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

[cmdletBinding()]
Param(
[Parameter()]
[String]
$ModuleName,

[Parameter()]
[String]
$RequiredVersion
)

$FullyQualifiedName = @{ModuleName="$ModuleName";RequiredVersion="$RequiredVersion"}
if (Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName) {
Write-Host "The $ModuleName PowerShell Module with version $RequiredVersion is already installed."
}
else {
Write-Host "Install Module $ModuleName with version $RequiredVersion..."
Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force
}
Loading

0 comments on commit 775cf9b

Please sign in to comment.