Skip to content

Commit

Permalink
[setup-t] simplify ghostscript + qpdf install on Windows
Browse files Browse the repository at this point in the history
Download choco packages from GH releases, the choco repository
is sometimes fragile.
  • Loading branch information
gaborcsardi committed Mar 25, 2024
1 parent faf8dab commit 0dce027
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 57 deletions.
46 changes: 17 additions & 29 deletions setup-r/lib/installer.js
Expand Up @@ -141,27 +141,17 @@ function acquireR(version) {
// does not know that
if (IS_WINDOWS && version.rtools) {
const rtoolsVersionNumber = parseInt(version.rtools);
const noqpdf = rtoolsVersionNumber >= 41;
var tries_left = 10;
var ok = false;
while (!ok && tries_left > 0) {
try {
yield acquireQpdfWindows(noqpdf);
ok = true;
}
catch (error) {
core.warning(`Failed to download qpdf or ghostscript: ${error}`);
yield new Promise(f => setTimeout(f, 10000));
tries_left = tries_left - 1;
}
try {
yield acquireQpdfWindows();
ok = true;
}
catch (error) {
throw "Failed to get qpdf and ghostscript.";
}
if (!ok) {
throw `Failed to get qpdf and ghostscript in 10 tries :(`;
}
let gspath = "c:\\program files\\gs\\" +
fs.readdirSync("c:\\program files\\gs") +
"\\bin";
core.addPath(gspath);
}
});
}
Expand Down Expand Up @@ -598,20 +588,18 @@ function acquireRtools(version) {
}
});
}
function acquireQpdfWindows(noqpdf) {
function acquireQpdfWindows() {
return __awaiter(this, void 0, void 0, function* () {
var pkgs = ["ghostscript"];
if (noqpdf) {
pkgs = pkgs.concat(["qpdf"]);
}
var args = ["install"].concat(pkgs).concat(["--no-progress"]);
try {
yield exec.exec("choco", args);
}
catch (error) {
core.debug(`${error}`);
throw `Failed to install qpdf: ${error}`;
}
yield core.group("Downloading and installing Ghostscript, qpdf", () => __awaiter(this, void 0, void 0, function* () {
let dlpath = yield tc.downloadTool("https://github.com/r-lib/actions/releases/download/sysreqs/autohotkey.portable.nupkg");
yield io.mv(dlpath, path.join(tempDirectory, "autohotkey.portable.nupkg"));
dlpath = yield tc.downloadTool("https://github.com/r-lib/actions/releases/download/sysreqs/Ghostscipt.app.nupkg");
yield io.mv(dlpath, path.join(tempDirectory, "Ghostscipt.app.nupkg"));
dlpath = yield tc.downloadTool("https://github.com/r-lib/actions/releases/download/sysreqs/qpdf.nupkg");
yield io.mv(dlpath, path.join(tempDirectory, "qpdf.nupkg"));
yield exec.exec("choco", ["install", "Ghostscript.app", "qpdf", "--source", tempDirectory]);
;
}));
});
}
function setupRLibrary() {
Expand Down
46 changes: 18 additions & 28 deletions setup-r/src/installer.ts
Expand Up @@ -117,24 +117,14 @@ async function acquireR(version: IRVersion) {
// does not know that
if (IS_WINDOWS && version.rtools) {
const rtoolsVersionNumber = parseInt(version.rtools);
const noqpdf = rtoolsVersionNumber >= 41;
var tries_left = 10;
var ok = false;
while (!ok && tries_left > 0) {
try {
await acquireQpdfWindows(noqpdf);
ok = true;
} catch (error) {
core.warning(`Failed to download qpdf or ghostscript: ${error}`);
await new Promise(f => setTimeout(f, 10000));
tries_left = tries_left - 1;
}
try {
await acquireQpdfWindows();
ok = true;
} catch (error) {
throw "Failed to get qpdf and ghostscript."
}
if (!ok) { throw `Failed to get qpdf and ghostscript in 10 tries :(` }
let gspath = "c:\\program files\\gs\\" +
fs.readdirSync("c:\\program files\\gs") +
"\\bin";
core.addPath(gspath);
}
}

Expand Down Expand Up @@ -571,19 +561,19 @@ async function acquireRtools(version: IRVersion) {
}
}

async function acquireQpdfWindows(noqpdf) {
var pkgs = ["ghostscript"];
if (noqpdf) {
pkgs = pkgs.concat(["qpdf"]);
}
var args = ["install"].concat(pkgs).concat(["--no-progress"]);
try {
await exec.exec("choco", args);
} catch (error) {
core.debug(`${error}`);

throw `Failed to install qpdf: ${error}`;
}
async function acquireQpdfWindows() {
await core.group("Downloading and installing Ghostscript, qpdf", async() => {
let dlpath = await tc.downloadTool("https://github.com/r-lib/actions/releases/download/sysreqs/autohotkey.portable.nupkg");
await io.mv(dlpath, path.join(tempDirectory, "autohotkey.portable.nupkg"));
dlpath = await tc.downloadTool("https://github.com/r-lib/actions/releases/download/sysreqs/Ghostscipt.app.nupkg");
await io.mv(dlpath, path.join(tempDirectory, "Ghostscipt.app.nupkg"));
dlpath = await tc.downloadTool("https://github.com/r-lib/actions/releases/download/sysreqs/qpdf.nupkg");
await io.mv(dlpath, path.join(tempDirectory, "qpdf.nupkg"));
await exec.exec(
"choco",
["install", "Ghostscript.app", "qpdf", "--source", tempDirectory]
);;
})
}

async function setupRLibrary() {
Expand Down

0 comments on commit 0dce027

Please sign in to comment.