@@ -71,14 +71,14 @@ in case you need to use a non-default token.
7171
7272By default, github-script will use the token provided to your workflow.
7373
74- # ## Print the available attributes of context:
74+ # ## Print the available attributes of context
7575
7676` ` ` yaml
7777- name: View context attributes
7878 uses: actions/github-script@v3
7979 with:
8080 script: console.log(context)
81- ` ` `
81+ ` ` `
8282
8383# ## Comment on an issue
8484
@@ -200,7 +200,6 @@ contain the actual diff text.
200200You can use the `github.graphql` object to run custom GraphQL queries against the GitHub API.
201201
202202` ` ` yaml
203-
204203jobs:
205204 list-issues:
206205 runs-on: ubuntu-latest
@@ -225,7 +224,6 @@ jobs:
225224 }
226225 const result = await github.graphql(query, variables)
227226 console.log(result)
228-
229227```
230228
231229### Run a separate file
@@ -268,3 +266,53 @@ external function.
268266Additionally, you'll want to use the [checkout
269267action](https://github.com/actions/checkout) to make sure your script file is
270268available.
269+
270+ # ## Use npm packages
271+
272+ Like importing your own files above, you can also use installed modules :
273+
274+ ` ` ` yaml
275+ on: push
276+
277+ jobs:
278+ echo-input:
279+ runs-on: ubuntu-latest
280+ steps:
281+ - uses: actions/checkout@v2
282+ - uses: actions/setup-node@v2
283+ with:
284+ node-version: 14
285+ - run: npm ci
286+ # or one-off:
287+ - run: npm install execa
288+ - uses: actions/github-script@v3
289+ with:
290+ script: |
291+ const execa = require(` ${process.env.GITHUB_WORKSPACE}/node_modules/execa`)
292+
293+ const { stdout } = await execa('echo', ['hello', 'world'])
294+
295+ console.log(stdout)
296+ ```
297+
298+ ### Use env as input
299+
300+ You can set env vars to use them in your script:
301+
302+ ``` yaml
303+ on : push
304+
305+ jobs :
306+ echo-input :
307+ runs-on : ubuntu-latest
308+ steps :
309+ - uses : actions/github-script@v3
310+ env :
311+ FIRST_NAME : Mona
312+ LAST_NAME : Octocat
313+ with :
314+ script : |
315+ const { FIRST_NAME, LAST_NAME } = process.env
316+
317+ console.log(`Hello ${FIRST_NAME} ${LAST_NAME}`)
318+ ` ` `
0 commit comments