Skip to content

Commit 2ba5f2d

Browse files
Copilotpelikhan
andcommitted
Add if condition to OIDC setup step to check secret presence
- Added if condition: secrets.{TOKEN_ENV_VAR} != '' - Setup step now only runs when the secret exists - Updated test to verify the if condition is present - Uses engine-specific token env var (e.g., ANTHROPIC_API_KEY for Claude) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 218e682 commit 2ba5f2d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pkg/workflow/openid.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ func GenerateOIDCSetupStep(oidcConfig *OIDCConfig, engine CodingAgentEngine) Git
9999

100100
stepLines = append(stepLines, " - name: Setup OIDC token")
101101
stepLines = append(stepLines, " id: setup_oidc_token")
102+
// Only run if the fallback token secret exists (check for non-empty secret)
103+
stepLines = append(stepLines, fmt.Sprintf(" if: secrets.%s != ''", engine.GetTokenEnvVarName()))
102104
stepLines = append(stepLines, " uses: actions/github-script@v8")
103105
stepLines = append(stepLines, " env:")
104106

pkg/workflow/openid_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ func TestClaudeEngineWithOIDC(t *testing.T) {
121121
t.Error("Expected OIDC setup step to be present")
122122
}
123123

124+
// Verify setup step has if condition to check for secret
125+
if !strings.Contains(stepsStr, "if: secrets.ANTHROPIC_API_KEY != ''") {
126+
t.Error("Expected OIDC setup step to have 'if: secrets.ANTHROPIC_API_KEY != ''' condition")
127+
}
128+
124129
// Verify OIDC revoke step is present
125130
if !strings.Contains(stepsStr, "Revoke OIDC token") {
126131
t.Error("Expected OIDC revoke step to be present")

0 commit comments

Comments
 (0)