@@ -18,6 +18,18 @@ arguments will be provided:
18
18
- ` core ` A reference to the [ @actions/core ] ( https://github.com/actions/toolkit/tree/main/packages/core ) package
19
19
- ` glob ` A reference to the [ @actions/glob ] ( https://github.com/actions/toolkit/tree/main/packages/glob ) package
20
20
- ` io ` A reference to the [ @actions/io ] ( https://github.com/actions/toolkit/tree/main/packages/io ) package
21
+ - ` require ` Is available, with some caveats:
22
+ - The location of the module that runs this action is where the Actions
23
+ runner downloads the github-script action to, so the ` require ` passed to
24
+ your script is actually a proxy that intercepts calls to require relative
25
+ paths and transforms them into an absolute path in the working directory,
26
+ instead.
27
+ - If you want to require an npm module in your working directory, you still
28
+ need to specify the relative path, including ` node_modules ` , such as
29
+ ` ./node_modules/lodash ` .
30
+ - If for some reason you need the non-wrapped ` require ` , there is an escape
31
+ hatch available: ` __original_require__ ` is the original value of ` require `
32
+ without our wrapping applied.
21
33
22
34
Since the ` script ` is just a function body, these values will already be
23
35
defined, so you don't have to (see examples below).
@@ -243,12 +255,10 @@ jobs:
243
255
- uses : actions/github-script@v3
244
256
with :
245
257
script : |
246
- const script = require(`${process.env.GITHUB_WORKSPACE} /path/to/script.js`)
258
+ const script = require(`. /path/to/script.js`)
247
259
console.log(script({github, context}))
248
260
` ` `
249
261
250
- _Note that the script path given to ` require()` must be an **absolute path** in this case, hence using [`GITHUB_WORKSPACE`](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables)._
251
-
252
262
And then export a function from your module:
253
263
254
264
` ` ` javascript
@@ -282,24 +292,24 @@ jobs:
282
292
- uses : actions/checkout@v2
283
293
- uses : actions/github-script@v3
284
294
env :
285
- SHA: " ${{env.parentSHA}}"
295
+ SHA : ' ${{env.parentSHA}}'
286
296
with :
287
297
script : |
288
- const script = require(` ${process.env.GITHUB_WORKSPACE} /path/to/script.js`)
298
+ const script = require(`. /path/to/script.js`)
289
299
await script({github, context, core})
290
300
` ` `
291
301
292
302
And then export an async function from your module:
293
303
294
304
` ` ` javascript
295
- module .exports = async ({ github, context, core }) => {
296
- const { SHA } = process .env
297
- const commit = await github .repos .getCommit ({
298
- owner: context .repo .owner ,
299
- repo: context .repo .repo ,
300
- ref: ` ${ SHA } `
301
- })
302
- core .exportVariable (' author' , commit .data .commit .author .email );
305
+ module.exports = async ({github, context, core}) => {
306
+ const {SHA} = process.env
307
+ const commit = await github.repos.getCommit({
308
+ owner : context.repo.owner,
309
+ repo : context.repo.repo,
310
+ ref : ` ${SHA}`
311
+ })
312
+ core.exportVariable('author', commit.data.commit.author.email)
303
313
}
304
314
```
305
315
@@ -324,13 +334,18 @@ jobs:
324
334
- uses : actions/github-script@v3
325
335
with :
326
336
script : |
327
- const execa = require(`${process.env.GITHUB_WORKSPACE} /node_modules/execa`)
337
+ const execa = require(`. /node_modules/execa`)
328
338
329
339
const { stdout } = await execa('echo', ['hello', 'world'])
330
340
331
341
console.log(stdout)
332
342
` ` `
333
343
344
+ _(Note that at this time, one still has to specify ` node_modules` in the
345
+ require path for modules in the working directory of the step that is
346
+ running. Hopefully we will have a solution for this in the future, but not
347
+ quite, yet.)_
348
+
334
349
# ## Use env as input
335
350
336
351
You can set env vars to use them in your script :
0 commit comments