Skip to content

Commit 613e082

Browse files
authored
github: support GITHUB_TOKEN + skip OIDC (anomalyco#5459)
1 parent b6856bd commit 613e082

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

github/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ inputs:
1717
description: "Custom prompt to override the default prompt"
1818
required: false
1919

20+
use_github_token:
21+
description: "Use GITHUB_TOKEN directly instead of OpenCode App token exchange. When true, skips OIDC and uses the GITHUB_TOKEN env var."
22+
required: false
23+
default: "false"
24+
2025
runs:
2126
using: "composite"
2227
steps:
@@ -51,3 +56,4 @@ runs:
5156
MODEL: ${{ inputs.model }}
5257
SHARE: ${{ inputs.share }}
5358
PROMPT: ${{ inputs.prompt }}
59+
USE_GITHUB_TOKEN: ${{ inputs.use_github_token }}

packages/opencode/src/cli/cmd/github.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,30 @@ export const GithubRunCommand = cmd({
411411
let exitCode = 0
412412
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
413413
const triggerCommentId = payload.comment.id
414+
const useGithubToken = normalizeUseGithubToken()
414415

415416
try {
416-
const actionToken = isMock ? args.token! : await getOidcToken()
417-
appToken = await exchangeForAppToken(actionToken)
417+
if (useGithubToken) {
418+
const githubToken = process.env["GITHUB_TOKEN"]
419+
if (!githubToken) {
420+
throw new Error(
421+
"GITHUB_TOKEN environment variable is not set. When using use_github_token, you must provide GITHUB_TOKEN.",
422+
)
423+
}
424+
appToken = githubToken
425+
} else {
426+
const actionToken = isMock ? args.token! : await getOidcToken()
427+
appToken = await exchangeForAppToken(actionToken)
428+
}
418429
octoRest = new Octokit({ auth: appToken })
419430
octoGraph = graphql.defaults({
420431
headers: { authorization: `token ${appToken}` },
421432
})
422433

423434
const { userPrompt, promptFiles } = await getUserPrompt()
424-
await configureGit(appToken)
435+
if (!useGithubToken) {
436+
await configureGit(appToken)
437+
}
425438
await assertPermissions()
426439

427440
await addReaction()
@@ -514,8 +527,10 @@ export const GithubRunCommand = cmd({
514527
// Also output the clean error message for the action to capture
515528
//core.setOutput("prepare_error", e.message);
516529
} finally {
517-
await restoreGitConfig()
518-
await revokeAppToken()
530+
if (!useGithubToken) {
531+
await restoreGitConfig()
532+
await revokeAppToken()
533+
}
519534
}
520535
process.exit(exitCode)
521536

@@ -544,6 +559,14 @@ export const GithubRunCommand = cmd({
544559
throw new Error(`Invalid share value: ${value}. Share must be a boolean.`)
545560
}
546561

562+
function normalizeUseGithubToken() {
563+
const value = process.env["USE_GITHUB_TOKEN"]
564+
if (!value) return false
565+
if (value === "true") return true
566+
if (value === "false") return false
567+
throw new Error(`Invalid use_github_token value: ${value}. Must be a boolean.`)
568+
}
569+
547570
function isIssueCommentEvent(
548571
event: IssueCommentEvent | PullRequestReviewCommentEvent,
549572
): event is IssueCommentEvent {

0 commit comments

Comments
 (0)