Install rustup
only on MacOS
This commit is contained in:
parent
cd0149be15
commit
7b201a613e
@ -16,6 +16,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const rustup = __importStar(require("./rustup"));
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@ -23,6 +24,7 @@ function run() {
|
||||
const version = core.getInput('rust-version');
|
||||
if (version) {
|
||||
yield rustup.install(version);
|
||||
exec.exec('rustup', ['default', version]);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
@ -17,24 +17,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const io = __importStar(require("@actions/io"));
|
||||
const toolCache = __importStar(require("@actions/tool-cache"));
|
||||
const path = __importStar(require("path"));
|
||||
const os = __importStar(require("os"));
|
||||
const fs_1 = require("fs");
|
||||
let osPlat = os.platform();
|
||||
let osArch = os.arch();
|
||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||
const WINDOWS = osPlat == 'win32';
|
||||
function install(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let toolPath = toolCache.find('rust', version);
|
||||
if (!toolPath) {
|
||||
toolPath = yield acquireRust(version);
|
||||
if (os.platform() == 'darwin') {
|
||||
let toolPath = yield acquireRust(version);
|
||||
core.debug('Rust toolchain is cached under ' + toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
}
|
||||
toolPath = path.join(toolPath, 'bin');
|
||||
core.addPath(toolPath);
|
||||
});
|
||||
}
|
||||
exports.install = install;
|
||||
@ -42,42 +36,15 @@ function acquireRust(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let script;
|
||||
try {
|
||||
script = yield toolCache.downloadTool(rustupUrl());
|
||||
script = yield toolCache.downloadTool("https://sh.rustup.rs");
|
||||
}
|
||||
catch (error) {
|
||||
core.debug(error);
|
||||
throw `Failed to download rustup: ${error}`;
|
||||
}
|
||||
if (WINDOWS) {
|
||||
yield io.cp(script, script + '.exe');
|
||||
script += '.exe';
|
||||
console.log(yield io.which('rustup', true));
|
||||
yield exec.exec(`"${script}"`, [
|
||||
'-y',
|
||||
'--default-toolchain',
|
||||
'none',
|
||||
]);
|
||||
}
|
||||
else {
|
||||
fs_1.chmodSync(script, '777');
|
||||
yield exec.exec(`"${script}"`, ['-y', '--default-toolchain', version]);
|
||||
}
|
||||
return yield toolCache.cacheDir(binRoot(), 'rust', version);
|
||||
fs_1.chmodSync(script, '777');
|
||||
yield exec.exec(`"${script}"`, ['-y', '--default-toolchain', 'none']);
|
||||
let cargo = path.join(process.env['HOME'] || '', '.cargo');
|
||||
return yield toolCache.cacheDir(cargo, 'rust', version);
|
||||
});
|
||||
}
|
||||
function rustupUrl() {
|
||||
if (WINDOWS) {
|
||||
return "https://win.rustup.rs";
|
||||
}
|
||||
else {
|
||||
return "https://sh.rustup.rs";
|
||||
}
|
||||
}
|
||||
function binRoot() {
|
||||
if (WINDOWS) {
|
||||
return path.join(process.env['USERPROFILE'] || '', '.cargo');
|
||||
}
|
||||
else {
|
||||
return path.join(process.env['HOME'] || '', '.cargo');
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as rustup from './rustup';
|
||||
import * as os from 'os';
|
||||
|
||||
@ -8,6 +9,8 @@ async function run() {
|
||||
|
||||
if(version) {
|
||||
await rustup.install(version);
|
||||
|
||||
exec.exec('rustup', ['default', version]);
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
@ -6,68 +6,32 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import {chmodSync} from 'fs';
|
||||
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = os.arch();
|
||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
||||
const WINDOWS: boolean = osPlat == 'win32';
|
||||
|
||||
export async function install(version: string) {
|
||||
let toolPath = toolCache.find('rust', version);
|
||||
if (os.platform() == 'darwin') {
|
||||
let toolPath = await acquireRust(version);
|
||||
|
||||
if (!toolPath) {
|
||||
toolPath = await acquireRust(version);
|
||||
core.debug('Rust toolchain is cached under ' + toolPath);
|
||||
}
|
||||
|
||||
toolPath = path.join(toolPath, 'bin');
|
||||
core.addPath(toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
}
|
||||
}
|
||||
|
||||
async function acquireRust(version: string): Promise<string> {
|
||||
let script: string;
|
||||
|
||||
try {
|
||||
script = await toolCache.downloadTool(rustupUrl());
|
||||
script = await toolCache.downloadTool("https://sh.rustup.rs");
|
||||
} catch (error) {
|
||||
core.debug(error);
|
||||
throw `Failed to download rustup: ${error}`;
|
||||
}
|
||||
|
||||
if(WINDOWS) {
|
||||
await io.cp(script, script + '.exe');
|
||||
script += '.exe';
|
||||
chmodSync(script, '777');
|
||||
await exec.exec(`"${script}"`, ['-y', '--default-toolchain', 'none']);
|
||||
|
||||
console.log(await io.which('rustup', true));
|
||||
let cargo = path.join(process.env['HOME'] || '', '.cargo');
|
||||
|
||||
await exec.exec(
|
||||
`"${script}"`,
|
||||
[
|
||||
'-y',
|
||||
'--default-toolchain',
|
||||
'none',
|
||||
]
|
||||
);
|
||||
} else {
|
||||
chmodSync(script, '777');
|
||||
|
||||
await exec.exec(`"${script}"`, ['-y', '--default-toolchain', version]);
|
||||
}
|
||||
|
||||
return await toolCache.cacheDir(binRoot(), 'rust', version);
|
||||
}
|
||||
|
||||
function rustupUrl(): string {
|
||||
if(WINDOWS) {
|
||||
return "https://win.rustup.rs"
|
||||
} else {
|
||||
return "https://sh.rustup.rs"
|
||||
}
|
||||
}
|
||||
|
||||
function binRoot(): string {
|
||||
if(WINDOWS) {
|
||||
return path.join(process.env['USERPROFILE'] || '', '.cargo');
|
||||
} else {
|
||||
return path.join(process.env['HOME'] || '', '.cargo');
|
||||
}
|
||||
return await toolCache.cacheDir(cargo, 'rust', version);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user