且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Java脚本执行bash脚本

更新时间:2023-01-31 20:12:12

这是一种可以通过JavaScript操作执行bash脚本的方法.脚本文件为index.js

This is how one can execute a bash script from a javascript action. Script-file is index.js

const core = require("@actions/core");
const exec = require("@actions/exec");
const github = require("@actions/github");

async function run() {
  try {
    // Set the src-path
    const src = __dirname + "/src";
    core.debug(`src: ${src}`);

    // Fetch the file path from input
    const filepath = core.getInput("file-path");
    core.debug(`input: ${filepath}`);

    // Execute bash script
    await exec.exec(`${src}/test`);

    // Get the JSON webhook payload for the event that triggered the workflow
    const payload = JSON.stringify(github.context.payload, undefined, 2);
    console.debug(`github event payload: ${payload}`);

  } catch (error) {
    core.setFailed(error.message);
  }
}

// noinspection JSIgnoredPromiseFromCall
run();