-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathinstaller.ts
805 lines (688 loc) · 21.7 KB
/
installer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
let tempDirectory = process.env["RUNNER_TEMP"] || "";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as tc from "@actions/tool-cache";
import * as io from "@actions/io";
import * as util from "util";
import * as path from "path";
import * as fs from "fs";
import * as restm from "typed-rest-client/RestClient";
import * as semver from "semver";
import osInfo from "linux-os-info";
const IS_WINDOWS = process.platform === "win32";
const IS_MAC = process.platform === "darwin";
const IS_LINUX = process.platform === "linux";
if (!tempDirectory) {
let baseLocation: string;
if (IS_WINDOWS) {
// On windows use the USERPROFILE env variable
baseLocation = process.env["USERPROFILE"] || "C:\\";
} else {
if (IS_MAC) {
baseLocation = "/Users";
} else {
baseLocation = "/home";
}
}
tempDirectory = path.join(baseLocation, "actions", "temp");
}
export async function getR(version: string) {
const selected = await determineVersion(version);
if (selected) {
version = selected;
}
// this works for 'next' and 'devel' as well, currently.
let rtoolsVersion =
core.getInput("rtools-version") || (version.charAt(0) == "3" ? "35" : "40");
let toolPath = tc.find("R", version);
if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`);
} else {
try {
await acquireR(version, rtoolsVersion);
} catch (error) {
core.debug(`${error}`);
throw `Failed to get R ${version}: ${error}`;
}
}
setREnvironmentVariables();
setupRLibrary();
core.setOutput("installed-r-version", version);
}
async function acquireR(version: string, rtoolsVersion: string) {
if (core.getInput("install-r") !== "true") {
return;
}
try {
if (IS_WINDOWS) {
await Promise.all([
await acquireRWindows(version),
await acquireRtools(rtoolsVersion),
]);
} else if (IS_MAC) {
await core.group('Downloading gfortran', async() => { await acquireFortranMacOS() });
await core.group('Downloading macOS utils', async() => { await acquireUtilsMacOS() });
await core.group('Downloading R', async() => { await acquireRMacOS(version) });
if (core.getInput("remove-openmp-macos") === "true") {
await core.group('Patching -fopenmp', async() => { await removeOpenmpFlags() });
}
} else {
await acquireRUbuntu(version);
}
} catch (error) {
core.debug(`${error}`);
throw `Failed to get R ${version}: ${error}`;
}
if (IS_WINDOWS) {
const rtoolsVersionNumber = parseInt(rtoolsVersion.substring(0, 2));
const rtools42 = rtoolsVersionNumber >= 41;
if (rtools42) {
var tries_left = 10;
var ok = false;
while (!ok && tries_left > 0) {
try {
await acquireQpdfWindows();
ok = true;
} catch (error) {
core.warning("Failed to download qpdf: ${error}");
await new Promise(f => setTimeout(f, 10000));
tries_left = tries_left - 1;
}
}
if (!ok) { throw `Failed to get qpdf in 10 tries :(` }
}
}
}
async function acquireFortranMacOS(): Promise<string> {
let gfortran: string = "gfortran-8.2-Mojave";
let mntPath: string = path.join("/Volumes", gfortran);
let fileName: string = `${gfortran}.dmg`;
let downloadUrl: string = `https://mac.r-project.org/tools/${fileName}`;
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(`${error}`);
throw `Failed to download ${downloadUrl}: ${error}`;
}
try {
await exec.exec("sudo", [
"hdiutil",
"attach",
path.join(tempDirectory, fileName)
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to mount ${fileName}: ${error}`;
}
try {
await exec.exec("sudo", [
"installer",
"-allowUntrusted",
"-dumplog",
"-package",
path.join(mntPath, gfortran, "gfortran.pkg"),
"-target",
"/"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to install gfortran: ${error}`;
}
// We do not detach the volume here, because it might lead to hangs
core.addPath("/usr/local/gfortran/bin");
// rename the gcov executable shipped with gfortran, as it conflits with the
// normal gcov executable in llvm, and we cannot append paths to PATH
// currently https://github.com/actions/toolkit/issues/270
await exec.exec("sudo", [
"mv",
"/usr/local/gfortran/bin/gcov",
"/usr/local/gfortran/bin/gcov-fortran"
]);
return "/";
}
async function acquireUtilsMacOS() {
// qpdf is needed by `--as-cran`
try {
await exec.exec("brew", ["install", "qpdf", "pkgconfig", "checkbashisms"]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to install qpdf: ${error}`;
}
}
async function removeOpenmpFlags() {
try {
await exec.exec("sed", [
"-i",
".bak",
"-e",
"s/-fopenmp//g",
"/Library/Frameworks/R.framework/Resources/etc/Makeconf"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to remove OpenMP flags: ${error}`;
}
}
async function acquireRUbuntu(version: string): Promise<string> {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileNameUbuntu(version);
let downloadUrl: string = getDownloadUrlUbuntu(fileName);
let downloadPath: string | null = null;
core.startGroup('Downloading R');
try {
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(`${error}`);
throw `Failed to download version ${version}: ${error}`;
}
core.endGroup()
//
// Install
//
let extPath: string = tempDirectory;
if (!extPath) {
throw new Error("Temp directory not set");
}
try {
await core.group('Updating system package data', async() => {
await exec.exec(
"sudo DEBIAN_FRONTEND=noninteractive apt-get update -y -qq"
);
});
// install gdbi-core and also qpdf, which is used by `--as-cran`
await core.group('Installing R system requirements', async() => {
await exec.exec(
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y gdebi-core qpdf devscripts"
);
});
await core.group("Installing R", async() => {
await exec.exec("sudo gdebi", [
"--non-interactive",
path.join(tempDirectory, fileName)
]);
});
} catch (error) {
core.debug(`${error}`);
throw `Failed to install R: ${error}`;
}
//
// Add symlinks to the installed R to the path
//
//
try {
await exec.exec("sudo ln", [
"-sf",
path.join("/opt", "R", version, "bin", "R"),
"/usr/local/bin/R"
]);
await exec.exec("sudo ln", [
"-sf",
path.join("/opt", "R", version, "bin", "Rscript"),
"/usr/local/bin/Rscript"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to setup symlinks to R: ${error}`;
}
return "/usr/local/bin";
}
async function acquireRMacOS(version: string): Promise<string> {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileNameMacOS(version);
let downloadUrl: string = await getDownloadUrlMacOS(version);
let downloadPath: string | null = null;
try {
if (downloadUrl == "") {
throw("Cannot determine download URL");
}
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(`${error}`);
throw `Failed to download version ${version}: ${error}`;
}
//
// Extract
//
let extPath: string = tempDirectory;
if (!extPath) {
throw new Error("Temp directory not set");
}
try {
await exec.exec("sudo", [
"installer",
"-allowUntrusted",
"-dumplog",
"-pkg",
path.join(tempDirectory, fileName),
"-target",
"/"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to install R: ${error}`;
}
// Older R versions on newer macOS cannot create a symlink to R and
// Rscript, we'll need to do it manually.
try {
await exec.exec("sudo ln", [
"-sf",
"/Library/Frameworks/R.framework/Resources/bin/R",
"/usr/local/bin/R"
]);
await exec.exec("sudo ln", [
"-sf",
"/Library/Frameworks/R.framework/Resources/bin/Rscript",
"/usr/local/bin/Rscript"
]);
} catch (error) {
core.debug(`${error}`);
core.debug("Marching on despite failed symlink creation.")
}
return "/";
}
async function acquireRWindows(version: string): Promise<string> {
let fileName: string = getFileNameWindows(version);
let downloadUrl: string = await getDownloadUrlWindows(version);
let downloadPath: string | null = null;
try {
if (downloadUrl == "") {
throw("Cannot determine download URL");
}
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(`${error}`);
throw `Failed to download version ${version}: ${error}`;
}
//
// Install
//
let extPath: string = tempDirectory;
if (!extPath) {
throw new Error("Temp directory not set");
}
try {
await exec.exec(path.join(tempDirectory, fileName), [
"/VERYSILENT",
"/SUPPRESSMSGBOXES",
"/DIR=C:\\R"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to install R: ${error}`;
}
core.addPath(`C:\\R\\bin`);
return "";
}
async function acquireRtools(version: string) {
const versionNumber = parseInt(version.substring(0, 2));
const rtools42 = versionNumber >= 41;
const rtools40 = !rtools42 && versionNumber >= 40;
const rtools3x = !rtools42 && !rtools40;
var downloadUrl, fileName;
if (rtools3x) {
fileName = util.format("Rtools%s.exe", version);
downloadUrl = util.format(
"http://cloud.r-project.org/bin/windows/Rtools/%s",
fileName)
} else if (rtools40) {
fileName = util.format("rtools%s-x86_64.exe", version);
downloadUrl = util.format(
"http://cloud.r-project.org/bin/windows/Rtools/%s",
fileName)
} else { // rtools42
fileName = "rtools42-5038-5046.exe";
downloadUrl = "https://github.com/gaborcsardi/Rtools42/releases/download/5038-5046/rtools42-5038-5046.exe";
}
// If Rtools is already installed just return, as there is a message box
// which hangs the build otherwise.
if (
(rtools42 && fs.existsSync("C:\\Rtools42")) ||
(rtools40 && fs.existsSync("C:\\rtools40")) ||
(rtools3x && fs.existsSync("C:\\Rtools"))
) {
core.debug(
"Skipping Rtools installation as a suitable Rtools is already installed"
);
} else {
console.log(`Downloading ${downloadUrl}...`);
let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
await io.mv(downloadPath, path.join(tempDirectory, fileName));
} catch (error) {
core.debug(`${error}`);
throw `Failed to download version ${version}: ${error}`;
}
try {
await exec.exec(path.join(tempDirectory, fileName), [
"/VERYSILENT",
"/SUPPRESSMSGBOXES"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to install Rtools: ${error}`;
}
}
if (rtools42) {
core.addPath(`C:\\rtools42\\usr\\bin`);
core.addPath(`C:\\rtools42\\x86_64-w64-mingw32.static.posix\\bin`);
} else if (rtools40) {
core.addPath(`C:\\rtools40\\usr\\bin`);
if (core.getInput("r-version").match("devel")) {
core.addPath(`C:\\rtools40\\ucrt64\\bin`);
core.exportVariable("_R_INSTALL_TIME_PATCHES_", "no");
}
if (core.getInput("update-rtools") === "true") {
try {
await exec.exec("c:\\rtools40\\usr\\bin\\bash.exe", [
"--login",
"-c",
"pacman -Syu --noconfirm"
]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to update rtools40 libraries: ${error}`;
}
}
} else { // rtools3x
core.addPath(`C:\\Rtools\\bin`);
if (core.getInput("windows-path-include-mingw") === "true") {
core.addPath(`C:\\Rtools\\mingw_64\\bin`);
}
}
}
async function acquireQpdfWindows() {
try {
await exec.exec("choco", ["install", "qpdf", "--no-progress"]);
} catch (error) {
core.debug(`${error}`);
throw `Failed to install qpdf: ${error}`;
}
}
async function setupRLibrary() {
let profilePath: fs.PathLike | fs.promises.FileHandle;
if (IS_WINDOWS) {
profilePath = path.join(
process.env["USERPROFILE"] || "C:\\",
"Documents",
".Rprofile"
);
} else {
profilePath = path.join(process.env["HOME"] || "/Users", ".Rprofile");
}
core.debug("R profile is at " + profilePath);
let rspm = process.env["RSPM"] ? `'${process.env["RSPM"]}'` : "NULL";
if (rspm === "NULL" && core.getInput("use-public-rspm") === "true") {
if (IS_WINDOWS) {
rspm = "'https://packagemanager.rstudio.com/all/latest'";
}
if (IS_LINUX) {
let codename = "";
try {
await exec.exec("lsb_release", ["--short", "--codename"], {
listeners: {
stdout: (data: Buffer): string => (codename += data.toString())
}
});
} catch (error) {
core.debug(`${error}`);
throw `Failed to query the linux version: ${error}`;
}
codename = codename.trim();
rspm = `'https://packagemanager.rstudio.com/all/__linux__/${codename}/latest'`;
}
}
if (rspm !== "NULL") {
core.exportVariable("RSPM", rspm.replace(/^'|'$/g, ""));
}
let cran = `'${core.getInput("cran") ||
process.env["CRAN"] ||
"https://cloud.r-project.org"}'`;
let user_agent;
if (core.getInput("http-user-agent") === "release") {
let os = IS_WINDOWS ? "win" : IS_MAC ? "macos" : "tarball";
let version = await getReleaseVersion(os);
user_agent = `sprintf("R/${version} R (${version} %s) on GitHub Actions", paste(R.version$platform, R.version$arch, R.version$os))`;
} else {
user_agent =
core.getInput("http-user-agent") === "default" ||
core.getInput("http-user-agent") === ""
? 'sprintf("R/%s R (%s) on GitHub Actions", getRversion(), paste(getRversion(), R.version$platform, R.version$arch, R.version$os))'
: `"${core.getInput("http-user-agent")}"`;
}
// Split the repositories by whitespace and then quote each entry joining with commas
let extra_repositories = core.getInput("extra-repositories");
// Prepend a , if there are extra repositories
if (extra_repositories) {
extra_repositories = extra_repositories
.split(/\s+/)
.map(x => `"${x}"`)
.join(",");
extra_repositories = ",\n " + extra_repositories;
}
await fs.promises.writeFile(
profilePath,
`Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
options(
repos = c(
RSPM = ${rspm},
CRAN = ${cran}${extra_repositories}
),
Ncpus = ${core.getInput("Ncpus")},
HTTPUserAgent = ${user_agent}
)\n`
);
// Make R_LIBS_USER
io.mkdirP(process.env["R_LIBS_USER"] || path.join(tempDirectory, "Library"));
}
function getFileNameMacOS(version: string): string {
const filename: string = util.format("R-%s.pkg", version);
return filename;
}
async function getDownloadUrlMacOS(version: string): Promise<string> {
if (version == "devel") {
return "https://mac.R-project.org/high-sierra/last-success/R-devel-x86_64.pkg";
}
if (version == "next" || version == "prerelease") {
return getDownloadUrlMacOSNext();
}
const filename: string = getFileNameMacOS(version);
if (semver.eq(version, "3.2.5")) {
// 3.2.5 is 'special', it is actually 3.2.4-revised...
return "https://cloud.r-project.org/bin/macosx/old/R-3.2.4-revised.pkg";
}
if (semver.lt(version, "3.4.0")) {
// older versions are in /old
return util.format(
"https://cloud.r-project.org/bin/macosx/old/%s",
filename
);
}
if (semver.lt(version, "4.0.0")) {
// older versions are in el-capitan/base
return util.format(
"https://cloud.r-project.org/bin/macosx/el-capitan/base/%s",
filename
);
}
// 4.0.0+ are in base/
return util.format(
"https://cloud.r-project.org/bin/macosx/base/%s",
filename
);
}
function getFileNameUbuntu(version: string): string {
const filename: string = util.format("r-%s_1_amd64.deb", version);
return filename;
}
function getDownloadUrlUbuntu(filename: string): string {
try {
const info = osInfo({ mode: "sync" });
const versionStr = info.version_id.replace(/[.]/g, "");
return util.format(
"https://cdn.rstudio.com/r/ubuntu-%s/pkgs/%s",
versionStr,
filename
);
} catch (error) {
throw `Failed to get OS info: ${error}`;
}
}
function getFileNameWindows(version: string): string {
const filename: string = util.format("R-%s-win.exe", version);
return filename;
}
async function getDownloadUrlWindows(version: string): Promise<string> {
if (version == "devel") {
return "https://cloud.r-project.org/bin/windows/base/R-devel-win.exe";
}
if (version == "next" || version == "prerelease") {
return getDownloadUrlWindowsNext();
}
const filename: string = getFileNameWindows(version);
const releaseVersion: string = await getReleaseVersion("win");
if (version == releaseVersion) {
return util.format(
"https://cloud.r-project.org/bin/windows/base/%s",
filename
);
}
return util.format(
"https://cloud.r-project.org/bin/windows/base/old/%s/%s",
version,
filename
);
}
function setREnvironmentVariables() {
core.exportVariable("R_LIBS_USER", path.join(tempDirectory, "Library"));
core.exportVariable("TZ", "UTC");
core.exportVariable("_R_CHECK_SYSTEM_CLOCK_", "FALSE");
if (!process.env["NOT_CRAN"]) core.exportVariable("NOT_CRAN", "true");
}
interface IRRef {
version: string;
}
interface IRRefURL {
URL: string;
}
async function getReleaseVersion(platform: string): Promise<string> {
let rest: restm.RestClient = new restm.RestClient("setup-r");
let tags: IRRef = (
await rest.get<IRRef>(
util.format("https://api.r-hub.io/rversions/r-release-%s", platform)
)
).result || { version: "" };
return tags.version;
}
async function getOldrelVersion(version: string): Promise<string> {
let rest: restm.RestClient = new restm.RestClient("setup-r");
let tags: IRRef = (
await rest.get<IRRef>(
util.format("https://api.r-hub.io/rversions/r-oldrel/%s", version)
)
).result || { version: "" };
return tags.version;
}
async function getAvailableVersions(): Promise<string[]> {
let rest: restm.RestClient = new restm.RestClient("setup-r");
let tags: IRRef[] =
(await rest.get<IRRef[]>("https://api.r-hub.io/rversions/r-versions"))
.result || [];
return tags.map(tag => tag.version);
}
async function determineVersion(version: string): Promise<string> {
// There is no linux endpoint, so we just use the tarball one for linux.
version = version.toLowerCase();
// Formerly called 'devel-ucrt' is now just 'devel'
if (version == "devel-ucrt") {
return "devel";
}
if (version == "latest" || version == "release") {
if (IS_WINDOWS) {
return getReleaseVersion("win");
}
if (IS_MAC) {
return getReleaseVersion("macos");
}
return getReleaseVersion("tarball");
}
if (version.startsWith("oldrel")) {
const [, oldRelVersion] = version.split(/[-\/]/);
if (oldRelVersion == null) {
return getOldrelVersion("1");
}
return getOldrelVersion(oldRelVersion);
}
if (!version.endsWith(".x")) {
const versionPart = version.split(".");
if (versionPart[1] == null || versionPart[2] == null) {
return await getLatestVersion(version.concat(".x"));
} else {
// This is also 'next' and 'devel'
return version;
}
}
return await getLatestVersion(version);
}
// This function is required to convert the version 1.10 to 1.10.0.
// Because caching utility accept only sementic version,
// which have patch number as well.
function normalizeVersion(version: string): string {
const versionPart = version.split(".");
if (versionPart[1] == null) {
//append minor and patch version if not available
return version.concat(".0.0");
}
if (versionPart[2] == null) {
//append patch version if not available
return version.concat(".0");
}
return version;
}
async function getPossibleVersions(version: string): Promise<string[]> {
const versions = await getAvailableVersions();
const possibleVersions = versions.filter(v => v.startsWith(version));
const versionMap = new Map();
possibleVersions.forEach(v => versionMap.set(normalizeVersion(v), v));
return Array.from(versionMap.keys())
.sort(semver.rcompare)
.map(v => versionMap.get(v));
}
async function getLatestVersion(version: string): Promise<string> {
// clean .x syntax: 1.10.x -> 1.10
const trimmedVersion = version.slice(0, version.length - 2);
const versions = await getPossibleVersions(trimmedVersion);
core.debug(`evaluating ${versions.length} versions`);
if (version.length === 0) {
throw new Error("unable to get latest version");
}
core.debug(`matched: ${versions[0]}`);
return versions[0];
}
async function getDownloadUrlWindowsNext(): Promise<string> {
let rest: restm.RestClient = new restm.RestClient("setup-r");
let tags: IRRefURL = (
await rest.get<IRRefURL>(
"https://api.r-hub.io/rversions/r-next-win"
)
).result || { URL: "" };
return tags.URL;
}
async function getDownloadUrlMacOSNext() {
let rest: restm.RestClient = new restm.RestClient("setup-r");
let tags: IRRefURL = (
await rest.get<IRRefURL>(
"https://api.r-hub.io/rversions/r-next-macos"
)
).result || { URL: "" };
return tags.URL;
}