From a56d4504dea86806b93dfdcf4e1b5dc08afd9883 Mon Sep 17 00:00:00 2001 From: Nihal Gonsalves Date: Tue, 30 Mar 2021 02:19:38 +0530 Subject: [PATCH 1/3] Document how to use installed npm packages --- README.md | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b58070c..29b7f77 100644 --- a/README.md +++ b/README.md @@ -71,14 +71,14 @@ in case you need to use a non-default token. By default, github-script will use the token provided to your workflow. -### Print the available attributes of context: +### Print the available attributes of context ```yaml - name: View context attributes uses: actions/github-script@v3 with: script: console.log(context) -``` +``` ### Comment on an issue @@ -200,7 +200,6 @@ contain the actual diff text. You can use the `github.graphql` object to run custom GraphQL queries against the GitHub API. ```yaml - jobs: list-issues: runs-on: ubuntu-latest @@ -225,7 +224,6 @@ jobs: } const result = await github.graphql(query, variables) console.log(result) - ``` ### Run a separate file @@ -268,3 +266,31 @@ external function. Additionally, you'll want to use the [checkout action](https://github.com/actions/checkout) to make sure your script file is available. + +### Use npm packages + +Like importing your own files above, you can also use installed modules: + +```yaml +on: push + +jobs: + echo-input: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 14 + - run: npm ci + # or one-off: + - run: npm install -g execa + - uses: actions/github-script@v3 + with: + script: | + const execa = require(`${process.env.GITHUB_WORKSPACE}/node_modules/execa`) + + const { stdout } = await execa('echo', ['hello', 'world']) + + console.log(stdout) +``` From 934655b9e0588f55f7f2f1a2c4c5037250f6816b Mon Sep 17 00:00:00 2001 From: Nihal Gonsalves Date: Tue, 30 Mar 2021 02:23:20 +0530 Subject: [PATCH 2/3] Document how to use `env:` as input --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 29b7f77..a80525f 100644 --- a/README.md +++ b/README.md @@ -294,3 +294,25 @@ jobs: console.log(stdout) ``` + +### Use env as input + +You can set env vars to use them in your script: + +```yaml +on: push + +jobs: + echo-input: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v3 + env: + FIRST_NAME: Mona + LAST_NAME: Octocat + with: + script: | + const { FIRST_NAME, LAST_NAME } = process.env + + console.log(`Hello ${FIRST_NAME} ${LAST_NAME}`) +``` From 01dfe2e0c1c727542efd65f9d45b780304a62dd7 Mon Sep 17 00:00:00 2001 From: Nihal Gonsalves Date: Tue, 30 Mar 2021 02:48:37 +0530 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a80525f..9a2c395 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,7 @@ jobs: node-version: 14 - run: npm ci # or one-off: - - run: npm install -g execa + - run: npm install execa - uses: actions/github-script@v3 with: script: |