diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index d15975c3..2ebf44ca 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -96,8 +96,7 @@ export async function restoreCache( compressionMethod }) if (!cacheEntry?.archiveLocation) { - // This is to support the old cache entry created - // by the old version of the cache action on windows. + // This is to support the old cache entry created by gzip on windows. if ( process.platform === 'win32' && compressionMethod !== CompressionMethod.Gzip @@ -111,7 +110,7 @@ export async function restoreCache( } core.debug( - "Couldn't find cache entry with zstd compression, falling back to gzip compression" + "Couldn't find cache entry with zstd compression, falling back to gzip compression." ) } else { // Cache not found diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts index c66d1a73..d196b9d5 100644 --- a/packages/cache/src/internal/cacheHttpClient.ts +++ b/packages/cache/src/internal/cacheHttpClient.ts @@ -104,6 +104,7 @@ export async function getCacheEntry( httpClient.getJson(getCacheApiUrl(resource)) ) if (response.statusCode === 204) { + // Cache not found return null } if (!isSuccessStatusCode(response.statusCode)) { @@ -113,6 +114,7 @@ export async function getCacheEntry( const cacheResult = response.result const cacheDownloadUrl = cacheResult?.archiveLocation if (!cacheDownloadUrl) { + // Cache achiveLocation not found throw new Error('Cache not found.') } core.setSecret(cacheDownloadUrl) diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index 69731381..0af6a87a 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -14,7 +14,7 @@ import { const IS_WINDOWS = process.platform === 'win32' -// Function also mutates the args array. For non-mutation call with passing an empty array. +// Returns tar path and type: BSD or GNU async function getTarPath(): Promise { switch (process.platform) { case 'win32': { @@ -43,6 +43,7 @@ async function getTarPath(): Promise { default: break } + // Default assumption is GNU tar is present in path return { path: await io.which('tar', true), type: ArchiveToolType.GNU @@ -60,6 +61,7 @@ async function getTarArgs( const cacheFileName = utils.getCacheFileName(compressionMethod) const tarFile = 'cache.tar' const workingDirectory = getWorkingDirectory() + // Speficic args for BSD tar on windows for workaround const BSD_TAR_ZSTD = tarPath.type === ArchiveToolType.BSD && compressionMethod !== CompressionMethod.Gzip && @@ -122,6 +124,7 @@ async function getTarArgs( return args } +// Returns commands to run tar and compression program async function getCommands( compressionMethod: CompressionMethod, type: string, @@ -201,6 +204,7 @@ async function getDecompressionProgram( } } +// Used for creating the archive // -T#: Compress using # working thread. If # is 0, attempt to detect and use the number of physical CPU cores. // zstdmt is equivalent to 'zstd -T0' // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit. @@ -240,6 +244,7 @@ async function getCompressionProgram( } } +// Executes all commands as separate processes async function execCommands(commands: string[], cwd?: string): Promise { for (const command of commands) { try { @@ -252,6 +257,7 @@ async function execCommands(commands: string[], cwd?: string): Promise { } } +// List the contents of a tar export async function listTar( archivePath: string, compressionMethod: CompressionMethod @@ -260,6 +266,7 @@ export async function listTar( await execCommands(commands) } +// Extract a tar export async function extractTar( archivePath: string, compressionMethod: CompressionMethod @@ -271,6 +278,7 @@ export async function extractTar( await execCommands(commands) } +// Create a tar export async function createTar( archiveFolder: string, sourceDirectories: string[],