mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-12-23 12:36:01 +01:00
Use path.sep in path replace
This commit is contained in:
parent
7c7d003bbb
commit
9fe7ad8b07
4 changed files with 17 additions and 149 deletions
|
@ -1,6 +1,5 @@
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
|
||||||
import * as tar from "../src/tar";
|
import * as tar from "../src/tar";
|
||||||
|
|
||||||
import fs = require("fs");
|
import fs = require("fs");
|
||||||
|
@ -34,9 +33,9 @@ test("extract BSD tar", async () => {
|
||||||
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
||||||
"-xz",
|
"-xz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath?.replace(/\\/g, "/"),
|
IS_WINDOWS ? archivePath.replace(/\\/g, "/") : archivePath,
|
||||||
"-C",
|
"-C",
|
||||||
targetDirectory?.replace(/\\/g, "/"),
|
IS_WINDOWS ? targetDirectory?.replace(/\\/g, "/") : targetDirectory
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,18 +52,14 @@ test("extract GNU tar", async () => {
|
||||||
await tar.extractTar(archivePath, targetDirectory);
|
await tar.extractTar(archivePath, targetDirectory);
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(2);
|
expect(execMock).toHaveBeenCalledTimes(2);
|
||||||
expect(execMock).toHaveBeenLastCalledWith(
|
expect(execMock).toHaveBeenLastCalledWith(`"tar"`, [
|
||||||
`"tar"`,
|
"-xz",
|
||||||
[
|
"-f",
|
||||||
"-xz",
|
archivePath.replace(/\\/g, "/"),
|
||||||
"-f",
|
"-C",
|
||||||
archivePath?.replace(/\\/g, "/"),
|
targetDirectory?.replace(/\\/g, "/"),
|
||||||
"-C",
|
"--force-local"
|
||||||
targetDirectory?.replace(/\\/g, "/"),
|
]);
|
||||||
"--force-local"
|
|
||||||
],
|
|
||||||
{ cwd: undefined }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -83,9 +78,9 @@ test("create BSD tar", async () => {
|
||||||
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
||||||
"-cz",
|
"-cz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath?.replace(/\\/g, "/"),
|
IS_WINDOWS ? archivePath.replace(/\\/g, "/") : archivePath,
|
||||||
"-C",
|
"-C",
|
||||||
sourceDirectory?.replace(/\\/g, "/"),
|
IS_WINDOWS ? sourceDirectory?.replace(/\\/g, "/") : sourceDirectory,
|
||||||
"."
|
"."
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
54
dist/restore/index.js
vendored
54
dist/restore/index.js
vendored
|
@ -2932,9 +2932,6 @@ const core = __importStar(__webpack_require__(470));
|
||||||
const exec_1 = __webpack_require__(986);
|
const exec_1 = __webpack_require__(986);
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
const fs_1 = __webpack_require__(747);
|
const fs_1 = __webpack_require__(747);
|
||||||
<<<<<<< HEAD
|
|
||||||
function getTarPath() {
|
|
||||||
=======
|
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const constants_1 = __webpack_require__(694);
|
const constants_1 = __webpack_require__(694);
|
||||||
function isGnuTar() {
|
function isGnuTar() {
|
||||||
|
@ -2955,7 +2952,6 @@ function isGnuTar() {
|
||||||
}
|
}
|
||||||
exports.isGnuTar = isGnuTar;
|
exports.isGnuTar = isGnuTar;
|
||||||
function getTarPath(args) {
|
function getTarPath(args) {
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Explicitly use BSD Tar on Windows
|
// Explicitly use BSD Tar on Windows
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
|
@ -2971,80 +2967,30 @@ function getTarPath(args) {
|
||||||
return yield io.which("tar", true);
|
return yield io.which("tar", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
function execTar(args) {
|
function execTar(args) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
||||||
=======
|
|
||||||
function execTar(args, cwd) {
|
|
||||||
var _a;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
try {
|
|
||||||
yield exec_1.exec(`"${yield getTarPath(args)}"`, args, { cwd: cwd });
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}`);
|
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
function extractTar(archivePath, targetDirectory) {
|
function extractTar(archivePath, targetDirectory) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Create directory to extract tar into
|
// Create directory to extract tar into
|
||||||
yield io.mkdirP(targetDirectory);
|
yield io.mkdirP(targetDirectory);
|
||||||
const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
||||||
=======
|
|
||||||
function getWorkingDirectory() {
|
|
||||||
var _a;
|
|
||||||
return _a = process.env["GITHUB_WORKSPACE"], (_a !== null && _a !== void 0 ? _a : process.cwd());
|
|
||||||
}
|
|
||||||
function extractTar(archivePath) {
|
|
||||||
var _a, _b;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Create directory to extract tar into
|
|
||||||
const workingDirectory = getWorkingDirectory();
|
|
||||||
yield io.mkdirP(workingDirectory);
|
|
||||||
const args = [
|
|
||||||
"-xz",
|
|
||||||
"-f",
|
|
||||||
(_a = archivePath) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, "/"),
|
|
||||||
"-P",
|
|
||||||
"-C",
|
|
||||||
(_b = workingDirectory) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, "/")
|
|
||||||
];
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
yield execTar(args);
|
yield execTar(args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.extractTar = extractTar;
|
exports.extractTar = extractTar;
|
||||||
<<<<<<< HEAD
|
|
||||||
function createTar(archivePath, sourceDirectory) {
|
function createTar(archivePath, sourceDirectory) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
||||||
yield execTar(args);
|
yield execTar(args);
|
||||||
=======
|
|
||||||
function createTar(archiveFolder, sourceDirectories) {
|
|
||||||
var _a, _b;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Write source directories to manifest.txt to avoid command length limits
|
|
||||||
const manifestFilename = "manifest.txt";
|
|
||||||
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join("\n"));
|
|
||||||
const workingDirectory = getWorkingDirectory();
|
|
||||||
const args = [
|
|
||||||
"-cz",
|
|
||||||
"-f",
|
|
||||||
(_a = constants_1.CacheFilename) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, "/"),
|
|
||||||
"-P",
|
|
||||||
"-C",
|
|
||||||
(_b = workingDirectory) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, "/"),
|
|
||||||
"--files-from",
|
|
||||||
manifestFilename
|
|
||||||
];
|
|
||||||
yield execTar(args, archiveFolder);
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.createTar = createTar;
|
exports.createTar = createTar;
|
||||||
|
|
73
dist/save/index.js
vendored
73
dist/save/index.js
vendored
|
@ -2913,30 +2913,7 @@ const core = __importStar(__webpack_require__(470));
|
||||||
const exec_1 = __webpack_require__(986);
|
const exec_1 = __webpack_require__(986);
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
const fs_1 = __webpack_require__(747);
|
const fs_1 = __webpack_require__(747);
|
||||||
<<<<<<< HEAD
|
|
||||||
function getTarPath() {
|
function getTarPath() {
|
||||||
=======
|
|
||||||
const path = __importStar(__webpack_require__(622));
|
|
||||||
const constants_1 = __webpack_require__(694);
|
|
||||||
function isGnuTar() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
core.debug("Checking tar --version");
|
|
||||||
let versionOutput = "";
|
|
||||||
yield exec_1.exec("tar --version", [], {
|
|
||||||
ignoreReturnCode: true,
|
|
||||||
silent: true,
|
|
||||||
listeners: {
|
|
||||||
stdout: (data) => (versionOutput += data.toString()),
|
|
||||||
stderr: (data) => (versionOutput += data.toString())
|
|
||||||
}
|
|
||||||
});
|
|
||||||
core.debug(versionOutput.trim());
|
|
||||||
return versionOutput.toUpperCase().includes("GNU TAR");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.isGnuTar = isGnuTar;
|
|
||||||
function getTarPath(args) {
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Explicitly use BSD Tar on Windows
|
// Explicitly use BSD Tar on Windows
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
|
@ -2952,80 +2929,30 @@ function getTarPath(args) {
|
||||||
return yield io.which("tar", true);
|
return yield io.which("tar", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
function execTar(args) {
|
function execTar(args) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
yield exec_1.exec(`"${yield getTarPath()}"`, args);
|
||||||
=======
|
|
||||||
function execTar(args, cwd) {
|
|
||||||
var _a;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
try {
|
|
||||||
yield exec_1.exec(`"${yield getTarPath(args)}"`, args, { cwd: cwd });
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}`);
|
throw new Error(`Tar failed with error: ${(_a = error) === null || _a === void 0 ? void 0 : _a.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
|
||||||
function extractTar(archivePath, targetDirectory) {
|
function extractTar(archivePath, targetDirectory) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Create directory to extract tar into
|
// Create directory to extract tar into
|
||||||
yield io.mkdirP(targetDirectory);
|
yield io.mkdirP(targetDirectory);
|
||||||
const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
const args = ["-xz", "-f", archivePath, "-C", targetDirectory];
|
||||||
=======
|
|
||||||
function getWorkingDirectory() {
|
|
||||||
var _a;
|
|
||||||
return _a = process.env["GITHUB_WORKSPACE"], (_a !== null && _a !== void 0 ? _a : process.cwd());
|
|
||||||
}
|
|
||||||
function extractTar(archivePath) {
|
|
||||||
var _a, _b;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Create directory to extract tar into
|
|
||||||
const workingDirectory = getWorkingDirectory();
|
|
||||||
yield io.mkdirP(workingDirectory);
|
|
||||||
const args = [
|
|
||||||
"-xz",
|
|
||||||
"-f",
|
|
||||||
(_a = archivePath) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, "/"),
|
|
||||||
"-P",
|
|
||||||
"-C",
|
|
||||||
(_b = workingDirectory) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, "/")
|
|
||||||
];
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
yield execTar(args);
|
yield execTar(args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.extractTar = extractTar;
|
exports.extractTar = extractTar;
|
||||||
<<<<<<< HEAD
|
|
||||||
function createTar(archivePath, sourceDirectory) {
|
function createTar(archivePath, sourceDirectory) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
const args = ["-cz", "-f", archivePath, "-C", sourceDirectory, "."];
|
||||||
yield execTar(args);
|
yield execTar(args);
|
||||||
=======
|
|
||||||
function createTar(archiveFolder, sourceDirectories) {
|
|
||||||
var _a, _b;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Write source directories to manifest.txt to avoid command length limits
|
|
||||||
const manifestFilename = "manifest.txt";
|
|
||||||
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join("\n"));
|
|
||||||
const workingDirectory = getWorkingDirectory();
|
|
||||||
const args = [
|
|
||||||
"-cz",
|
|
||||||
"-f",
|
|
||||||
(_a = constants_1.CacheFilename) === null || _a === void 0 ? void 0 : _a.replace(/\\/g, "/"),
|
|
||||||
"-P",
|
|
||||||
"-C",
|
|
||||||
(_b = workingDirectory) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, "/"),
|
|
||||||
"--files-from",
|
|
||||||
manifestFilename
|
|
||||||
];
|
|
||||||
yield execTar(args, archiveFolder);
|
|
||||||
>>>>>>> 4fa017f... Fallback to GNU tar if BSD tar is unavailable
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.createTar = createTar;
|
exports.createTar = createTar;
|
||||||
|
|
10
src/tar.ts
10
src/tar.ts
|
@ -28,7 +28,7 @@ async function getTarPath(args: string[]): Promise<string> {
|
||||||
const systemTar = `${process.env["windir"]}\\System32\\tar.exe`;
|
const systemTar = `${process.env["windir"]}\\System32\\tar.exe`;
|
||||||
if (existsSync(systemTar)) {
|
if (existsSync(systemTar)) {
|
||||||
return systemTar;
|
return systemTar;
|
||||||
} else if (isGnuTar()) {
|
} else if (await isGnuTar()) {
|
||||||
args.push("--force-local");
|
args.push("--force-local");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,9 @@ export async function extractTar(
|
||||||
const args = [
|
const args = [
|
||||||
"-xz",
|
"-xz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath?.replace(/\\/g, "/"),
|
archivePath.replace(new RegExp("\\" + path.sep, "g"), "/"),
|
||||||
"-C",
|
"-C",
|
||||||
targetDirectory?.replace(/\\/g, "/")
|
targetDirectory.replace(new RegExp("\\" + path.sep, "g"), "/")
|
||||||
];
|
];
|
||||||
await execTar(args);
|
await execTar(args);
|
||||||
}
|
}
|
||||||
|
@ -66,9 +66,9 @@ export async function createTar(
|
||||||
const args = [
|
const args = [
|
||||||
"-cz",
|
"-cz",
|
||||||
"-f",
|
"-f",
|
||||||
archivePath?.replace(/\\/g, "/"),
|
archivePath.replace(new RegExp("\\" + path.sep, "g"), "/"),
|
||||||
"-C",
|
"-C",
|
||||||
sourceDirectory?.replace(/\\/g, "/"),
|
sourceDirectory.replace(new RegExp("\\" + path.sep, "g"), "/"),
|
||||||
"."
|
"."
|
||||||
];
|
];
|
||||||
await execTar(args);
|
await execTar(args);
|
||||||
|
|
Loading…
Reference in a new issue