mirror of
https://github.com/actions/github-script.git
synced 2026-04-08 07:00:05 +00:00
Run from a script or a file
This commit is contained in:
parent
64af053a78
commit
35288c3418
3 changed files with 61 additions and 4 deletions
26
dist/index.js
vendored
26
dist/index.js
vendored
|
|
@ -9273,6 +9273,12 @@ var core = __webpack_require__(470);
|
|||
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
|
||||
var lib_github = __webpack_require__(469);
|
||||
|
||||
// EXTERNAL MODULE: external "fs"
|
||||
var external_fs_ = __webpack_require__(747);
|
||||
|
||||
// EXTERNAL MODULE: external "path"
|
||||
var external_path_ = __webpack_require__(622);
|
||||
|
||||
// CONCATENATED MODULE: ./src/async-function.ts
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => null).constructor;
|
||||
function callAsyncFunction(args, source) {
|
||||
|
|
@ -9284,6 +9290,8 @@ function callAsyncFunction(args, source) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
process.on('unhandledRejection', handleError);
|
||||
main().catch(handleError);
|
||||
async function main() {
|
||||
|
|
@ -9299,7 +9307,7 @@ async function main() {
|
|||
if (previews != null)
|
||||
opts.previews = previews.split(',');
|
||||
const github = new lib_github.GitHub(token, opts);
|
||||
const script = Object(core.getInput)('script', { required: true });
|
||||
const script = getScript();
|
||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||
const result = await callAsyncFunction({ require: __webpack_require__(875), github, context: lib_github.context, core: core }, script);
|
||||
let encoding = Object(core.getInput)('result-encoding');
|
||||
|
|
@ -9317,6 +9325,22 @@ async function main() {
|
|||
}
|
||||
Object(core.setOutput)('result', output);
|
||||
}
|
||||
function getScript() {
|
||||
const script = Object(core.getInput)('script');
|
||||
const filePath = Object(core.getInput)('file');
|
||||
if (script && filePath) {
|
||||
Object(core.setFailed)('A script and a file were provided; only one is allowed');
|
||||
process.exit(1);
|
||||
}
|
||||
if (!(script || filePath)) {
|
||||
Object(core.setFailed)('Neither a script nor a file were provided');
|
||||
process.exit(1);
|
||||
}
|
||||
if (filePath) {
|
||||
return Object(external_fs_.readFileSync)(Object(external_path_.resolve)(filePath)).toString('utf-8');
|
||||
}
|
||||
return script;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function handleError(err) {
|
||||
console.error(err);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue