Skip to content
This repository was archived by the owner on Dec 17, 2023. It is now read-only.

Commit 52110c5

Browse files
committed
Add a separate file example
1 parent f498913 commit 52110c5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,41 @@ jobs:
144144
This will print the full diff object in the screen; `result.data` will
145145
contain the actual diff text.
146146

147+
### Run a separate file
148+
149+
If you don't want to inline your entire script that you want to run, you can
150+
use a separate JavaScript file in your repository like so:
151+
152+
```yaml
153+
on: push
154+
155+
jobs:
156+
echo-input:
157+
runs-on: ubuntu-latest
158+
steps:
159+
- uses: @actions/github-script@0.9.0
160+
with:
161+
script: |
162+
const path = require('path')
163+
const scriptPath = path.resolve('./path/to/script.js')
164+
console.log(require(scriptPath)({context}))
165+
```
166+
167+
And then export a function from your script:
168+
169+
```javascript
170+
module.exports = ({context}) => {
171+
return context.payload.client_payload.value
172+
}
173+
```
174+
175+
You can also use async functions in this manner, as long as you `await` it in
176+
the inline script.
177+
178+
Note that because you can't `require` things like the GitHub context or
179+
Actions Toolkit libraries, you'll want to pass them as arguments to your
180+
external script.
181+
147182
### Result encoding
148183

149184
By default, the JSON-encoded return value of the function is set as the "result" in the

0 commit comments

Comments
 (0)