mirror of
https://github.com/actions/github-script.git
synced 2025-12-09 00:26:20 +00:00
feature: build source file with ncc
This commit is contained in:
27
src/main.js
Normal file
27
src/main.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const core = require('@actions/core')
|
||||
const {GitHub, context} = require('@actions/github')
|
||||
|
||||
process.on('unhandledRejection', handleError)
|
||||
main().catch(handleError)
|
||||
|
||||
async function main() {
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
|
||||
const token = core.getInput('github-token', {required: true})
|
||||
const debug = core.getInput('debug')
|
||||
const userAgent = core.getInput('user-agent')
|
||||
const previews = core.getInput('previews')
|
||||
const opts = {}
|
||||
if (debug === 'true') opts.log = console
|
||||
if (userAgent != null) opts.userAgent = userAgent
|
||||
if (previews != null) opts.previews = previews.split(',')
|
||||
const client = new GitHub(token, opts)
|
||||
const script = core.getInput('script', {required: true})
|
||||
const fn = new AsyncFunction('require', 'github', 'context', script)
|
||||
const result = await fn(require, client, context)
|
||||
core.setOutput('result', JSON.stringify(result))
|
||||
}
|
||||
|
||||
function handleError(err) {
|
||||
console.error(err)
|
||||
core.setFailed(err.message)
|
||||
}
|
||||
Reference in New Issue
Block a user