From 0dce0274b7c33e5d574f8da1e3b3cd008d3e5c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Mon, 25 Mar 2024 14:42:01 +0100 Subject: [PATCH] [setup-t] simplify ghostscript + qpdf install on Windows Download choco packages from GH releases, the choco repository is sometimes fragile. --- setup-r/lib/installer.js | 46 +++++++++++++++------------------------- setup-r/src/installer.ts | 46 ++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 57 deletions(-) diff --git a/setup-r/lib/installer.js b/setup-r/lib/installer.js index 3f5d3728..3f167553 100644 --- a/setup-r/lib/installer.js +++ b/setup-r/lib/installer.js @@ -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); } }); } @@ -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() { diff --git a/setup-r/src/installer.ts b/setup-r/src/installer.ts index ba03bb1e..37c9e428 100644 --- a/setup-r/src/installer.ts +++ b/setup-r/src/installer.ts @@ -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); } } @@ -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() {