github-script
Skill4 starsChanged 7 months agoMITView on GitHub
Advanced use cases and examples for using actions/github-script. You MUST load this skill when using actions/github-script in workflows.
- Reads credentials
2 other projects use a version of this.
Adopted by
Most recently taken up by
- kjanat/skillstheir own version, first seen Jun 30, 2026
- github/gh-awtheir own version, first seen May 27, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- github/gh-aw★ 5.3ksame name
- kjanat/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository124 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/AGENTS.mdAGENTS.md
- .github/workflows/AGENTS.mdAGENTS.md
- .vscode/AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- agent-log-analysisSkill
- agent-mdSkill
- agent-md-writerSkill
- agent-skill-md-writerSkill
- agentskillsSkill
- agents-md-writerSkill
- ai-prompt-writerSkill
- ansibleSkill
- apache-airflow-apiSkill
- apache-airflow-dagsSkill
- astro-cliSkill
- astronomer-docsSkill
- awesome-copilotSkill
- brainstorm-agent-runsSkill
- brainstorm-github-prSkill
- brainstormSkill
- catSkill
- chrome-devtoolsSkill
- claude-docsSkill
- codeqlSkill
- code-reviewSkill
- code-tourSkill
- coding-standard-writerSkill
- context-aware-opsSkill
- copilot-cliSkill
- copilot-docsSkill
- critical-thinkingSkill
- datadog-agentSkill
- datadog-apiSkill
- datadog-mcpSkill
- datadog-monitorsSkill
- datadog-pulumiSkill
- devcontainerSkill
- dictationSkill
- direnvSkill
- dockerfileSkill
- dockerSkill
- docs-reviewSkill
- docs-writerSkill
- dot-claudeSkill
- dotfilesSkill
- dot-githubSkill
- editorconfigSkill
- fact-writerSkill
- gdpr-compliantSkill
- gh-agent-taskSkill
- gh-apiSkill
- gh-aw-compileSkill
- gh-aw-firewall-debugSkill
- gh-aw-firewallSkill
- gh-aw-newSkill
- gh-awSkill
- gh-aw-troubleshootingSkill
- gh-codespaceSkill
- gh-issueSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
When a native gh CLI command or existing standard GitHub Action already performs the exact required task efficiently.
- Very specific: line 27
If the required API endpoint is not supported by the octokit version embedded in the current actions/github-script release.
- Very specific: line 174
Use the @actions/exec package directly inside your script:
- Very specific: line 230
Avoid Script Injections: Do NOT evaluate expressions directly in the script.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Script
<!-- markdownlint-disable MD013 -->Expert guide for using actions/github-script in GitHub Actions workflows. Focuses on advanced API interactions, cross-platform execution, and secure script implementation.
When to Use
- You need to perform complex interactions with the GitHub API from within a workflow.
- You want to use JavaScript/TypeScript to automate issue management, PR reviews, or other GitHub actions.
- You're looking for examples of how to use the pre-authenticated
octokitclient provided byactions/github-script. - You need to execute shell commands cross-platform within a GitHub Script block.
When Not to Use
- When a native
ghCLI command or existing standard GitHub Action already performs the exact required task efficiently. - For running complex bash scripts that don't need the GitHub API (use standard
run:steps instead). - If the required API endpoint is not supported by the
octokitversion embedded in the currentactions/github-scriptrelease.
Common Pitfalls
- Script Injection: Passing user-controlled input (like PR titles) directly into the JavaScript template literal instead of passing it via the
env:block. - Scope Creep: Writing massive, 500-line monolithic JavaScript functions inside the workflow YAML instead of extracting the logic into a proper
.jsfile or local action. - Assuming Global Context: Forgetting that
github-scriptruns inside the runner environment and doesn't automatically have access to all repository files unless actions/checkout has been run.
Core Concepts
actions/github-script allows you to write JavaScript within your workflow to interact
directly with the GitHub API via an authenticated octokit client.
github: A pre-authenticatedoctokit/rest.jsclient.context: An object containing the workflow run context.core: A reference to@actions/core.glob: A reference to@actions/glob.io: A reference to@actions/io.exec: A reference to@actions/exec.getOctokit: A factory function to create additional clients with different tokens.
Common Use Cases
1. Comment on an Issue
on:
issues:
types: [opened]
jobs:
comment:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👋 Thanks for reporting!'
})2. Apply a Label to an Issue
on:
issues:
types: [opened]
jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Triage']
})3. Create or Update File Contents (Poller Example)
Useful when polling repositories and updating a README.md periodically.
on:
workflow_dispatch:
schedule:
- cron: "0 12 * * *"
jobs:
poll:
runs-on: ubuntu-latest
steps:
- name: Fetch all
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ORG_PAT }}
script: |
const repos = await github.paginate(github.rest.search.repos, {
q: "<query string>",
})
let newReadme = `
<updating the README>
`
const existingReadme = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: "<repo>",
path: "README.md",
})
await github.rest.repos.createOrUpdateFileContents({
owner: context.repo.owner,
repo: "<repo>",
path: "README.md",
message: "Update README",
content: btoa(newReadme),
sha: existingReadme.data.sha,
})4. Welcome a First-Time Contributor
on: pull_request_target
jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v9
with:
script: |
const creator = context.payload.sender.login
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
creator,
state: 'all'
})
const issues = await github.paginate(opts)
for (const issue of issues) {
if (issue.number === context.issue.number) {
continue
}
if (issue.pull_request) {
return // Creator is already a contributor.
}
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `**Welcome**, new contributor!
Please make sure you've read our contributing guide
and we look forward to reviewing your Pull request shortly ✨`
})5. Executing Commands Cross-Platform
Use the @actions/exec package directly inside your script:
on: push
jobs:
use-exec:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/github-script@v9
with:
script: |
const {
exitCode,
stdout,
stderr
} = await exec.getExecOutput('echo', ['hello']);
console.log(exitCode, stdout, stderr)6. Complex Condition Checking and Workflow Control
Replace verbose GitHub Actions expressions with a centralized github-script block to determine if subsequent steps
should run based on complex logic (e.g., event type, user roles, and message content).
- name: Check conditions
id: check
uses: actions/github-script@v7
env:
TRIGGERS: '/co, /cogni'
with:
script: |
const triggers = process.env.TRIGGERS.split(',').map(t => t.trim());
const isBot = context.actor.endsWith('[bot]');
const eventName = context.eventName;
let run = false;
if (eventName === 'issue_comment' && !isBot) {
const body = context.payload.comment?.body;
const assoc = context.payload.comment?.author_association;
const isAllowed = ['MEMBER', 'OWNER'].includes(assoc);
run = isAllowed && triggers.some(t => body?.includes(t));
}
core.setOutput('run', run ? 'true' : '');
- name: Dependent Step
if: steps.check.outputs.run == 'true'
run: echo "Logic passed!"Security Best Practices
Avoid Script Injections: Do NOT evaluate expressions directly in the
script. Pass them as environment variables.# BAD: vulnerable to script injection script: console.log('${{ github.event.pull_request.title }}') # GOOD: pass via env env: TITLE: ${{ github.event.pull_request.title }} script: console.log(process.env.TITLE)- Require Authentication for External Repo Access: The default
GITHUB_TOKENis scoped only to the current repository. To access other repos, configure a PAT and pass it togithub-token.
Related Skills
- gh-api:
You MUST load this skill when working with the
gh apicommand. - gh-run:
You MUST load this skill when working with the
gh runand thegh workflowcommands.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

