Skip to content

Commit 8037ad4

Browse files
wesmclaude
andcommitted
fix: use ANTHROPIC_API_KEY for opencode agent in gh-action (#325)
OpenCode is a multi-provider tool with no single API key of its own. It previously fell through to the default OPENAI_API_KEY, which was confusing. Default to ANTHROPIC_API_KEY (matching OpenCode's own GitHub Actions docs) and add a note in the workflow preamble telling users to swap the secret if they use a different model provider. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 05b27f8 commit 8037ad4

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

cmd/roborev/ghaction.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,19 @@ After generating the workflow, add repository secrets ` +
6565
// List required secrets per agent
6666
infos := ghaction.AgentSecrets(cfg.Agents)
6767
for i, info := range infos {
68-
fmt.Printf(
69-
" %d. Add a repository secret "+
70-
"named %q (%s API key)\n",
71-
i+1, info.SecretName, info.Name)
68+
if info.Name == "opencode" {
69+
fmt.Printf(
70+
" %d. Add a repository secret "+
71+
"named %q (default for "+
72+
"opencode; change if using "+
73+
"a different provider)\n",
74+
i+1, info.SecretName)
75+
} else {
76+
fmt.Printf(
77+
" %d. Add a repository secret "+
78+
"named %q (%s API key)\n",
79+
i+1, info.SecretName, info.Name)
80+
}
7281
fmt.Printf(
7382
" gh secret set %s\n",
7483
info.SecretName)

internal/ghaction/ghaction.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func AgentEnvVar(agentName string) string {
8585
switch agentName {
8686
case "claude-code":
8787
return "ANTHROPIC_API_KEY"
88+
case "opencode":
89+
return "ANTHROPIC_API_KEY"
8890
case "gemini":
8991
return "GOOGLE_API_KEY"
9092
case "copilot":
@@ -253,8 +255,14 @@ var workflowTemplate = `# roborev CI Review
253255
#
254256
# Required setup:
255257
{{- range .EnvEntries }}
258+
{{- if eq .Name "opencode" }}
259+
# - Add a repository secret named "{{ .SecretName }}" (default for opencode).
260+
# If you use a different model provider, replace with the appropriate key
261+
# (e.g., OPENAI_API_KEY, GOOGLE_API_KEY) and update the env block below.
262+
{{- else }}
256263
# - Add a repository secret named "{{ .SecretName }}" with your {{ .Name }} API key
257264
{{- end }}
265+
{{- end }}
258266
#
259267
# Review behavior (types, reasoning, severity) is configured in
260268
# .roborev.toml under the [ci] section.

internal/ghaction/ghaction_test.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,34 @@ func TestGenerate(t *testing.T) {
199199
"@openai/codex@latest",
200200
},
201201
},
202+
{
203+
name: "opencode uses ANTHROPIC_API_KEY",
204+
cfg: WorkflowConfig{
205+
Agents: []string{"opencode"},
206+
},
207+
wantStrs: []string{
208+
"opencode-ai/opencode@latest",
209+
"ANTHROPIC_API_KEY",
210+
"different model provider",
211+
},
212+
envChecks: func(t *testing.T, env map[string]string) {
213+
if _, ok := env["ANTHROPIC_API_KEY"]; !ok {
214+
t.Error("expected ANTHROPIC_API_KEY in env")
215+
}
216+
},
217+
},
202218
{
203219
name: "dedupes env vars",
204220
cfg: WorkflowConfig{
205-
Agents: []string{"codex", "opencode"},
221+
Agents: []string{"claude-code", "opencode"},
206222
},
207223
wantStrs: []string{
208-
"@openai/codex@latest",
224+
"@anthropic-ai/claude-code@latest",
209225
"opencode-ai/opencode@latest",
210226
},
211227
envChecks: func(t *testing.T, env map[string]string) {
212-
if _, ok := env["OPENAI_API_KEY"]; !ok {
213-
t.Error("expected OPENAI_API_KEY in env")
228+
if _, ok := env["ANTHROPIC_API_KEY"]; !ok {
229+
t.Error("expected ANTHROPIC_API_KEY in env")
214230
}
215231
},
216232
},
@@ -262,12 +278,12 @@ func TestGenerate(t *testing.T) {
262278
lines := strings.Split(out, "\n")
263279
envDefCount := 0
264280
for _, line := range lines {
265-
if strings.HasPrefix(strings.TrimSpace(line), "OPENAI_API_KEY:") {
281+
if strings.HasPrefix(strings.TrimSpace(line), "ANTHROPIC_API_KEY:") {
266282
envDefCount++
267283
}
268284
}
269285
if envDefCount != 1 {
270-
t.Errorf("expected 1 OPENAI_API_KEY: definition, got %d", envDefCount)
286+
t.Errorf("expected 1 ANTHROPIC_API_KEY: definition, got %d", envDefCount)
271287
}
272288
}
273289
}
@@ -453,7 +469,7 @@ func TestAgentEnvVar(t *testing.T) {
453469
{"claude-code", "ANTHROPIC_API_KEY"},
454470
{"gemini", "GOOGLE_API_KEY"},
455471
{"copilot", "GITHUB_TOKEN"},
456-
{"opencode", "OPENAI_API_KEY"},
472+
{"opencode", "ANTHROPIC_API_KEY"},
457473
{"droid", "OPENAI_API_KEY"},
458474
}
459475
for _, tt := range tests {
@@ -482,10 +498,16 @@ func TestAgentSecrets(t *testing.T) {
482498
wantVars: []string{"OPENAI_API_KEY"},
483499
},
484500
{
485-
name: "dedupes by env var",
501+
name: "codex and opencode have separate keys",
486502
agents: []string{"codex", "opencode"},
503+
wantLen: 2,
504+
wantVars: []string{"OPENAI_API_KEY", "ANTHROPIC_API_KEY"},
505+
},
506+
{
507+
name: "dedupes by env var",
508+
agents: []string{"claude-code", "opencode"},
487509
wantLen: 1,
488-
wantVars: []string{"OPENAI_API_KEY"},
510+
wantVars: []string{"ANTHROPIC_API_KEY"},
489511
},
490512
{
491513
name: "multi env var",

0 commit comments

Comments
 (0)