GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Document how to use npm packages and env input by nihalgonsalves · Pull Request #126 · actions/github-script

Conversation

@nihalgonsalves

@nihalgonsalves nihalgonsalves commented Mar 29, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

joshmgross commented 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}`)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nihalgonsalves added 2 commits March 30, 2021 02:20
@nihalgonsalves
Document how to use installed npm packages
a56d450
@nihalgonsalves
Document how to use env: as input
934655b
@nihalgonsalves nihalgonsalves changed the title Add an input variable Document how to use npm packages and env input Mar 29, 2021
@nihalgonsalves

nihalgonsalves commented Mar 29, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

joshmgross
joshmgross approved these changes Mar 29, 2021
View reviewed changes

@joshmgross joshmgross left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread README.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@nihalgonsalves
Update README.md
01dfe2e
@nihalgonsalves

nihalgonsalves commented Mar 29, 2021

Copy link
Copy Markdown
Contributor Author

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

Thanks for the quick review! :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

joshmgross
joshmgross approved these changes Mar 29, 2021
View reviewed changes
joshmgross
joshmgross approved these changes Mar 29, 2021
View reviewed changes
@joshmgross
joshmgross merged commit 8685086 into actions:main Mar 29, 2021
@joshmgross joshmgross mentioned this pull request May 13, 2025
Clearly document passing inputs to the script #603
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2026
Epic 0: Firebase auth, Cloud Run deploy, CI/CD automation combsmith/broodly#51
Draft
2 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@joshmgross joshmgross joshmgross approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@nihalgonsalves @joshmgross
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.