feat: expose `getOctokit` in script context for multi-token workflows by salmanmkc · Pull Request #700 · actions/github-script

Summary

Expose getOctokit from @actions/github in the script execution context, enabling workflows that need to interact with multiple tokens without relying on require.

Motivation

It's common for workflows to juggle multiple authentication tokens — for example, a GITHUB_TOKEN for the current repo and a separate PAT or GitHub App installation token for cross-repo operations. Currently, the only way to create additional Octokit clients in github-script is via require('@actions/github'), which is an undocumented implementation detail.

This change makes getOctokit a first-class part of the script context alongside github, context, core, etc.

Changes

  • src/main.ts — Added getOctokit to the object passed to callAsyncFunction
  • src/async-function.ts — Added getOctokit to the AsyncFunctionArguments type definition (with proper signature including OctokitOptions and OctokitPlugin support)

Usage

- uses: actions/github-script@v8
  env:
    APP_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
  with:
    script: |
      // Default client using github-token input
      const { data: issue } = await github.rest.issues.get({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: context.issue.number
      })

      // Second client using a different token
      const appOctokit = getOctokit(process.env.APP_TOKEN)
      await appOctokit.rest.repos.createDispatchEvent({
        owner: 'my-org',
        repo: 'another-repo',
        event_type: 'trigger-deploy',
        client_payload: { issue: issue.number }
      })

Checklist

  • getOctokit added to script execution context
  • TypeScript type (AsyncFunctionArguments) updated
  • README updated to document getOctokit
  • dist/ rebuilt
  • Tests for multi-token usage