cargo/src/main.ts
2019-10-22 14:35:28 +03:00

44 lines
1.1 KiB
TypeScript

const path = require('path');
import * as core from '@actions/core';
import * as input from './input';
import {Cargo, Cross} from '@actions-rs/core';
export async function run(actionInput: input.Input): Promise<void> {
let program;
if (actionInput.useCross) {
program = await Cross.getOrInstall();
} else {
program = await Cargo.get();
}
let args: string[] = [];
if (actionInput.toolchain) {
args.push(`+${actionInput.toolchain}`);
}
args.push(actionInput.command);
args = args.concat(actionInput.args);
await program.call(args);
}
async function main(): Promise<void> {
const actionInput = input.get();
const matchersPath = path.join(__dirname, '.matchers');
console.log(`::add-matcher::${path.join(matchersPath, 'rust.json')}`);
// Enabling `rustfmt` problem matcher only if `cargo fmt` is called
if (actionInput.command == 'fmt') {
console.log(`::add-matcher::${path.join(matchersPath, 'rustfmt.json')}`);
}
try {
await run(actionInput);
} catch (error) {
core.setFailed(error.message);
}
}
main();