@@ -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