mirror of
https://github.com/actions/github-script.git
synced 2025-12-20 14:22:28 +00:00
docs: use GITHUB_WORKSPACE environment variable
- update example for using `GITHUB_WORKSPACE` environment variable to keep things simple, and use less steps - include `github` object as a parameter to the sample script to better illustrate usage
This commit is contained in:
@@ -198,17 +198,16 @@ jobs:
|
|||||||
- uses: actions/github-script@v2
|
- uses: actions/github-script@v2
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const path = require('path')
|
const script = require(`${process.env.GITHUB_WORKSPACE}/.path/to/script.js`)
|
||||||
const scriptPath = path.resolve('./path/to/script.js')
|
console.log(script(github, context))
|
||||||
console.log(require(scriptPath)({context}))
|
|
||||||
```
|
```
|
||||||
|
|
||||||
*Note that the script path given to `require()` must be an absolute path in this case, hence the call to `path.resolve()`.*
|
*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)*
|
||||||
|
|
||||||
And then export a function from your module:
|
And then export a function from your module:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
module.exports = ({context}) => {
|
module.exports = (github, context) => {
|
||||||
return context.payload.client_payload.value
|
return context.payload.client_payload.value
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user