diff --git a/libs/github/src/Actions.Workflow/Step.cs b/libs/github/src/Actions.Workflow/Step.cs index 2b4759b2..1c5e56e2 100644 --- a/libs/github/src/Actions.Workflow/Step.cs +++ b/libs/github/src/Actions.Workflow/Step.cs @@ -1,4 +1,5 @@ -using YamlDotNet.Core.Events; +using YamlDotNet.Core; +using YamlDotNet.Core.Events; using YamlDotNet.RepresentationModel; namespace Logicality.GitHub.Actions.Workflow; @@ -173,8 +174,19 @@ internal void Build(YamlMappingNode node, SequenceStyle sequenceStyle) if (!string.IsNullOrWhiteSpace(_run)) { - node.Add("run", _run); - + if (_run.Contains(Environment.NewLine)) + { + var runNode = new YamlScalarNode(_run) + { + Style = ScalarStyle.Literal + }; + node.Add("run", runNode); + } + else + { + node.Add("run", _run); + } + if (!string.IsNullOrWhiteSpace(_workingDirectory)) { node.Add("working-directory", _workingDirectory); diff --git a/libs/github/tests/Actions.Workflow.Tests/JobStepTests.cs b/libs/github/tests/Actions.Workflow.Tests/JobStepTests.cs index d4b2b016..1a39023c 100644 --- a/libs/github/tests/Actions.Workflow.Tests/JobStepTests.cs +++ b/libs/github/tests/Actions.Workflow.Tests/JobStepTests.cs @@ -73,7 +73,35 @@ public void Step_Run() actual.ShouldBe(expected.ReplaceLineEndings());; } - + + [Fact] + public void Step_Run_Scalar() + { + var actual = new Workflow("workflow") + .Job("build") + .Step("step") + .Run(""" + sudo apt-get update + sudo apt-get install -y ca-certificates + """) + .Workflow + .GetYaml(); + + var expected = Workflow.Header + @" + +name: workflow +jobs: + build: + steps: + - id: step + run: |- + sudo apt-get update + sudo apt-get install -y ca-certificates +"; + + actual.ShouldBe(expected.ReplaceLineEndings()); ; + } + [Fact] public void Step_WorkingDirectory_With_Run() {