Skip to content

changeset-check.yml hardcodes origin/main and needs fetch-depth 0 #425

Description

@gtbuchanan

changeset-check.yml resolves its diff base differently from pre-commit.yml, and the difference costs a full-history clone on every PR.

Current state

changeset-check.yml:

- uses: actions/checkout@v7
  with:
    fetch-depth: 0
...
- run: pnpm exec changeset status --since=origin/main

pre-commit.yml, which gets this right:

- uses: actions/checkout@v7        # no fetch-depth — shallow is fine
...
- env:
    BASE_SHA: ${{ github.event.pull_request.base.sha }}
  run: mise run hk:base -- "$BASE_SHA"

Two separate problems.

1. Hardcoded origin/main

The base is assumed rather than read from the event. A PR targeting anything other than main — a release branch, a stacked PR — is diffed against the wrong base. github.event.pull_request.base.sha is the base GitHub actually recorded, and is what pre-commit.yml already uses.

2. fetch-depth: 0 as a workaround for shallow-clone breakage

changeset status --since cannot run on a shallow clone. @changesets/git's getChangedFilesSince shells out to git merge-base <ref> HEAD and diffs from the divergence point, which needs common ancestry the shallow clone does not have. fetch-depth: 0 sidesteps that by cloning all history on every PR run.

gtb hk base solves the same problem properly: it detects git rev-parse --is-shallow-repository and fetches just the base before diffing (executeHkBase in packages/cli/src/commands/root/hk.ts), so pre-commit.yml needs no fetch-depth at all.

Note the two gates in this workflow have different needs. gtb changeset check only reads the base commit's tree (rev-parse --verify, cat-file -e, git show <base>:pnpm-workspace.yaml) — a depth-1 fetch of the base would satisfy it. Only changeset status needs real ancestry.

Suggested fix

  • Pass github.event.pull_request.base.sha to both steps instead of origin/main.
  • Port the shallow-detect-and-fetch handling from executeHkBase so the checkout can drop fetch-depth: 0. Since changeset status needs merge-base ancestry rather than just the base commit, this likely needs a deepening fetch (--deepen / --shallow-since) rather than the --depth=1 that suffices for hk, so it needs measuring before committing to it.
  • Consider extracting the shared base-ref resolution so gtb hk and gtb changeset check don't drift apart.

Deferred out of the PR that added gtb changeset check, which kept the existing convention rather than changing base resolution for the stock changeset status gate at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions