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— AddedgetOctokitto the object passed tocallAsyncFunctionsrc/async-function.ts— AddedgetOctokitto theAsyncFunctionArgumentstype definition (with proper signature includingOctokitOptionsandOctokitPluginsupport)
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
-
getOctokitadded to script execution context - TypeScript type (
AsyncFunctionArguments) updated - README updated to document
getOctokit -
dist/rebuilt - Tests for multi-token usage