mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 16:16:21 +00:00
Remove caveat about node_modules
This commit is contained in:
29
README.md
29
README.md
@@ -18,18 +18,12 @@ arguments will be provided:
|
|||||||
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
|
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
|
||||||
- `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package
|
- `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package
|
||||||
- `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package
|
- `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package
|
||||||
- `require` Is available, with some caveats:
|
- `require` A proxy wrapper around the normal Node.js `require` to enable
|
||||||
- The location of the module that runs this action is where the Actions
|
requiring relative paths (relative to the current working directory) and
|
||||||
runner downloads the github-script action to, so the `require` passed to
|
requiring npm packages installed in the current working directory. If for
|
||||||
your script is actually a proxy that intercepts calls to require relative
|
some reason you need the non-wrapped `require`, there is an escape hatch
|
||||||
paths and transforms them into an absolute path in the working directory,
|
available: `__original_require__` is the original value of `require` without
|
||||||
instead.
|
our wrapping applied.
|
||||||
- If you want to require an npm module in your working directory, you still
|
|
||||||
need to specify the relative path, including `node_modules`, such as
|
|
||||||
`./node_modules/lodash`.
|
|
||||||
- If for some reason you need the non-wrapped `require`, there is an escape
|
|
||||||
hatch available: `__original_require__` is the original value of `require`
|
|
||||||
without our wrapping applied.
|
|
||||||
|
|
||||||
Since the `script` is just a function body, these values will already be
|
Since the `script` is just a function body, these values will already be
|
||||||
defined, so you don't have to (see examples below).
|
defined, so you don't have to (see examples below).
|
||||||
@@ -255,7 +249,7 @@ jobs:
|
|||||||
- uses: actions/github-script@v3
|
- uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const script = require(`./path/to/script.js`)
|
const script = require('./path/to/script.js')
|
||||||
console.log(script({github, context}))
|
console.log(script({github, context}))
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -295,7 +289,7 @@ jobs:
|
|||||||
SHA: '${{env.parentSHA}}'
|
SHA: '${{env.parentSHA}}'
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const script = require(`./path/to/script.js`)
|
const script = require('./path/to/script.js')
|
||||||
await script({github, context, core})
|
await script({github, context, core})
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -334,18 +328,13 @@ jobs:
|
|||||||
- uses: actions/github-script@v3
|
- uses: actions/github-script@v3
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const execa = require(`./node_modules/execa`)
|
const execa = require('execa')
|
||||||
|
|
||||||
const { stdout } = await execa('echo', ['hello', 'world'])
|
const { stdout } = await execa('echo', ['hello', 'world'])
|
||||||
|
|
||||||
console.log(stdout)
|
console.log(stdout)
|
||||||
```
|
```
|
||||||
|
|
||||||
_(Note that at this time, one still has to specify `node_modules` in the
|
|
||||||
require path for modules in the working directory of the step that is
|
|
||||||
running. Hopefully we will have a solution for this in the future, but not
|
|
||||||
quite, yet.)_
|
|
||||||
|
|
||||||
### Use env as input
|
### Use env as input
|
||||||
|
|
||||||
You can set env vars to use them in your script:
|
You can set env vars to use them in your script:
|
||||||
|
|||||||
Reference in New Issue
Block a user