Skip to content

Commit

Permalink
Better support multi-line run
Browse files Browse the repository at this point in the history
  • Loading branch information
damianh committed Nov 5, 2024
1 parent 6313fd4 commit b372f30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
18 changes: 15 additions & 3 deletions libs/github/src/Actions.Workflow/Step.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using YamlDotNet.Core.Events;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.RepresentationModel;

namespace Logicality.GitHub.Actions.Workflow;
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 29 additions & 1 deletion libs/github/tests/Actions.Workflow.Tests/JobStepTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit b372f30

Please sign in to comment.