rs-cargo/src/main.ts

49 lines
1 KiB
TypeScript
Raw Normal View History

2019-09-12 23:48:44 +03:00
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as input from './input';
async function getCross(): Promise<string> {
try {
return await io.which('cross', true);
} catch (error) {
core.warning('Unable to find cross, installing it now');
}
try {
await exec.exec('cargo', ['install', 'cross']);
} catch (error) {
core.setFailed(error.message);
}
return 'cross';
}
async function run() {
const actionInput = input.parse();
let program;
if (actionInput.useCross) {
program = await getCross();
} else {
program = 'cargo';
}
let args: string[] = [actionInput.command];
2019-09-12 23:48:44 +03:00
if (actionInput.toolchain) {
args.push(`+${actionInput.toolchain}`);
}
args = args.concat(actionInput.args);
console.log(program, args);
2019-09-12 23:48:44 +03:00
try {
await exec.exec(program, args);
} catch (error) {
core.setFailed(error.message);
}
}
run();