1
0
Fork 0

Add better comments

pull/1260/head
Sampark Sharma 2022-12-12 10:58:58 +00:00 committed by GitHub
parent d7ae8cd1ef
commit cad074ceef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -96,8 +96,7 @@ export async function restoreCache(
compressionMethod compressionMethod
}) })
if (!cacheEntry?.archiveLocation) { if (!cacheEntry?.archiveLocation) {
// This is to support the old cache entry created // This is to support the old cache entry created by gzip on windows.
// by the old version of the cache action on windows.
if ( if (
process.platform === 'win32' && process.platform === 'win32' &&
compressionMethod !== CompressionMethod.Gzip compressionMethod !== CompressionMethod.Gzip
@ -111,7 +110,7 @@ export async function restoreCache(
} }
core.debug( 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 { } else {
// Cache not found // Cache not found

View File

@ -104,6 +104,7 @@ export async function getCacheEntry(
httpClient.getJson<ArtifactCacheEntry>(getCacheApiUrl(resource)) httpClient.getJson<ArtifactCacheEntry>(getCacheApiUrl(resource))
) )
if (response.statusCode === 204) { if (response.statusCode === 204) {
// Cache not found
return null return null
} }
if (!isSuccessStatusCode(response.statusCode)) { if (!isSuccessStatusCode(response.statusCode)) {
@ -113,6 +114,7 @@ export async function getCacheEntry(
const cacheResult = response.result const cacheResult = response.result
const cacheDownloadUrl = cacheResult?.archiveLocation const cacheDownloadUrl = cacheResult?.archiveLocation
if (!cacheDownloadUrl) { if (!cacheDownloadUrl) {
// Cache achiveLocation not found
throw new Error('Cache not found.') throw new Error('Cache not found.')
} }
core.setSecret(cacheDownloadUrl) core.setSecret(cacheDownloadUrl)

View File

@ -14,7 +14,7 @@ import {
const IS_WINDOWS = process.platform === 'win32' 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<ArchiveTool> { async function getTarPath(): Promise<ArchiveTool> {
switch (process.platform) { switch (process.platform) {
case 'win32': { case 'win32': {
@ -43,6 +43,7 @@ async function getTarPath(): Promise<ArchiveTool> {
default: default:
break break
} }
// Default assumption is GNU tar is present in path
return <ArchiveTool>{ return <ArchiveTool>{
path: await io.which('tar', true), path: await io.which('tar', true),
type: ArchiveToolType.GNU type: ArchiveToolType.GNU
@ -60,6 +61,7 @@ async function getTarArgs(
const cacheFileName = utils.getCacheFileName(compressionMethod) const cacheFileName = utils.getCacheFileName(compressionMethod)
const tarFile = 'cache.tar' const tarFile = 'cache.tar'
const workingDirectory = getWorkingDirectory() const workingDirectory = getWorkingDirectory()
// Speficic args for BSD tar on windows for workaround
const BSD_TAR_ZSTD = const BSD_TAR_ZSTD =
tarPath.type === ArchiveToolType.BSD && tarPath.type === ArchiveToolType.BSD &&
compressionMethod !== CompressionMethod.Gzip && compressionMethod !== CompressionMethod.Gzip &&
@ -122,6 +124,7 @@ async function getTarArgs(
return args return args
} }
// Returns commands to run tar and compression program
async function getCommands( async function getCommands(
compressionMethod: CompressionMethod, compressionMethod: CompressionMethod,
type: string, 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. // -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' // 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. // --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<void> { async function execCommands(commands: string[], cwd?: string): Promise<void> {
for (const command of commands) { for (const command of commands) {
try { try {
@ -252,6 +257,7 @@ async function execCommands(commands: string[], cwd?: string): Promise<void> {
} }
} }
// List the contents of a tar
export async function listTar( export async function listTar(
archivePath: string, archivePath: string,
compressionMethod: CompressionMethod compressionMethod: CompressionMethod
@ -260,6 +266,7 @@ export async function listTar(
await execCommands(commands) await execCommands(commands)
} }
// Extract a tar
export async function extractTar( export async function extractTar(
archivePath: string, archivePath: string,
compressionMethod: CompressionMethod compressionMethod: CompressionMethod
@ -271,6 +278,7 @@ export async function extractTar(
await execCommands(commands) await execCommands(commands)
} }
// Create a tar
export async function createTar( export async function createTar(
archiveFolder: string, archiveFolder: string,
sourceDirectories: string[], sourceDirectories: string[],