Skip to content

Conversation

@alex-page
Copy link

@alex-page alex-page commented Jul 23, 2025

The Problem

The changesets/action fails with "There is no .changeset directory in this project" when using sparse checkout, even when the cwd parameter is specified. I am using sparse checkout to take a folder from a very large GitHub repository and this folder has it's own .changeset directory.

Root Cause

The error occurs during the initial validation phase of the action, before any custom commands run. Here's the code flow:

1: In changesets/action index.ts we call let { changesets } = await readChangesetState(); without passing the cwd in.

let { changesets } = await readChangesetState();

2: This is passed into readChangesetState.ts where the cwd is set to process.cwd() because the cwd from the action is not passed through.

let changesets = await readChangesets(cwd);

  1. The readChangesets function from @changesets/read looks for .changeset at the provided path and throws the error when not found.

https://github.com/changesets/changesets/blob/c7b6832a7a2783073e720d2085a546810e9b55eb/packages/read/src/index.ts#L22-L35

Why This Happens

  • index.ts calls readChangesetState() without the cwd parameter
  • readChangesetState defaults to process.cwd() (repository root)
  • With sparse checkout, .changeset doesn't exist at the repo root
  • The action fails during initialization, before version or publish commands run

## Issue Analysis: changesets/action with Sparse Checkout

### The Problem
The changesets/action fails with "There is no .changeset directory in this project" when using sparse checkout, even when the `cwd` parameter is specified.

### Root Cause
The error occurs during the initial validation phase of the action, before any custom commands run. Here's the code flow:

1. **In [changesets/action index.ts line 31](https://raw.githubusercontent.com/changesets/action/refs/heads/main/src/index.ts)**:
   ```typescript
   let { changesets } = await readChangesetState();  // No cwd parameter passed
   ```

2. **In [readChangesetState.ts](https://raw.githubusercontent.com/changesets/action/refs/heads/main/src/readChangesetState.ts)**:
   ```typescript
   export default async function readChangesetState(
     cwd: string = process.cwd()  // Defaults to repo root when not provided
   ): Promise<ChangesetState> {
     let preState = await readPreState(cwd);
     let changesets = await readChangesets(cwd);  // This calls @changesets/read
   ```

3. **The `readChangesets` function from `@changesets/read`** looks for `.changeset` at the provided path and throws the error when not found.

### Why This Happens
- `index.ts` calls `readChangesetState()` without the `cwd` parameter
- `readChangesetState` defaults to `process.cwd()` (repository root)
- With sparse checkout, `.changeset` doesn't exist at the repo root
- The action fails during initialization, before `version` or `publish` commands run

### Workaround
Since the validation happens before our custom commands execute, we need to ensure `.changeset` exists at the repository root:

```yaml
- name: Create .changeset symlink for changesets/action
  run: |
    # The changesets/action checks for .changeset at repo root during initialization
    # Since we're using sparse checkout, we need to create a symlink
    ln -s libraries/javascript/polaris/.changeset .changeset
```

### Proper Fix
The changesets/action should pass the `cwd` parameter to `readChangesetState()`:
```typescript
let { changesets } = await readChangesetState(cwd);  // Pass the cwd parameter
```
```
@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2025

⚠️ No Changeset found

Latest commit: 0c655c6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed. Using it to test the action pointed to this commit.

@alex-page alex-page closed this Jul 23, 2025
@alex-page
Copy link
Author

This didn't work.

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.

1 participant