mirror of
https://github.com/actions/github-script.git
synced 2026-02-08 12:07:26 +00:00
Support using a file
This commit is contained in:
parent
648bc46b8a
commit
2dbe5367a7
3 changed files with 1754 additions and 1581 deletions
|
|
@ -7,7 +7,8 @@ branding:
|
||||||
inputs:
|
inputs:
|
||||||
script:
|
script:
|
||||||
description: The script to run
|
description: The script to run
|
||||||
required: true
|
file:
|
||||||
|
description: The javascript file to run
|
||||||
github-token:
|
github-token:
|
||||||
description: The GitHub token used to create an authenticated client
|
description: The GitHub token used to create an authenticated client
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
|
|
||||||
3306
dist/index.js
vendored
3306
dist/index.js
vendored
File diff suppressed because it is too large
Load diff
22
src/main.ts
22
src/main.ts
|
|
@ -1,6 +1,7 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {context, GitHub} from '@actions/github'
|
import {context, GitHub} from '@actions/github'
|
||||||
import {callAsyncFunction} from './async-function'
|
import {callAsyncFunction} from './async-function'
|
||||||
|
import { existsSync, readFileSync } from 'fs'
|
||||||
|
|
||||||
process.on('unhandledRejection', handleError)
|
process.on('unhandledRejection', handleError)
|
||||||
main().catch(handleError)
|
main().catch(handleError)
|
||||||
|
|
@ -15,7 +16,7 @@ async function main() {
|
||||||
if (userAgent != null) opts.userAgent = userAgent
|
if (userAgent != null) opts.userAgent = userAgent
|
||||||
if (previews != null) opts.previews = previews.split(',')
|
if (previews != null) opts.previews = previews.split(',')
|
||||||
const github = new GitHub(token, opts)
|
const github = new GitHub(token, opts)
|
||||||
const script = core.getInput('script', {required: true})
|
const script = loadScript()
|
||||||
|
|
||||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilatin errors.
|
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilatin errors.
|
||||||
const result = await callAsyncFunction(
|
const result = await callAsyncFunction(
|
||||||
|
|
@ -42,6 +43,25 @@ async function main() {
|
||||||
core.setOutput('result', output)
|
core.setOutput('result', output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadScript(){
|
||||||
|
const file = core.getInput('file')
|
||||||
|
let script = core.getInput('script')
|
||||||
|
|
||||||
|
if(!script && !file){
|
||||||
|
throw new Error('either "script" or "file" must be a "string')
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file){
|
||||||
|
if(!existsSync(file)){
|
||||||
|
throw new Error('file can\'t be found: ' + file)
|
||||||
|
}
|
||||||
|
|
||||||
|
script = readFileSync(file, 'utf-8')
|
||||||
|
}
|
||||||
|
|
||||||
|
return script
|
||||||
|
}
|
||||||
|
|
||||||
function handleError(err: any) {
|
function handleError(err: any) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue