Skip to content

Fix constraints and update yarn lock at the end of release process#145

Merged
cryptodev-2s merged 19 commits intomainfrom
feature/update-yarn-constraints-lock
Jun 25, 2024
Merged

Fix constraints and update yarn lock at the end of release process#145
cryptodev-2s merged 19 commits intomainfrom
feature/update-yarn-constraints-lock

Conversation

@cryptodev-2s
Copy link
Copy Markdown
Contributor

@cryptodev-2s cryptodev-2s commented May 17, 2024

Description

In our current release process, we often encounter issues with dependency constraints, outdated yarn.lock files, and duplicated dependencies. These issues can lead to inconsistencies in our release process. Additionally, these steps are frequently needed whenever we release our packages, making the process cumbersome and error-prone.

Solution

This PR adds a new step to our release tool to streamline and automate the process. This step will:

  1. Fix Constraints: Ensure that all package versions adhere to the specified constraints,-.
  2. Update the Yarn Lockfile: Refresh the yarn.lock file to include the latest dependency resolutions..
  3. Deduplicate Dependencies: Remove duplicate dependencies to streamline the dependency tree, which helps in reducing the overall package size and avoiding multiple versions of the same dependency.

Implementation Details

  • Constraint Fixing: Introduces a command to enforce and fix version constraints for dependencies.
  • Yarn Lockfile Update: Runs yarn install to regenerate the yarn.lock file with the latest dependency resolutions.
  • Dependency Deduplication: Utilizes the yarn deduplicate command to clean up duplicated dependencies in the lockfile.
  • Release Tool Update: Integrates these steps into our release tool to automate the process, making it more fluid and less error-prone.

@cryptodev-2s cryptodev-2s requested a review from a team as a code owner May 17, 2024 14:30
@kanthesha
Copy link
Copy Markdown

The tests are failing!

    @scope/d does not seem to have a changelog. Skipping.
    Error: Command failed with exit code 1: yarn constraints --fix
    Internal Error: @scope/monorepo@workspace:.: This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile

And in the local as well.

  ● create-release-branch (functional) › against a monorepo with independent versions › does not update the changelogs of any packages that have been tagged with intentionally-skip

    Command failed with exit code 1: /Users/dck/Workspace/metamask/create-release-branch/node_modules/.bin/tsx /Users/dck/Workspace/metamask/create-release-branch/src/cli.ts --project-directory /var/folders/25/ryczmnrj08g0xdlfv3h5jlpw0000gn/T/create-release-branch-tests/wDg3SIGTUwN_Cn8M5rJCZ/local-repo --temp-directory /var/folders/25/ryczmnrj08g0xdlfv3h5jlpw0000gn/T/create-release-branch-tests/wDg3SIGTUwN_Cn8M5rJCZ/local-repo/tmp
    Error: Command failed with exit code 1: yarn constraints --fix
error Command "constraints" not found.

@cryptodev-2s
Copy link
Copy Markdown
Contributor Author

cryptodev-2s commented May 21, 2024

@kanthesha yes the functional test are failing. In the current testing configuration I need to add a constraints file, currently working on it.

@cryptodev-2s cryptodev-2s requested a review from kanthesha May 21, 2024 12:05
Copy link
Copy Markdown

@kanthesha kanthesha left a comment

Choose a reason for hiding this comment

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

Overall LGTM. I have made some minor suggestions.

@cryptodev-2s cryptodev-2s requested a review from kanthesha May 22, 2024 10:12
kanthesha
kanthesha previously approved these changes May 22, 2024
Copy link
Copy Markdown

@kanthesha kanthesha left a comment

Choose a reason for hiding this comment

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

LGTM.

@desi desi requested a review from a team May 23, 2024 18:34
@cryptodev-2s cryptodev-2s requested a review from mcmire May 29, 2024 11:00
@cryptodev-2s cryptodev-2s requested a review from kanthesha May 29, 2024 17:15
Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Is there a functional test we can add to confirm that the workflow bug we are trying to solve is fixed?

packageManager: 'yarn@3.2.1',
});

const constraintsProContent = `
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm... this constraints file doesn't really check anything I don't think? I believe that Yarn looks for certain predicates to exist. Perhaps this just file just needs to be present?

Copy link
Copy Markdown
Contributor Author

@cryptodev-2s cryptodev-2s May 29, 2024

Choose a reason for hiding this comment

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

It checks that each package has a name and a version field.
it's required for the constraints fix otherwise it throws This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a strange error when the constraints file doesn't exist. I would have expected something like "constraints.pro not found".

I just tried removing these lines and running the tests and they don't seem to fail with the error you describe 🤔

Copy link
Copy Markdown
Contributor Author

@cryptodev-2s cryptodev-2s May 31, 2024

Choose a reason for hiding this comment

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

we can remove the constraints file only the plugin installation is required (the error I sent earlier was related to the plugin installation removal), but don't we want to test that constraints check really works as this constraints at least checks that each package has a version and name, we can add more checks ? in this case we can also make this testing in a separate scenario as you proposed later (sorry I just saw the other comment)

@mcmire
Copy link
Copy Markdown
Contributor

mcmire commented May 29, 2024

Also can we update the PR description to describe the problem that we are solving here and how the changes solve that problem instead of just describing the changes? That would help us understand the context behind this PR in the future.

@cryptodev-2s
Copy link
Copy Markdown
Contributor Author

Also can we update the PR description to describe the problem that we are solving here and how the changes solve that problem instead of just describing the changes? That would help us understand the context behind this PR in the future.

I updated the description

packageManager: 'yarn@3.2.1',
});

const constraintsProContent = `
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a strange error when the constraints file doesn't exist. I would have expected something like "constraints.pro not found".

I just tried removing these lines and running the tests and they don't seem to fail with the error you describe 🤔

@mcmire
Copy link
Copy Markdown
Contributor

mcmire commented May 31, 2024

Just repeating my comment above about adding a functional test here. I think the problem that running yarn was intended to solve was so that the release PR wouldn't fail CI. CI runs yarn --immutable and then it runs yarn constraints as a part of the lint step, so it seems like we ought to have a test that runs the tool, then runs yarn --immutable, then yarn constraints and expects both of these commands to return an exit code of 0. This way we can be sure that we've solved the original problem. Is this possible to add?

Copy link
Copy Markdown
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Sorry for the long delay in reviewing this. Looks good to me.

);
});

it('updates the dependency version in package "b" when package "a" version is bumped', async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

create-release-branch runs yarn constraints --fix and doesn't care what the constraints are exactly. So it isn't necessary the case that create-release-branch always updates dependencies like this — it really depends on what the project's constraints file does (a project may have different constraints, in theory). That said, I'm okay with using this test name since it points to why we decided to add yarn constraints --fix in the first place. If we ever want to run constraints for a different reason we may have to adjust this test name to be more accurate, but I don't anticipate that happening any time soon.

@cryptodev-2s cryptodev-2s merged commit 03b300a into main Jun 25, 2024
@cryptodev-2s cryptodev-2s deleted the feature/update-yarn-constraints-lock branch June 25, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants