fix(ci): skip Claude workflows cleanly when ANTHROPIC_API_KEY is unset#7
Merged
Merged
Conversation
Both claude.yml (@claude mention responder) and claude-review.yml (auto-PR review) invoke anthropics/claude-code-action@v1, which fails with an opaque environment-validation error when the secret is missing. A fresh fork of this template would then see red CI on every PR until the maintainer added the secret. Refactor both workflows into a two-job pattern: - A check-secret gate job exposes whether ANTHROPIC_API_KEY is set via a job output (since `if: ${{ secrets.X != '' }}` is not allowed at job level). - The downstream responder/review job is gated on that output, so it is skipped (not failed) when the secret is absent. - A ::notice:: annotation tells the maintainer exactly which secret to add and where. Behavior is unchanged when the secret IS set. Refs #6 AI-Tool: claude-code Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens both shipped GitHub Actions workflows (
claude.ymlandclaude-review.yml) so that they skip cleanly whenANTHROPIC_API_KEYis not configured, rather than failing with an opaque environment-validation error. Fresh forks of this template now get green/skipped CI on PRs until the maintainer adds the secret — no red checks before any code is even written.Closes #6
Changes
.github/workflows/claude-review.ymlandclaude.ymlcheck-secretgate job that runs first and exposes a boolean outputhas_key. (Job-levelif: ${{ secrets.X != '' }}isn't allowed by GitHub Actions, hence the gate-job pattern.)needs.check-secret.outputs.has_key == 'true'.::notice::annotation with actionable wording when the secret is missing: where to add it (Settings → Secrets and variables → Actions) and what name (ANTHROPIC_API_KEY).docs/integrations.mdArchitecture
Code Walkthrough
Why a separate gate job?
GitHub Actions intentionally restricts
secrets.*evaluation in job-levelifconditions to prevent secret oracling. The supported pattern is to expose the secret to a step viaenv:, evaluate at runtime, and propagate the result throughoutputs. The cost is one extra short-lived job; the benefit is that downstream jobs are skipped (which counts as success at the workflow level), not failed.Testing
python -c "import yaml; yaml.safe_load(open('...'))"for both files.ANTHROPIC_API_KEYset. Ifcheck-secretsucceeds andreviewis skipped on this PR, the fix is confirmed.claude.yml's existing@claude-mention conditional is preserved — it now ANDs with the secret-present check.Agent Review Context
.github/workflows/claude-review.yml,.github/workflows/claude.ymlChecklist
docs/integrations.md)🤖 Generated with Claude Code