Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export async function installPrek(version: Version): Promise<string> {
`Selected release asset ${asset.archiveName} for runner ${process.platform}/${process.arch} (tool-cache arch ${toolArch})`
)
const manifestAsset = getAssetForVersion(version, asset.archiveName)

core.info(`Downloading prek from ${manifestAsset.downloadUrl}`)
const archivePath = await tc.downloadTool(manifestAsset.downloadUrl)

core.info(`Downloaded archive to ${archivePath}`)

await verifyDownloadChecksum(archivePath, manifestAsset, version)

const extractedPath =
asset.archiveType === 'zip' ? await tc.extractZip(archivePath) : await tc.extractTar(archivePath)
const extractedPath = await extractArchive(archivePath, asset)
core.info(`Extracted ${asset.archiveType} archive to ${extractedPath}`)

const binaryPath = await getBinaryPath(extractedPath, asset)
Expand All @@ -50,6 +50,29 @@ export async function installPrek(version: Version): Promise<string> {
}
}

async function extractArchive(archivePath: string, asset: ReleaseAsset): Promise<string> {
if (asset.archiveType === 'tar.gz') {
return tc.extractTar(archivePath)
}

if (process.platform === 'win32') {
return extractWindowsZipArchive(archivePath)
}

return tc.extractZip(archivePath)
}

async function extractWindowsZipArchive(archivePath: string): Promise<string> {
try {
// bsdtar can extract zip archives much faster than the zip fallback on Windows runners.
return await tc.extractTar(archivePath, undefined, 'x')
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
core.info(`Extracting zip with tar failed, falling back to zip extraction: ${message}`)
return tc.extractZip(archivePath)
Comment thread
j178 marked this conversation as resolved.
Comment thread
j178 marked this conversation as resolved.
}
Comment thread
j178 marked this conversation as resolved.
}

// Translate the current runner platform/arch into the expected release archive and executable names.
export function getReleaseAssetFor(platform: NodeJS.Platform, arch: NodeJS.Architecture): ReleaseAsset {
const binaryName = platform === 'win32' ? 'prek.exe' : 'prek'
Expand Down
Loading