@@ -132,3 +132,19 @@ jobs:
|
||||
|
||||
This will print the full diff object in the screen; `result.data` will
|
||||
contain the actual diff text.
|
||||
|
||||
### Result encoding
|
||||
|
||||
By default, the JSON-encoded return value of the function is set as the "result" in the
|
||||
output of a github-script step. For some workflows, string encoding is preferred. This option can be set using the
|
||||
`result-encoding` input:
|
||||
|
||||
|
||||
```yaml
|
||||
- uses: actions/[email protected]
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
result-encoding: string
|
||||
script: |
|
||||
return "I will be string (not JSON) encoded!"
|
||||
```
|
||||
|
||||
@@ -19,6 +19,9 @@ inputs:
|
||||
default: actions/github-script
|
||||
previews:
|
||||
description: A comma-separated list of API previews to accept
|
||||
result-encoding:
|
||||
description: Either "string" or "json" (default "json")—how the result will be encoded
|
||||
default: json
|
||||
outputs:
|
||||
result:
|
||||
description: The return value of the script, stringified with `JSON.stringify`
|
||||
|
||||
Vendored
+20
-3
File diff suppressed because one or more lines are too long
+18
-1
@@ -18,7 +18,24 @@ async function main() {
|
||||
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))
|
||||
|
||||
let encoding = core.getInput('result-encoding')
|
||||
encoding = encoding ? encoding : 'json'
|
||||
|
||||
let output
|
||||
|
||||
switch (encoding) {
|
||||
case 'json':
|
||||
output = JSON.stringify(result)
|
||||
break
|
||||
case 'string':
|
||||
output = String(result)
|
||||
break
|
||||
default:
|
||||
throw new Error('"result-encoding" must be either "string" or "json"')
|
||||
}
|
||||
|
||||
core.setOutput('result', output)
|
||||
}
|
||||
|
||||
function handleError(err) {
|
||||
|
||||
Reference in New Issue
Block a user