From b0ee7adf365b9dba864347b32fcb02e0b4e52fd7 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Mon, 2 Jun 2025 22:00:07 -0400 Subject: [PATCH] Update README to use `v8` and `octokit` by default --- README.md | 70 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 6c8dceb..e2a93d1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ uses the GitHub API and the workflow run context. To use this action, provide an input named `script` that contains the body of an asynchronous JavaScript function call. The following arguments will be provided: -- `github`/`octokit` A pre-authenticated +- `github`/ `octokit` A pre-authenticated [octokit/rest.js](https://octokit.github.io/rest.js) client with pagination plugins - `context` An object containing partial [context of the workflow run](./src/context.ts) - `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package @@ -75,7 +75,7 @@ and potential `SyntaxError`s when the expression is not valid JavaScript code (p To pass inputs, set `env` vars on the action step and reference them in your script with `process.env`: ```yaml -- uses: actions/github-script@v7 +- uses: actions/github-script@v8 env: TITLE: ${{ github.event.pull_request.title }} with: @@ -94,7 +94,7 @@ The return value of the script will be in the step's outputs under the "result" key. ```yaml -- uses: actions/github-script@v7 +- uses: actions/github-script@v8 id: set-result with: script: return "Hello!" @@ -113,7 +113,7 @@ output of a github-script step. For some workflows, string encoding is preferred `result-encoding` input: ```yaml -- uses: actions/github-script@v7 +- uses: actions/github-script@v8 id: my-script with: result-encoding: string @@ -125,32 +125,32 @@ output of a github-script step. For some workflows, string encoding is preferred By default, requests made with the `github` instance will not be retried. You can configure this with the `retries` option: ```yaml -- uses: actions/github-script@v7 +- uses: actions/github-script@v8 id: my-script with: result-encoding: string retries: 3 script: | - github.rest.issues.get({ + octokit.rest.issues.get({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, }) ``` -In this example, request failures from `github.rest.issues.get()` will be retried up to 3 times. +In this example, request failures from `octokit.rest.issues.get()` will be retried up to 3 times. You can also configure which status codes should be exempt from retries via the `retry-exempt-status-codes` option: ```yaml -- uses: actions/github-script@v7 +- uses: actions/github-script@v8 id: my-script with: result-encoding: string retries: 3 retry-exempt-status-codes: 400,401 script: | - github.rest.issues.get({ + octokit.rest.issues.get({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -172,7 +172,7 @@ By default, github-script will use the token provided to your workflow. ```yaml - name: View context attributes - uses: actions/github-script@v7 + uses: actions/github-script@v8 with: script: console.log(context) ``` @@ -188,10 +188,10 @@ jobs: comment: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | - github.rest.issues.createComment({ + octokit.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -210,10 +210,10 @@ jobs: apply-label: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | - github.rest.issues.addLabels({ + octokit.rest.issues.addLabels({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -232,18 +232,18 @@ jobs: welcome: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | // Get a list of all issues created by the PR opener // See: https://octokit.github.io/rest.js/#pagination const creator = context.payload.sender.login - const opts = github.rest.issues.listForRepo.endpoint.merge({ + const opts = octokit.rest.issues.listForRepo.endpoint.merge({ ...context.issue, creator, state: 'all' }) - const issues = await github.paginate(opts) + const issues = await octokit.paginate(opts) for (const issue of issues) { if (issue.number === context.issue.number) { @@ -255,7 +255,7 @@ jobs: } } - await github.rest.issues.createComment({ + await octokit.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -277,11 +277,11 @@ jobs: diff: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const diff_url = context.payload.pull_request.diff_url - const result = await github.request(diff_url) + const result = await octokit.request(diff_url) console.log(result) ``` @@ -301,7 +301,7 @@ jobs: list-issues: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const query = `query($owner:String!, $name:String!, $label:String!) { @@ -318,7 +318,7 @@ jobs: name: context.repo.repo, label: 'wontfix' } - const result = await github.graphql(query, variables) + const result = await octokit.graphql(query, variables) console.log(result) ``` @@ -335,17 +335,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const script = require('./path/to/script.js') - console.log(script({github, context})) + console.log(script({octokit, context})) ``` And then export a function from your module: ```javascript -module.exports = ({github, context}) => { +module.exports = ({octokit, context}) => { return context.payload.client_payload.value } ``` @@ -373,21 +373,21 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 env: SHA: '${{env.parentSHA}}' with: script: | const script = require('./path/to/script.js') - await script({github, context, core}) + await script({octokit, context, core}) ``` And then export an async function from your module: ```javascript -module.exports = async ({github, context, core}) => { +module.exports = async ({octokit, context, core}) => { const {SHA} = process.env - const commit = await github.rest.repos.getCommit({ + const commit = await octokit.rest.repos.getCommit({ owner: context.repo.owner, repo: context.repo.repo, ref: `${SHA}` @@ -417,7 +417,7 @@ jobs: - run: npm ci # or one-off: - run: npm install execa - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const execa = require('execa') @@ -447,7 +447,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const { default: printStuff } = await import('${{ github.workspace }}/src/print-stuff.js') @@ -491,11 +491,11 @@ jobs: apply-label: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: github-token: ${{ secrets.MY_PAT }} script: | - github.rest.issues.addLabels({ + octokit.rest.issues.addLabels({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -515,7 +515,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const exitCode = await exec.exec('echo', ['hello']) @@ -533,7 +533,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/github-script@v7 + - uses: actions/github-script@v8 with: script: | const {