Skip to content

Commit

Permalink
(#152) Only run signing steps on Windows
Browse files Browse the repository at this point in the history
All of the signing steps in Chocolatey.Cake.Recipe require one of two
things. Either:

- usage of Windows PowerShell
- usage of signtool.exe (with a hard coded path in Windows)

Neither of these things are found on a Linux/Mac build runner.  As such
we need to add criteria to only run tasks on Windows.

This criteria wasn't "needed" previously, since there was another
criteria present to only run when on TeamCity, or the signing
certificate was in place. When the new verify task, which doesn't have
this same criteria, was added, it started failing the build, as the
other tasks weren't being explicit about this requirement.

This commit addresses this underlying problem, by adding an explicit
criteria to each step related to signing to ensure running on Windows
so that it isn't forgotten about in the future.
  • Loading branch information
gep13 committed May 16, 2024
1 parent 8a699ac commit 6a0e863
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Chocolatey.Cake.Recipe/Content/sign.cake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

BuildParameters.Tasks.VerifyPowerShellScriptsTask = Task("Verify-PowerShellScripts")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows")
.WithCriteria(() => BuildParameters.ShouldVerifyPowerShellScripts, "Skipping since verifying PowerShell scripts has been disabled")
.Does(() =>
{
Expand Down Expand Up @@ -45,6 +46,7 @@ BuildParameters.Tasks.VerifyPowerShellScriptsTask = Task("Verify-PowerShellScrip
});

BuildParameters.Tasks.SignPowerShellScriptsTask = Task("Sign-PowerShellScripts")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows")
.WithCriteria(() => (!string.IsNullOrWhiteSpace(BuildParameters.CertificateFilePath) && FileExists(BuildParameters.CertificateFilePath)) || BuildSystem.IsRunningOnTeamCity, "Skipping because unable to find certificate, and not running on TeamCity")
.WithCriteria(() => BuildParameters.ShouldAuthenticodeSignPowerShellScripts, "Skipping since authenticode signing of PowerShell scripts has been disabled")
.Does(() =>
Expand Down Expand Up @@ -105,6 +107,7 @@ BuildParameters.Tasks.SignPowerShellScriptsTask = Task("Sign-PowerShellScripts")
});

BuildParameters.Tasks.SignAssembliesTask = Task("Sign-Assemblies")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows")
.WithCriteria(() => (!string.IsNullOrWhiteSpace(BuildParameters.CertificateFilePath) && FileExists(BuildParameters.CertificateFilePath)) || BuildSystem.IsRunningOnTeamCity, "Skipping because unable to find certificate, and not running on TeamCity")
.WithCriteria(() => BuildParameters.ShouldAuthenticodeSignOutputAssemblies, "Skipping since authenticode signing of output assemblies has been disabled")
.Does(() =>
Expand Down Expand Up @@ -153,6 +156,7 @@ BuildParameters.Tasks.SignAssembliesTask = Task("Sign-Assemblies")
});

BuildParameters.Tasks.SignMsisTask = Task("Sign-Msis")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows")
.WithCriteria(() => (!string.IsNullOrWhiteSpace(BuildParameters.CertificateFilePath) && FileExists(BuildParameters.CertificateFilePath)) || BuildSystem.IsRunningOnTeamCity, "Skipping because unable to find certificate, and not running on TeamCity")
.WithCriteria(() => BuildParameters.ShouldAuthenticodeSignMsis, "Skipping since authenticode signing of msi's has been disabled")
.Does(() =>
Expand Down

0 comments on commit 6a0e863

Please sign in to comment.