Skip to content

Read workflows from GitHub's default branch, not checkout - #23

Merged
singerbj merged 1 commit into
mainfrom
claude/eager-fermi-lmgnil
Oct 18, 2026
Merged

singerbj merged 1 commit into
mainfrom
claude/eager-fermi-lmgnil

Conversation

@singerbj

Copy link
Copy Markdown
Owner

Summary

This change makes gh-runner audit workflows against the default branch on GitHub (via the API) rather than relying on the local checkout. This ensures the audit reflects what GitHub will actually run, not a potentially stale or out-of-sync local copy.

Key Changes

  • Workflow source abstraction: Introduced WorkflowSource interface to support reading workflows from either a checkout or GitHub API, with implementations checkoutWorkflows() and githubWorkflows()

  • GitHub API methods: Added GhClient methods to read workflows from GitHub:

    • workflowFileNames() - lists workflow files on a branch
    • workflowFile() - reads a single workflow file raw and untrimmed
    • openPullRequestWithPrefix() - finds open PRs by branch prefix
  • Audit refactoring: New auditWorkflows() function that:

    • Reads workflows from GitHub's default branch first
    • Falls back to checkout only if GitHub read fails and checkout exists
    • Warns when falling back or when GitHub can't be read
    • Works without a checkout entirely
  • Fix branch logic: Simplified proposeWorkflowFix() to:

    • Check for open fix PRs by prefix instead of any pushed branch
    • Avoid stacking PRs when one is already open
    • Allow new fixes after a PR is closed (even if branch remains)
  • Improved reporting: Enhanced workflow audit output to:

    • Indicate which branch is being checked
    • Warn when nothing will send runners jobs
    • Clarify when the refusal watcher is off
  • Test coverage: Added comprehensive tests for:

    • Reading workflows from GitHub vs checkout
    • Fallback behavior when GitHub is unreachable
    • Handling of stale checkouts
    • Scanning without a checkout at all
    • PR branch conflict detection

Notable Implementation Details

  • The GitHub API read uses raw content format to preserve line numbers for audit reporting
  • Checkout fallback only happens if GitHub read fails; a successful read from GitHub is always preferred
  • The fix workflow no longer requires a checkout to exist, though one is still needed to actually apply fixes
  • Error messages distinguish between "no workflows directory" and "couldn't read" scenarios

https://claude.ai/code/session_011jzs3cPY8d3Le9V5W22Dyd

…tcher is off

The startup audit read .github/workflows from whatever was checked out
locally. GitHub runs the default branch, so a stale clone or another
branch could hide a merged GH_RUNNER_* fallback: gh-runner offered a fix
that was already merged and registered a runner with the refusal watcher
quietly off.

- Scan the default branch through the contents API. Fall back to the
  checkout only when GitHub can't be read, and warn that it may not match.
  The audit no longer needs a checkout at all.
- When the watcher is off, say so. When no job can reach the runner and
  nothing reads its variable, warn that it will sit idle.
- A fix PR blocks a new one only while it's open, and only once the
  default branch is known to still need the fix. A merged PR's leftover
  branch no longer stops anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011jzs3cPY8d3Le9V5W22Dyd
@singerbj
singerbj merged commit 2e42e31 into main Oct 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants