oven-sh/bun · error · Error
GITHUB_TOKEN environment variable is required
Error message
GITHUB_TOKEN environment variable is required
What it means
autoCloseDuplicates() requires GITHUB_TOKEN to authenticate every GitHub call (searching stale issues, reading comments, closing duplicates). Without it the script cannot run at all and aborts before any API request.
Solutions
- Pass the Actions token: env: GITHUB_TOKEN: ${{ github.token }} on the step
- Locally, export a PAT with repo scope as GITHUB_TOKEN before running
- Confirm the secret exists under repository/organization secrets
Example fix
# before
- run: bun scripts/auto-close-duplicates.ts
# after
- run: bun scripts/auto-close-duplicates.ts
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }} Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.GITHUB_TOKEN) {
console.error('GITHUB_TOKEN not set; export it or add env: GITHUB_TOKEN: ${{ github.token }} to the step');
process.exit(1);
} Prevention
- Map github.token onto every step that calls the GitHub API
- Keep a preflight env check at the top of CI helper scripts
When it happens
Trigger: Running the script locally or in CI without GITHUB_TOKEN in the environment; a workflow step missing the env: mapping for the token.
Common situations: Local reproduction attempt without exporting a token; workflow refactored and env block dropped; token secret renamed.
Related errors
- Invalid GITHUB_REPOSITORY format
- Azure secret not found
- [azure] Unsupported OS
- Buildkite token not found: set BUILDKITE_AGENT_TOKEN or…
- github
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/1c75be03cd2efa14.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/auto-close-duplicates.ts:221
});
// Close the issue as duplicate
await githubRequest(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, token, "POST", {
body: `Duplicate of #${duplicateOfNumber}.
This issue has been automatically closed as a duplicate.
If this is incorrect, please re-open this issue or create a new one.
🤖 Generated with [Claude Code](https://claude.ai/code)`,
});
}
async function autoCloseDuplicates(): Promise<void> {
console.log("[DEBUG] Starting auto-close duplicates script");
const token = process.env.GITHUB_TOKEN;
if (!token) {
throw new Error("GITHUB_TOKEN environment variable is required");
}
console.log("[DEBUG] GitHub token found");
// Parse GITHUB_REPOSITORY (format: "owner/repo")
const repository = process.env.GITHUB_REPOSITORY || "oven-sh/bun";
const [owner, repo] = repository.split("/");
if (!owner || !repo) {
throw new Error(`Invalid GITHUB_REPOSITORY format: ${repository}`);
}
console.log(`[DEBUG] Repository: ${owner}/${repo}`);
const threeDaysAgo = new Date();
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
console.log(`[DEBUG] Checking for duplicate comments older than: ${threeDaysAgo.toISOString()}`);
console.log("[DEBUG] Fetching open issues created more than 3 days ago...");
const allIssues: GitHubIssue[] = [];
let page = 1;View on GitHub (pinned to 8c5296ac45)