Skip to content

Commit 6080382

Browse files
committed
Add feature flag
1 parent 64d6107 commit 6080382

2 files changed

Lines changed: 34 additions & 27 deletions

File tree

src/Runner.Common/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public static class Features
174174
public static readonly string CompareWorkflowParser = "actions_runner_compare_workflow_parser";
175175
public static readonly string SetOrchestrationIdEnvForActions = "actions_set_orchestration_id_env_for_actions";
176176
public static readonly string SendJobLevelAnnotations = "actions_send_job_level_annotations";
177+
public static readonly string SymlinkCachedActions = "actions_symlink_cached_actions";
177178
}
178179

179180
// Node version migration related constants

src/Runner.Worker/ActionManager.cs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -811,39 +811,45 @@ private async Task DownloadRepositoryActionAsync(IExecutionContext executionCont
811811
if (!string.IsNullOrEmpty(actionArchiveCacheDir) &&
812812
Directory.Exists(actionArchiveCacheDir))
813813
{
814-
var cacheDirectory = Path.Combine(actionArchiveCacheDir, downloadInfo.ResolvedNameWithOwner.Replace(Path.DirectorySeparatorChar, '_').Replace(Path.AltDirectorySeparatorChar, '_'), downloadInfo.ResolvedSha);
815-
if (Directory.Exists(cacheDirectory))
814+
var symlinkCachedActions = executionContext.Global.Variables.GetBoolean(Constants.Runner.Features.SymlinkCachedActions) ?? false;
815+
if (symlinkCachedActions)
816816
{
817-
try
817+
Trace.Info($"Checking if can symlink '{downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha}'");
818+
819+
var cacheDirectory = Path.Combine(actionArchiveCacheDir, downloadInfo.ResolvedNameWithOwner.Replace(Path.DirectorySeparatorChar, '_').Replace(Path.AltDirectorySeparatorChar, '_'), downloadInfo.ResolvedSha);
820+
if (Directory.Exists(cacheDirectory))
818821
{
819-
Trace.Info($"Found unpacked action directory '{cacheDirectory}' in cache directory '{actionArchiveCacheDir}'");
820-
821-
// repository archive from github always contains a nested folder
822-
var nestedDirectories = new DirectoryInfo(cacheDirectory).GetDirectories();
823-
if (nestedDirectories.Length != 1)
822+
try
824823
{
825-
throw new InvalidOperationException($"'{cacheDirectory}' contains '{nestedDirectories.Length}' directories");
824+
Trace.Info($"Found unpacked action directory '{cacheDirectory}' in cache directory '{actionArchiveCacheDir}'");
825+
826+
// repository archive from github always contains a nested folder
827+
var nestedDirectories = new DirectoryInfo(cacheDirectory).GetDirectories();
828+
if (nestedDirectories.Length != 1)
829+
{
830+
throw new InvalidOperationException($"'{cacheDirectory}' contains '{nestedDirectories.Length}' directories");
831+
}
832+
else
833+
{
834+
executionContext.Debug($"Symlink '{nestedDirectories[0].Name}' to '{destDirectory}'");
835+
Directory.CreateSymbolicLink(destDirectory, nestedDirectories[0].FullName);
836+
}
837+
838+
executionContext.Debug($"Created symlink from cached directory '{cacheDirectory}' to '{destDirectory}'");
839+
executionContext.Global.JobTelemetry.Add(new JobTelemetry()
840+
{
841+
Type = JobTelemetryType.General,
842+
Message = $"Action directory cache usage: {downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha} use symlink from cache"
843+
});
844+
845+
Trace.Info("Finished getting action repository.");
846+
return;
826847
}
827-
else
848+
catch (Exception ex)
828849
{
829-
executionContext.Debug($"Symlink '{nestedDirectories[0].Name}' to '{destDirectory}'");
830-
Directory.CreateSymbolicLink(destDirectory, nestedDirectories[0].FullName);
850+
Trace.Error($"Failed to create symlink from cached directory '{cacheDirectory}' to '{destDirectory}'. Error: {ex}");
851+
// Fall through to normal download logic
831852
}
832-
833-
executionContext.Debug($"Created symlink from cached directory '{cacheDirectory}' to '{destDirectory}'");
834-
executionContext.Global.JobTelemetry.Add(new JobTelemetry()
835-
{
836-
Type = JobTelemetryType.General,
837-
Message = $"Action directory cache usage: {downloadInfo.ResolvedNameWithOwner}@{downloadInfo.ResolvedSha} use symlink from cache"
838-
});
839-
840-
Trace.Info("Finished getting action repository.");
841-
return;
842-
}
843-
catch (Exception ex)
844-
{
845-
Trace.Error($"Failed to create symlink from cached directory '{cacheDirectory}' to '{destDirectory}'. Error: {ex}");
846-
// Fall through to normal download logic
847853
}
848854
}
849855

0 commit comments

Comments
 (0)