dunamai-action/src/index.ts

38 lines
993 B
TypeScript
Raw Normal View History

2020-07-10 22:50:28 -04:00
import * as core from "@actions/core";
import { execSync } from "child_process";
2020-07-10 20:43:29 -04:00
2020-07-10 20:59:22 -04:00
function runCommand(command: string): Buffer {
2020-07-10 20:43:29 -04:00
console.log(`Running command: ${command}`);
return execSync(command);
}
2020-07-10 22:50:28 -04:00
function main(): void {
2020-07-10 20:43:29 -04:00
const install = core.getInput("install");
const envVar = core.getInput("env-var");
const command = core.getInput("command");
const args = core.getInput("args");
2020-07-10 20:59:22 -04:00
if (install === "none") {
2020-07-10 20:43:29 -04:00
// No install.
2020-07-10 20:59:22 -04:00
} else if (install === "latest") {
2020-07-10 20:43:29 -04:00
runCommand("pip install dunamai");
} else {
2020-07-10 20:59:22 -04:00
runCommand(`pip install dunamai==${install}`);
2020-07-10 20:43:29 -04:00
}
const version = runCommand(`${command} ${args}`).toString();
core.setOutput("version", version);
console.log(`Dynamic version: ${version}`);
if (envVar !== "") {
console.log(`Setting environment variable: ${envVar}`);
core.exportVariable(envVar, version);
}
}
try {
main();
} catch (error) {
core.setFailed(error.message);
}