Actions/github-script

Hi there!
I’m trying to run-a-separate-file for GitHub - actions/github-script: Write workflows scripting the GitHub API in JavaScript
And there’s a notice:

Note that because you can’t require things like the GitHub context or Actions Toolkit libraries, you’ll want to pass them as arguments to your external function.

How exactly would I do that?
I’m trying to use {{ secret.NAME }} and {{ steps.STEPNAME.outputs.stdout }} context inside my script
And actions throwing a SyntaxError: Unexcpected token '.'

What should I pass with action itself and how exactly I should change my js code?

also, can I pass const script = require(${process.env.GITHUB_WORKSPACE}/path/to/script.js) an url to my js file? like const script = require(raw.github.com/sdkhfksjdhf/myfile.js) or something ?

Thanks!

:wave: Hey @alexpotapov87,

You’ll want to pass all of that info into the function you require from your script, including any libraries.

So for example, if your script referenced a step output and a secret, your script might look like:

module.exports = ({secret, stepOutput}) => {
  console.log("Step output" + stepOutput);
}

And your step would then pass in those two values:

    steps:
      - uses: actions/checkout@v2
      - uses: actions/github-script@v4
        with:
          script: |
            const script = require('./path/to/script.js')
            const secret = "${{ secret.NAME }}"
            const stepOutput = "${{ steps.STEPNAME.outputs.stdout }}"
            console.log(script({secret, stepOutput}))

I’m not sure about the specific semantics of requiring a URL, I think you’d need to fetch the file first and then require it