GeezerVison is showing github.com — Document how to use npm packages and env input by nihalgonsalves · Pull Request #126 · actions/github-script
Conversation
ℹ️ Updated to document env and process.env as inputs.
We've been using actions/github-script to glue together different build tools. We've had cases where we want to passthrough outputs of other scripts to this action –
-
One way would be to just use an input value:
- uses: actions/github-script@v3
with:
foo: 'bar'
script: console.log(core.getInput('foo'))
which works, but displays this warning:
Warning: Unexpected input(s) 'foo', valid inputs are ['script', 'github-token', 'debug', 'user-agent', 'previews', 'result-encoding']
-
Another way would be to inline the value:
- uses: actions/github-script@v3
with:
script: console.log('${{ 'foo' }}')
but this can cause issues depending on what the value of the string is, and requires you to be aware of how your string will interact with the program:
- uses: actions/github-script@v3
with:
script: console.log('${{ 'Single quotes can kill: '' a script' }}')
# SyntaxError: missing ) after argument list
So this PR introduces a simple input variable that is exposed directly to the function:
- uses: actions/github-script@v3
with:
input: hello world
script: console.log(input)
It can be combined with JSON.parse(input) in the script to pass through stringified JSON (from other jobs or CLI tools, for example).
I also made two other changes
- Changed the PR comment workflow to check whether the base and head repos are the same, so that changes can be tested more easily on forks (for example, checking my changes here: nihalgonsalves/github-script#1). It still won't comment on PRs across forks (like this one).
- In addition to the docs for this input variable, I also added a README section documenting how installed packages can be used.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Would step environment variables work here and avoid the quotes issue?
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsenv
A couple concerns with this approach:
input is not descriptive name
- It only supports a single
input.
If environment variables support your case, I'd prefer we document how to use those as inputs.
For example:
- uses: actions/github-script@v3
env:
FIRST_NAME: Mona
LAST_NAME: Octocat
with:
script: console.log(`Hello ${process.env.FIRST_NAME} ${process.env.LAST_NAME}`)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@joshmgross Thanks - not sure why I didn't think of that. It works perfectly. I updated my PR to simply update the README.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for this!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
I updated the npm command example to remove the -g flag.
Thanks for the quick review! :)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|