mirror of
https://github.com/actions/runner.git
synced 2026-07-05 12:11:57 +08:00
Compare commits
4 Commits
main
...
sha256/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52a508ee00 | ||
|
|
37c15cef16 | ||
|
|
75697ced2e | ||
|
|
8185d1e939 |
@@ -12,8 +12,6 @@ namespace GitHub.Runner.Plugins.Repository.v1_0
|
||||
{
|
||||
public class CheckoutTask : IRunnerActionPlugin
|
||||
{
|
||||
private readonly Regex _validSha1 = new(@"\b[0-9a-f]{40}\b", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled, TimeSpan.FromSeconds(2));
|
||||
|
||||
public async Task RunAsync(RunnerActionPluginExecutionContext executionContext, CancellationToken token)
|
||||
{
|
||||
string runnerWorkspace = executionContext.GetRunnerContext("workspace");
|
||||
@@ -99,7 +97,7 @@ namespace GitHub.Runner.Plugins.Repository.v1_0
|
||||
{
|
||||
sourceBranch = refInput;
|
||||
sourceVersion = executionContext.GetInput(Pipelines.PipelineConstants.CheckoutTaskInputs.Version); // version get removed when checkout move to repo in the graph
|
||||
if (string.IsNullOrEmpty(sourceVersion) && RegexUtility.IsMatch(sourceBranch, WellKnownRegularExpressions.SHA1))
|
||||
if (string.IsNullOrEmpty(sourceVersion) && RegexUtility.IsMatch(sourceBranch, WellKnownRegularExpressions.CommitHash))
|
||||
{
|
||||
sourceVersion = sourceBranch;
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace GitHub.Runner.Plugins.Repository.v1_1
|
||||
{
|
||||
sourceBranch = refInput;
|
||||
sourceVersion = executionContext.GetInput(Pipelines.PipelineConstants.CheckoutTaskInputs.Version); // version get removed when checkout move to repo in the graph
|
||||
if (string.IsNullOrEmpty(sourceVersion) && RegexUtility.IsMatch(sourceBranch, WellKnownRegularExpressions.SHA1))
|
||||
if (string.IsNullOrEmpty(sourceVersion) && RegexUtility.IsMatch(sourceBranch, WellKnownRegularExpressions.CommitHash))
|
||||
{
|
||||
sourceVersion = sourceBranch;
|
||||
// If Ref is a SHA and the repo is self, we need to use github.ref as source branch since it might be refs/pull/*
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace GitHub.DistributedTask.Pipelines.Expressions
|
||||
public const String Email = nameof(Email);
|
||||
public const String IPv4Address = nameof(IPv4Address);
|
||||
public const String SHA1 = nameof(SHA1);
|
||||
public const String CommitHash = nameof(CommitHash);
|
||||
public const String Url = nameof(Url);
|
||||
|
||||
/// <summary>
|
||||
@@ -24,7 +25,8 @@ namespace GitHub.DistributedTask.Pipelines.Expressions
|
||||
case IPv4Address:
|
||||
return s_validIPv4Address;
|
||||
case SHA1:
|
||||
return s_validSha1;
|
||||
case CommitHash:
|
||||
return s_validCommitHash;
|
||||
case Url:
|
||||
return s_validUrl;
|
||||
default:
|
||||
@@ -46,9 +48,9 @@ namespace GitHub.DistributedTask.Pipelines.Expressions
|
||||
)
|
||||
);
|
||||
|
||||
// 40 hex characters
|
||||
private static readonly Lazy<Regex> s_validSha1 = new Lazy<Regex>(() => new Regex(
|
||||
@"\b[0-9a-f]{40}\b",
|
||||
// 40 or 64 hex characters (SHA-1 or SHA-256 commit hash)
|
||||
private static readonly Lazy<Regex> s_validCommitHash = new Lazy<Regex>(() => new Regex(
|
||||
@"\b(?:[0-9a-f]{40}|[0-9a-f]{64})\b",
|
||||
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled, RegexUtility.GetRegexTimeOut()
|
||||
)
|
||||
);
|
||||
|
||||
@@ -24,7 +24,10 @@ namespace GitHub.Runner.Common.Tests
|
||||
"osx-arm64"
|
||||
};
|
||||
|
||||
Assert.Equal(40, BuildConstants.Source.CommitHash.Length);
|
||||
Assert.True(
|
||||
BuildConstants.Source.CommitHash.Length == 40 || BuildConstants.Source.CommitHash.Length == 64,
|
||||
"CommitHash should be a 40-char SHA-1 or 64-char SHA-256 hex string");
|
||||
Assert.Matches("^[0-9a-f]+$", BuildConstants.Source.CommitHash);
|
||||
Assert.True(validPackageNames.Contains(BuildConstants.RunnerPackage.PackageName), $"PackageName should be one of the following '{string.Join(", ", validPackageNames)}', current PackageName is '{BuildConstants.RunnerPackage.PackageName}'");
|
||||
}
|
||||
}
|
||||
|
||||
100
src/Test/L0/Sdk/WellKnownRegularExpressionsL0.cs
Normal file
100
src/Test/L0/Sdk/WellKnownRegularExpressionsL0.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using GitHub.DistributedTask.Pipelines.Expressions;
|
||||
using Xunit;
|
||||
|
||||
namespace GitHub.Runner.Common.Tests.Sdk
|
||||
{
|
||||
public sealed class WellKnownRegularExpressionsL0
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void SHA1_Key_Returns_CommitHash_Regex()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.SHA1);
|
||||
|
||||
Assert.NotNull(regex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void CommitHash_Key_Returns_CommitHash_Regex()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
|
||||
Assert.NotNull(regex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void SHA1_And_CommitHash_Return_Same_Regex()
|
||||
{
|
||||
var sha1Regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.SHA1);
|
||||
var commitHashRegex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
|
||||
Assert.Same(sha1Regex, commitHashRegex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void Matches_40_Char_Hex()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
|
||||
Assert.Matches(regex.Value, new string((char)97, 40));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void Matches_64_Char_Hex()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
|
||||
Assert.Matches(regex.Value, new string((char)97, 64));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void Does_Not_Match_63_Char_Hex()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
|
||||
Assert.DoesNotMatch(regex.Value, new string((char)97, 63));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void Does_Not_Match_65_Char_Hex()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
|
||||
Assert.DoesNotMatch(regex.Value, new string((char)97, 65));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void Matches_Mixed_Case_64_Char()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex(WellKnownRegularExpressions.CommitHash);
|
||||
var value = new string((char)65, 32) + new string((char)98, 32);
|
||||
|
||||
Assert.Matches(regex.Value, value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Sdk")]
|
||||
public void Unknown_Key_Returns_Null()
|
||||
{
|
||||
var regex = WellKnownRegularExpressions.GetRegex("UnknownType");
|
||||
|
||||
Assert.Null(regex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user