From e89411bb6f540b448a41d4a997c7c8dd9376dafb Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Mon, 18 Aug 2025 10:50:15 -0700 Subject: [PATCH] feat: skip action gracefully for workflow validation errors (#460) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: skip action gracefully for workflow validation errors Handle workflow_not_found_on_default_branch and workflow_content_mismatch errors by skipping the action with a warning instead of failing. This improves user experience when adding Claude Code workflows to new repositories or making workflow changes in PRs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * Update src/github/token.ts --------- Co-authored-by: Claude --- action.yml | 2 +- src/github/token.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4d1b330..d1f8434 100644 --- a/action.yml +++ b/action.yml @@ -286,7 +286,7 @@ runs: fi - name: Revoke app token - if: always() && inputs.github_token == '' + if: always() && inputs.github_token == '' && steps.prepare.outputs.skipped_due_to_workflow_validation_mismatch != 'true' shell: bash run: | curl -L \ diff --git a/src/github/token.ts b/src/github/token.ts index 6c83c9b..da30285 100644 --- a/src/github/token.ts +++ b/src/github/token.ts @@ -31,8 +31,33 @@ async function exchangeForAppToken(oidcToken: string): Promise { const responseJson = (await response.json()) as { error?: { message?: string; + details?: { + error_code?: string; + }; }; + type?: string; + message?: string; }; + + // Check for specific workflow validation error codes that should skip the action + const errorCode = responseJson.error?.details?.error_code; + + if ( + errorCode === "workflow_not_found_on_default_branch" || + errorCode === "workflow_content_mismatch" + ) { + const message = + responseJson.message ?? + responseJson.error?.message ?? + "Workflow validation failed"; + core.warning(`Skipping action due to workflow validation: ${message}`); + console.log( + "Action skipped due to workflow validation error. This is expected when adding Claude Code workflows to new repositories or on PRs with workflow changes.", + ); + core.setOutput("skipped_due_to_workflow_validation_mismatch", "true"); + process.exit(0); + } + console.error( `App token exchange failed: ${response.status} ${response.statusText} - ${responseJson?.error?.message ?? "Unknown error"}`, ); @@ -77,6 +102,7 @@ export async function setupGitHubToken(): Promise { core.setOutput("GITHUB_TOKEN", appToken); return appToken; } catch (error) { + // Only set failed if we get here - workflow validation errors will exit(0) before this core.setFailed( `Failed to setup GitHub token: ${error}\n\nIf you instead wish to use this action with a custom GitHub token or custom GitHub app, provide a \`github_token\` in the \`uses\` section of the app in your workflow yml file.`, );