Skip to content
Latchkey

actions/github-script

Run inline JavaScript with a preauthenticated GitHub API client, no separate action needed.

Official actionCategory: Utilities & ScriptingLatest v7View on GitHub

What it does

actions/github-script runs a snippet of JavaScript with github (an authenticated Octokit), context, core, and io in scope, so simple API automation needs no custom action.

It is the quickest way to comment on a PR, add labels, or dispatch another workflow from inside a job.

Usage

workflow (.yml)
steps:
  - uses: actions/github-script@v7
    with:
      script: |
        await github.rest.issues.createComment({
          owner: context.repo.owner,
          repo: context.repo.repo,
          issue_number: context.issue.number,
          body: 'Build passed on ' + context.sha.slice(0, 7),
        })

Inputs

InputDescriptionDefaultRequired
scriptJavaScript to run. Async, with github/context/core in scope.-Yes
github-tokenToken for the API client.GITHUB_TOKENNo
result-encodingHow to encode the result output: json or string.jsonNo
retriesAutomatic retry count for failed API calls.0No

Outputs

OutputDescription
resultThe value returned by the script.

Notes

The default GITHUB_TOKEN permissions are set by the workflow permissions: block. Grant pull-requests: write to comment.

Common errors

  • Resource not accessible by integration means the GITHUB_TOKEN lacks the needed scope. Add it under permissions:.

Security and pinning

  • Grant the least permissions: the script needs. Do not run github-script with untrusted input on pull_request_target without care.

Alternatives and related

Frequently asked questions

How do I use the script output later?
Read steps.<id>.outputs.result. Set result-encoding: string if you returned a plain string.

References

Running actions/github-script? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card