Merge pull request #18 from actions/result-encoding

Result encoding
This commit is contained in:
Jonathan Clem
2020-01-08 14:57:34 -05:00
committed by GitHub
4 changed files with 57 additions and 4 deletions
+16
View File
@@ -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!"
```
+3
View File
@@ -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`
+20 -3
View File
File diff suppressed because one or more lines are too long
+18 -1
View File
@@ -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) {