Use BSD tar on windows

This commit is contained in:
Josh Gross
2019-12-07 23:00:48 -05:00
parent 3d01b4eb53
commit 7352daed78
6 changed files with 117 additions and 163 deletions

27
src/tar.ts Normal file
View File

@@ -0,0 +1,27 @@
import { exec } from "@actions/exec";
import * as io from "@actions/io";
export async function extractTar(archivePath: string, targetDirectory: string) {
// Create directory to extract tar into
await io.mkdirP(targetDirectory);
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
await exec(`"${await getTarPath()}"`, args);
}
export async function createTar(archivePath: string, sourceDirectory: string) {
// http://man7.org/linux/man-pages/man1/tar.1.html
// tar [-options] <name of the tar archive> [files or directories which to add into archive]
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
await exec(`"${await getTarPath()}"`, args);
}
async function getTarPath(): Promise<string> {
// Explicitly use BSD Tar on Windows
const IS_WINDOWS = process.platform === "win32";
return IS_WINDOWS
? `${process.env["windir"]}\\System32\\tar.exe`
: await io.which("tar", true);
}