This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba1f5f6
commit 3135027
Showing
5 changed files
with
104 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint-disable sonarjs/no-duplicate-string */ | ||
|
||
import * as exec from '@actions/exec'; | ||
import * as semver from 'semver'; | ||
|
||
enum CompressionMethod { | ||
GZIP, | ||
ZSTD_WITHOUT_LONG, | ||
ZSTD, | ||
} | ||
|
||
async function getTarCompressionMethod(): Promise<CompressionMethod> { | ||
if (process.platform === 'win32') { | ||
return CompressionMethod.GZIP; | ||
} | ||
|
||
const [zstdOutput, zstdVersion] = await exec | ||
.getExecOutput('zstd', ['--version'], { | ||
ignoreReturnCode: true, | ||
silent: true, | ||
}) | ||
.then((out) => out.stdout.trim()) | ||
.then((out) => [out, semver.clean(out)]); | ||
|
||
if (!zstdOutput?.toLowerCase().includes('zstd command line interface')) { | ||
return CompressionMethod.GZIP; | ||
} else if (!zstdVersion || semver.lt(zstdVersion, 'v1.3.2')) { | ||
return CompressionMethod.ZSTD_WITHOUT_LONG; | ||
} else { | ||
return CompressionMethod.ZSTD; | ||
} | ||
} | ||
|
||
export async function createTar( | ||
archivePath: string, | ||
paths: string[], | ||
cwd: string, | ||
): Promise<number> { | ||
const compressionMethod = await getTarCompressionMethod(); | ||
|
||
const compressionArgs = | ||
compressionMethod === CompressionMethod.GZIP | ||
? ['-z'] | ||
: compressionMethod === CompressionMethod.ZSTD_WITHOUT_LONG | ||
? ['--use-compress-program', 'zstd -T0 --long=30'] | ||
: ['--use-compress-program', 'zstd -T0']; | ||
|
||
return exec.exec('tar', [ | ||
'-c', | ||
...compressionArgs, | ||
'--posix', | ||
'-f', | ||
archivePath, | ||
'-C', | ||
cwd, | ||
...paths, | ||
]); | ||
} | ||
|
||
export async function extractTar( | ||
archivePath: string, | ||
cwd: string, | ||
): Promise<number> { | ||
const compressionMethod = await getTarCompressionMethod(); | ||
|
||
const compressionArgs = | ||
compressionMethod === CompressionMethod.GZIP | ||
? ['-z'] | ||
: compressionMethod === CompressionMethod.ZSTD_WITHOUT_LONG | ||
? ['--use-compress-program', 'zstd -d --long=30'] | ||
: ['--use-compress-program', 'zstd -d']; | ||
|
||
return exec.exec('tar', [ | ||
'-x', | ||
...compressionArgs, | ||
'-f', | ||
archivePath, | ||
'-C', | ||
cwd, | ||
]); | ||
} |