8000 Merge pull request #126 from nihalgonsalves/ng/input · joelabrahamsson/github-script@8685086 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit 8685086

Browse files
authored
Merge pull request actions#126 from nihalgonsalves/ng/input
Document how to use npm packages and env input
2 parents 3d069b2 + 01dfe2e commit 8685086

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

README.md

Lines changed: 52 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,53 @@ 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 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

Comments
 (0)
0