mirror of
https://github.com/actions/runner.git
synced 2025-12-12 15:13:30 +00:00
removed throw and else on container action handler (#1873)
* removed throw and else on container action handler * repaired merge resolution error
This commit is contained in:
@@ -1042,7 +1042,7 @@ namespace GitHub.Runner.Worker
|
|||||||
if (actionDefinitionData.Execution.ExecutionType == ActionExecutionType.Container)
|
if (actionDefinitionData.Execution.ExecutionType == ActionExecutionType.Container)
|
||||||
{
|
{
|
||||||
var containerAction = actionDefinitionData.Execution as ContainerActionExecutionData;
|
var containerAction = actionDefinitionData.Execution as ContainerActionExecutionData;
|
||||||
if (containerAction.Image.EndsWith("Dockerfile") || containerAction.Image.EndsWith("dockerfile"))
|
if (DockerUtil.IsDockerfile(containerAction.Image))
|
||||||
{
|
{
|
||||||
var dockerFileFullPath = Path.Combine(actionEntryDirectory, containerAction.Image);
|
var dockerFileFullPath = Path.Combine(actionEntryDirectory, containerAction.Image);
|
||||||
executionContext.Debug($"Dockerfile for action: '{dockerFileFullPath}'.");
|
executionContext.Debug($"Dockerfile for action: '{dockerFileFullPath}'.");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace GitHub.Runner.Worker.Container
|
namespace GitHub.Runner.Worker.Container
|
||||||
@@ -65,6 +66,16 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsDockerfile(string image)
|
||||||
|
{
|
||||||
|
if (image.StartsWith("docker://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var imageWithoutPath = image.Split('/').Last();
|
||||||
|
return imageWithoutPath.StartsWith("Dockerfile.", StringComparison.OrdinalIgnoreCase) || imageWithoutPath.EndsWith("Dockerfile", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
public static string CreateEscapedOption(string flag, string key)
|
public static string CreateEscapedOption(string flag, string key)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(key))
|
if (String.IsNullOrEmpty(key))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -56,7 +56,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
{
|
{
|
||||||
Data.Image = Data.Image.Substring("docker://".Length);
|
Data.Image = Data.Image.Substring("docker://".Length);
|
||||||
}
|
}
|
||||||
else if (Data.Image.EndsWith("Dockerfile") || Data.Image.EndsWith("dockerfile"))
|
else if (DockerUtil.IsDockerfile(Data.Image))
|
||||||
{
|
{
|
||||||
// ensure docker file exist
|
// ensure docker file exist
|
||||||
dockerFile = Path.Combine(ActionDirectory, Data.Image);
|
dockerFile = Path.Combine(ActionDirectory, Data.Image);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using GitHub.Runner.Worker.Container;
|
using GitHub.Runner.Worker.Container;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@@ -145,6 +145,49 @@ namespace GitHub.Runner.Common.Tests.Worker.Container
|
|||||||
Assert.Equal(expected, actual);
|
Assert.Equal(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("Level", "L0")]
|
||||||
|
[Trait("Category", "Worker")]
|
||||||
|
[InlineData("dockerhub/repo", false)]
|
||||||
|
[InlineData("debian:latest", false)]
|
||||||
|
[InlineData("something/dockerfileimage", false)]
|
||||||
|
[InlineData("ghcr.io/docker/dockerfile", true)] // should be false but might break the current workflows
|
||||||
|
[InlineData("Dockerfile", true)]
|
||||||
|
[InlineData("Dockerfile.", true)]
|
||||||
|
[InlineData(".Dockerfile", true)]
|
||||||
|
[InlineData(".Dockerfile.", false)]
|
||||||
|
[InlineData("dockerfile", true)]
|
||||||
|
[InlineData("dockerfile.", true)]
|
||||||
|
[InlineData(".dockerfile", true)]
|
||||||
|
[InlineData(".dockerfile.", false)]
|
||||||
|
[InlineData("Dockerfile.test", true)]
|
||||||
|
[InlineData("test.Dockerfile", true)]
|
||||||
|
[InlineData("docker/dockerfile:latest", false)]
|
||||||
|
[InlineData("/some/path/dockerfile:latest", false)]
|
||||||
|
[InlineData("dockerfile:latest", false)]
|
||||||
|
[InlineData("Dockerfile:latest", false)]
|
||||||
|
[InlineData("dockerfile-latest", false)]
|
||||||
|
[InlineData("Dockerfile-latest", false)]
|
||||||
|
[InlineData("dockerfile.latest", true)]
|
||||||
|
[InlineData("Dockerfile.latest", true)]
|
||||||
|
[InlineData("../dockerfile/dockerfileone", false)]
|
||||||
|
[InlineData("../Dockerfile/dockerfileone", false)]
|
||||||
|
[InlineData("../dockerfile.test", true)]
|
||||||
|
[InlineData("../Dockerfile.test", true)]
|
||||||
|
[InlineData("./dockerfile/image", false)]
|
||||||
|
[InlineData("./Dockerfile/image", false)]
|
||||||
|
[InlineData("example/Dockerfile.test", true)]
|
||||||
|
[InlineData("./example/Dockerfile.test", true)]
|
||||||
|
[InlineData("example/test.dockerfile", true)]
|
||||||
|
[InlineData("./example/test.dockerfile", true)]
|
||||||
|
[InlineData("docker://Dockerfile", false)]
|
||||||
|
[InlineData("docker://ubuntu:latest", false)]
|
||||||
|
public void IsDockerfile(string input, bool expected)
|
||||||
|
{
|
||||||
|
var actual = DockerUtil.IsDockerfile(input);
|
||||||
|
Assert.Equal(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", "Worker")]
|
[Trait("Category", "Worker")]
|
||||||
|
|||||||
Reference in New Issue
Block a user