8000 Document how to use installed npm packages · mattukouta/github-script@a56d450 · GitHub
[go: up one dir, main page]

Skip to content

Commit a56d450

Browse files
Document how to use installed npm packages
1 parent 3d069b2 commit a56d450

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ in case you need to use a non-default token.
7171

7272
By 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.
200200
You can use the `github.graphql` object to run custom GraphQL queries against the GitHub API.
201201

202202
```yaml
203-
204203
jobs:
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,31 @@ external function.
268266
Additionally, you'll want to use the [checkout
269267
action](https://github.com/actions/checkout) to make sure your script file is
270268
available.
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 -g 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+
```

0 commit comments

Comments
 (0)
0