Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/Calamari.Tests/CommitToGitCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions source/Calamari/Commands/CommitToGitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ IEnumerable<IConvention> BuildCommitToRemoteConventions(CommitToGitRepositorySet
{
new DelegateInstallConvention(d =>
{
var exitCode = d.Variables.GetInt32(SpecialVariables.Action.Script.ExitCode) ?? 0;
if (exitCode != 0)
{
throw new CommandException($"Transformation script exited with code {exitCode}. Changes will not be committed.");
}

var commitParams = repositoryConfig!.CommitParameters;
var updater = new RepositoryUpdater(commitParams, log, new UserDefinedCommitMessageGenerator(commitParams.Description));

Expand Down