Skip to content

Commit 5541733

Browse files
committed
Add an example using ESM import
1 parent 41e1ab4 commit 5541733

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,31 @@ jobs:
338338
console.log(stdout)
339339
```
340340
341+
### Use ESM `import`
342+
343+
To import an ESM file, you'll need to reference your script by an absolute path and ensure you have a `package.json` file with `"type": "module"` specified.
344+
345+
For a script in your repository `src/print-stuff.js`:
346+
```js
347+
export default function printStuff() { console.log('stuff') }
348+
```
349+
350+
```yaml
351+
on: push
352+
353+
jobs:
354+
print-stuff:
355+
runs-on: ubuntu-latest
356+
steps:
357+
- uses: actions/checkout@v2
358+
- uses: actions/github-script@v6
359+
with:
360+
script: |
361+
const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js')
362+
363+
await printStuff()
364+
```
365+
341366
### Use env as input
342367

343368
You can set env vars to use them in your script:

0 commit comments

Comments
 (0)