File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,41 @@ jobs:
144144This will print the full diff object in the screen; `result.data` will
145145contain 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/[email protected] 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
149184By default, the JSON-encoded return value of the function is set as the "result" in the
You can’t perform that action at this time.
0 commit comments