Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect changed workspaces #2015

Merged
merged 11 commits into from
Aug 10, 2022
Merged

Conversation

cristiano-belloni
Copy link
Contributor

@cristiano-belloni cristiano-belloni commented Aug 9, 2022

This PR adds a getChangedWorkspaces to utils, which is a function that takes a branch name and:

  1. Gets all the files that git marks as changed between the current state of the repo and the latest commit in common with the specified branch, including untracked and unstaged files. This is handy, for example, to find out the files changed in a PR where the branch specified is the target branch.
  2. Gets all the nearest package.json for each of the changed files to compute the containing workspace of each changed file.
  3. Matches the list of workspace to the global WorkspaceContent and returns a subset WorkspaceContent containing only the changed workspace info.

Example

const workspaces = await getAllWorkspaces();
const changedWorkspaces = await getChangedWorkspaces(workspaces, "origin/main");

// Assuming that only files in `workspace-1` and `workspace-3` have changed, the result would be:

[
  Map(
    {
      'workspace-1': {
        // Noisy package info, omissis...
      },
      'workspace-3': {
        // Noisy package info, omissis...
      },
    },
   ),
  {
    'workspace-1': {
      location: 'packages/workspace-1',
      workspaceDependencies: ['workspace-2', 'workspace-3'],
      mismatchedWorkspaceDependencies: [],
    },
    'workspace-3': {
      location: 'packages/workspace-3',
      workspaceDependencies: [],
      mismatchedWorkspaceDependencies: [],
    },
  },
]

Tasks:

  • Match changed files to the closest package.json, which in turn matches to an entry in workspaceInfo
  • Return a subset of the workspaceInfo workspaces, with the same type
  • Make it possible to specify a branch in getGitDiff
  • Take workspaces in the arguments

@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2022

🦋 Changeset detected

Latest commit: fcc8957

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
modular-scripts Minor

Not sure what this means? Click here to learn what changesets are.

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

@coveralls
Copy link
Collaborator

coveralls commented Aug 9, 2022

Coverage Status

Coverage increased (+0.3%) to 33.917% when pulling fcc8957 on feature/changed-files-from-merge-base into 12d9ea0 on main.

@cristiano-belloni cristiano-belloni marked this pull request as ready for review August 9, 2022 15:16
@cristiano-belloni cristiano-belloni merged commit c9af2ad into main Aug 10, 2022
@cristiano-belloni cristiano-belloni deleted the feature/changed-files-from-merge-base branch August 10, 2022 12:11
@github-actions github-actions bot mentioned this pull request Aug 10, 2022
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.

4 participants