Repository navigation
Conversation
Forks of a private repository are private, so the deploy build cannot clone them with this workflow's token and fails with 'repository not found'. For private repositories, fetch refs/pull/<n>/head from the base repository instead. Public repositories keep checking out the fork directly. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
Author
|
@elastic/docs-engineering could you review this? Where I'd like the most attention:
Untested end to end. Proposed verification after merge and the |
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.
Why
Preview deploys fail for pull requests that Elastic employees open from their fork of a private repository. The preview comment is posted ("⏳ Building and deploying preview…") and then never updated, because the build job dies at checkout.
Real example: https://github.com/elastic/cloud/pull/161041 (opened from
gigerdo/cloud), run https://github.com/elastic/cloud/actions/runs/43048361021:deploy-preview,commentandupdate-link-indexare all skipped as a consequence, so nothing ever replaces the in-progress comment.Why this happens
docs-deploy.ymldeliberately lets fork PRs from Elastic org members through (is-fork == 'true'andis-org-member == 'true'). Non-members are rejected byEvaluateandReject fork checkout. So the fork guard is not skipped by mistake; the member is allowed, which is also whypre-commentposted the comment.buildjob then checks outneeds.preflight.outputs.head-repo, which is the fork (gigerdo/cloud).GITHUB_TOKENof the workflow run is scoped to the base repository (contents: readonelastic/cloud) and has no access togigerdo/cloud. GitHub answers with "repository not found", not 403.This was never visible for public repositories, where forks are public and can be cloned anonymously. It only shows up for private repositories such as
elastic/cloud. Verified for the example:elastic/cloudisprivate: true,gigerdo/cloudisprivate: trueandfork: true.Why
refs/pull/<n>/headworksThe base repository itself exposes every PR head, including fork PRs, as
refs/pull/<n>/head. The workflow's token can read the base repository, so no extra permission or secret is needed. For the failing example:That is exactly the
head-shathe failed run tried to fetch from the fork.What
In the
buildjob ofdocs-deploy.yml, the singleCheckoutstep becomes two mutually exclusive steps:head-repoathead-shagithub.repositoryatrefs/pull/<n>/headThe condition is only true when all of these hold:
github.event.repository.private == true, the event ispull_request,is-fork == 'true', andpr-numberis not empty. The second step is its exact negation, so one of the two always runs and never both.Nothing else changes.
HEAD_REPOis still the fork's name for the later build step (GITHUB_REPOSITORY), and the existingValidate checkout SHAstep still runs after either checkout.Security
EvaluateandReject fork checkoutand never reach checkout.persist-credentials: falseand thecontents: readpermission are kept.Validate checkout SHAcomparesHEADwithhead-shafrom the triggering run. If the author pushes again between the build and the deploy,refs/pull/<n>/headpoints at the newer commit, the check fails and the deploy stops with the existing "branch may have been updated" message, the same behaviour as before for stale SHAs.Scope: private repositories only
Public repositories are intentionally not touched. They work today and keep the exact same code path. If public forks ever need this, that is a separate decision.
Testing
Done:
actionlint .github/workflows/docs-deploy.ymlpasses.git ls-remotethatrefs/pull/161041/headinelastic/cloudresolves to the SHA the failed run requested.Not done: an end-to-end run.
docs-deploy.ymlis a reusable workflow called aselastic/docs-actions/.github/workflows/docs-deploy.yml@v1and it triggers onworkflow_run, so it cannot be exercised from a branch of this repo alone. Suggested verification after merge and thev1tag move: re-run https://github.com/elastic/cloud/actions/runs/43048361021 (or push to the PR) and check thatCheckoutsucceeds andValidate checkout SHApasses. I also have not checked whetheractions/checkout@v7fetchingrefs/pull/<n>/headwithfetch-depth: 1behaves differently from the plain-SHA fetch; it is the documented use of therefinput.Not in this PR
When
buildfails, the in-progress comment is never updated, so a failed deploy looks like a hung one. That is a separate concern (error handling rather than checkout) and should be its own PR.Until this ships, the workaround for affected PRs is to push the branch to the private repository itself instead of a fork.
🤖 Generated with Claude Code