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

FIX use composer runtime api #11157

Merged
merged 16 commits into from
Feb 27, 2024
Merged

FIX use composer runtime api #11157

merged 16 commits into from
Feb 27, 2024

Conversation

lekoala
Copy link
Contributor

@lekoala lekoala commented Feb 23, 2024

Description

VersionProvider has to store in cache the composer lock file when it could simply use the composer runtime api to get the same information
Also fixes return types for array, fix irrelevant ?? checks (that are done on false, they only apply to null values)

Issues

#11134

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

Copy link
Member

@kinglozzer kinglozzer left a comment

Choose a reason for hiding this comment

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

Some thoughts:

  • Test failures :(
  • We should look to remove the code that manually parses composer.lock. We already implicitly require composer-runtime-api: ^2 (via silverstripe/vendor-plugin), so we know that the runtime API will be available
  • We should explicitly require composer-runtime-api in composer.json
  • It’d be worth testing the performance overhead of the runtime API (it looks like it’ll be very minimal) and seeing if we can remove our caching. There’s nothing inherently brittle about the caching we have in place, but less code to maintain is less code to maintain 😄

@lekoala
Copy link
Contributor Author

lekoala commented Feb 23, 2024

seems harder than expected, i only did some quick tests on my local project and it seemed to work at first glance but obviously the return values are not the ones expected in the tests.
it was a bit worried to add a composer.json entry in a patch release so that's why i didn't do it and kept the existing code for the same reason, since it's a protected method, it could technically be overwritten.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

This is mostly an echo of KingLozzer's review:

This will at a very minimum need the broken tests updated match the new functionality. We don't need as much test coverage with the composer runtime API since we can trust it to give us the correct versions, but we do need some (non-failing) test coverage.

I agree that we should aim to remove the composer.lock related functionality. Please:

  • deprecate the getComposerLock() method
  • add composer-runtime-api as an explicit dependency (we can do this in minor releases, which this should be targetting)
  • Remove the if (class_exists(\Composer\InstalledVersions::class)) { conditional statement since this will always evaluate as true, and remove the code that won't be reached

Please target the 5 branch and add a changelog entry for this change.

src/Core/Manifest/VersionProvider.php Outdated Show resolved Hide resolved
src/Core/Manifest/VersionProvider.php Outdated Show resolved Hide resolved
src/Core/Manifest/VersionProvider.php Outdated Show resolved Hide resolved
src/Core/Manifest/VersionProvider.php Outdated Show resolved Hide resolved
src/Core/Manifest/VersionProvider.php Show resolved Hide resolved
@GuySartorelli
Copy link
Member

Also please don't tick boxes in the checkbox that aren't correct. i.e. "CI is green" was ticked but CI is very obviously not green 😅

@GuySartorelli
Copy link
Member

i only did some quick tests on my local project and it seemed to work at first glance but obviously the return values are not the ones expected in the tests.

The current tests are basically feeding in dummy composer.lock files (or content, haven't actually looked at them this is from memory), which obviously won't affect the composer runtime API.
I think we can ignore what the actual versions are for the tests now and just trust that composer isn't lying - so just check that our method outputs a SEMVER compliant string using composer/semver

@lekoala lekoala changed the base branch from 5.1 to 5 February 26, 2024 08:14
@lekoala
Copy link
Contributor Author

lekoala commented Feb 26, 2024

i only did some quick tests on my local project and it seemed to work at first glance but obviously the return values are not the ones expected in the tests.

The current tests are basically feeding in dummy composer.lock files (or content, haven't actually looked at them this is from memory), which obviously won't affect the composer runtime API. I think we can ignore what the actual versions are for the tests now and just trust that composer isn't lying - so just check that our method outputs a SEMVER compliant string using composer/semver

yes, that's exactly why it fails
i've updated the test it's only very basic for now but it should pass
the fixtures could be removed if we are happy with this

@lekoala
Copy link
Contributor Author

lekoala commented Feb 26, 2024

  • It’d be worth testing the performance overhead of the runtime API (it looks like it’ll be very minimal) and seeing if we can remove our caching. There’s nothing inherently brittle about the caching we have in place, but less code to maintain is less code to maintain 😄

from what i see, it prevents loading the installed.php file which is a 2k line array. Not sure what is faster, instantiating a cache interface then get/set value from it or read a 2k array that is going to be opcached anyway.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Tests are passing and works well locally. Just needs a changelog entry, but that's obviously a separate PR to silverstripe/developer-docs
@kinglozzer do you want any further changes? I agree that removing the caching would be ideal but it's also not really a problem if it stays.

Copy link
Member

@kinglozzer kinglozzer left a comment

Choose a reason for hiding this comment

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

One change, otherwise good to go I think. Thanks @lekoala

composer.json Outdated Show resolved Hide resolved
@lekoala
Copy link
Contributor Author

lekoala commented Feb 27, 2024

i've also deleted the fixtures

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you!
Please don't forget to open a PR to silverstripe/developer-docs to add a quick note to the 5.2.0 changelog.

@GuySartorelli GuySartorelli merged commit 4f3282b into silverstripe:5 Feb 27, 2024
15 checks passed
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.

3 participants