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

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