actions/github-script
Run inline JavaScript with a preauthenticated GitHub API client, no separate action needed.
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
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
| Input | Description | Default | Required |
|---|---|---|---|
script | JavaScript to run. Async, with github/context/core in scope. | - | Yes |
github-token | Token for the API client. | GITHUB_TOKEN | No |
result-encoding | How to encode the result output: json or string. | json | No |
retries | Automatic retry count for failed API calls. | 0 | No |
Outputs
| Output | Description |
|---|---|
result | The 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 integrationmeans theGITHUB_TOKENlacks the needed scope. Add it underpermissions:.
Security and pinning
- Grant the least
permissions:the script needs. Do not run github-script with untrusted input onpull_request_targetwithout care.
Alternatives and related
Frequently asked questions
How do I use the script output later?
steps.<id>.outputs.result. Set result-encoding: string if you returned a plain string.