From a656f437f9d9b3320b64a31c2a35a3cacf88ccb0 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Tue, 28 Jul 2020 21:54:19 -0400 Subject: [PATCH 1/2] 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 --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8e08984ee..308a58c40 100644 --- a/README.md +++ b/README.md @@ -198,17 +198,16 @@ jobs: - uses: actions/github-script@v2 with: script: | - const path = require('path') - const scriptPath = path.resolve('./path/to/script.js') - console.log(require(scriptPath)({context})) + const script = require(`${process.env.GITHUB_WORKSPACE}/.path/to/script.js`) + console.log(script(github, 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: ```javascript -module.exports = ({context}) => { +module.exports = (github, context) => { return context.payload.client_payload.value } ``` From 07ecbc5ac00027e21bc0fd76525207d910fd035e Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 29 Jul 2020 11:49:45 -0400 Subject: [PATCH 2/2] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 308a58c40..a3197e0e6 100644 --- a/README.md +++ b/README.md @@ -198,11 +198,11 @@ jobs: - uses: actions/github-script@v2 with: script: | - const script = require(`${process.env.GITHUB_WORKSPACE}/.path/to/script.js`) - console.log(script(github, context)) + const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`) + console.log(script({github, context})) ``` -*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)* +*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).* And then export a function from your module: