FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Document how to use npm packages and env input by nihalgonsalves · Pull Request #126 · actions/github-script · GitHub

Document how to use npm packages and env input - #126

Merged
joshmgross merged 3 commits into
actions:mainfrom
nihalgonsalves:ng/input
Mar 29, 2021
Merged

Document how to use npm packages and env input#126
joshmgross merged 3 commits into
actions:mainfrom
nihalgonsalves:ng/input

Conversation

nihalgonsalves commented Mar 29, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

ℹ️ 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.

nihalgonsalves requested a review from a team March 29, 2021 15:34
nihalgonsalves changed the title Add input params Add an input variable Mar 29, 2021

Copy link
Copy Markdown
Contributor

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:

  1. input is not descriptive name
  2. 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}`)

nihalgonsalves changed the title Add an input variable Document how to use npm packages and env input Mar 29, 2021

nihalgonsalves commented Mar 29, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

@joshmgross Thanks - not sure why I didn't think of that. It works perfectly. I updated my PR to simply update the README.

joshmgross left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Awesome, thanks for this!

Comment thread README.md Outdated

Copy link
Copy Markdown
Contributor Author

I updated the npm command example to remove the -g flag.

Thanks for the quick review! :)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL