From c29099ed93091e38d8ff387f0950d8e3c13a4533 Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Tue, 30 Jun 2026 13:40:06 +1000 Subject: [PATCH 1/3] Make commit to git step skip committing when transformation script fails --- .../Calamari.Tests/CommitToGitCommandTest.cs | 18 ++++++++++++++++++ source/Calamari/Commands/CommitToGitCommand.cs | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/source/Calamari.Tests/CommitToGitCommandTest.cs b/source/Calamari.Tests/CommitToGitCommandTest.cs index eda7d0092..16026feb6 100644 --- a/source/Calamari.Tests/CommitToGitCommandTest.cs +++ b/source/Calamari.Tests/CommitToGitCommandTest.cs @@ -570,6 +570,24 @@ public void CommitToGit_FailsWithCommandException_WhenCustomPropertiesFileDoesNo .Should().NotBe(0, "the command must reject runs whose --customPropertiesFile path does not exist"); } + [Test] + public void CommitToGit_SkipsCommitting_WhenTransformationScript_ReturnsNonZeroExitCode() + { + const string packageReferenceName = "my-configs"; + const string destinationPath = "output-dir"; + + var zipPath = CreateZipWithEntry(packageReferenceName, "configs/settings.json", "{\"setting\": \"value\"}"); + AddInputPackageVariables(packageReferenceName, zipPath, destinationPath); + variables.AddRange([ + new CalamariExecutionVariable(ScriptVariables.ScriptBody, "exit 1", false), + new CalamariExecutionVariable(ScriptVariables.Syntax, ScriptSyntax.Bash.ToString(), false), + ]); + + RunCommitToGit().Should().NotBe(0); + GetCommittedFileContent($"{destinationPath}/configs/settings.json") + .Should().BeNull("the package files should not have been committed into the repository under the destination path, when the transformation script returns non-zero exit code"); + } + // --- Helpers --- int RunCommitToGit(params string[] extraArgs) diff --git a/source/Calamari/Commands/CommitToGitCommand.cs b/source/Calamari/Commands/CommitToGitCommand.cs index 30f7722fb..f590faf84 100644 --- a/source/Calamari/Commands/CommitToGitCommand.cs +++ b/source/Calamari/Commands/CommitToGitCommand.cs @@ -275,6 +275,7 @@ IEnumerable BuildTransformRepositoryConventions() log.SetOutputVariable(SpecialVariables.Action.Script.ExitCode, "0", d.Variables); return; } + new ExecuteScriptConvention(scriptEngine, commandLineRunner, log).Install(d); }) ]; @@ -286,6 +287,13 @@ IEnumerable BuildCommitToRemoteConventions(CommitToGitRepositorySet { new DelegateInstallConvention(d => { + var exitCode = d.Variables.GetInt32(SpecialVariables.Action.Script.ExitCode) ?? 0; + if (exitCode != 0) + { + log.Error($"Transformation script exited with code {exitCode}. Skipping commit to Git."); + return; + } + var commitParams = repositoryConfig!.CommitParameters; var updater = new RepositoryUpdater(commitParams, log, new UserDefinedCommitMessageGenerator(commitParams.Description)); From 8a4604390422fc599708d050cfade6df74e9da93 Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Tue, 30 Jun 2026 13:40:44 +1000 Subject: [PATCH 2/3] Tidy up white space change --- source/Calamari/Commands/CommitToGitCommand.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/source/Calamari/Commands/CommitToGitCommand.cs b/source/Calamari/Commands/CommitToGitCommand.cs index f590faf84..8454bf45c 100644 --- a/source/Calamari/Commands/CommitToGitCommand.cs +++ b/source/Calamari/Commands/CommitToGitCommand.cs @@ -275,7 +275,6 @@ IEnumerable BuildTransformRepositoryConventions() log.SetOutputVariable(SpecialVariables.Action.Script.ExitCode, "0", d.Variables); return; } - new ExecuteScriptConvention(scriptEngine, commandLineRunner, log).Install(d); }) ]; From 8ccd278b3d8ee21ef7702b5a113be5cfad138df4 Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Tue, 30 Jun 2026 14:09:29 +1000 Subject: [PATCH 3/3] Update to throw command exception --- source/Calamari/Commands/CommitToGitCommand.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/Calamari/Commands/CommitToGitCommand.cs b/source/Calamari/Commands/CommitToGitCommand.cs index 8454bf45c..641ae10bb 100644 --- a/source/Calamari/Commands/CommitToGitCommand.cs +++ b/source/Calamari/Commands/CommitToGitCommand.cs @@ -289,8 +289,7 @@ IEnumerable BuildCommitToRemoteConventions(CommitToGitRepositorySet var exitCode = d.Variables.GetInt32(SpecialVariables.Action.Script.ExitCode) ?? 0; if (exitCode != 0) { - log.Error($"Transformation script exited with code {exitCode}. Skipping commit to Git."); - return; + throw new CommandException($"Transformation script exited with code {exitCode}. Changes will not be committed."); } var commitParams = repositoryConfig!.CommitParameters;