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

feat(composer): filter releases using php constraint #19851

Closed
wants to merge 2 commits into from

Conversation

rarkins
Copy link
Collaborator

@rarkins rarkins commented Jan 15, 2023

Changes

  • Adds extractedConstraints to composer.extract
  • Adds constraints to packagist.getPkgReleases
  • Adds function to cross compare and filter these against php releases

Context

Closes #18715

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@@ -415,6 +416,60 @@ export async function getPkgReleases(
version.matches(constraintValue, releaseConstraint)
);
});
} else {
if (constraintName === 'php') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ideally don't hardcode this so that it can be reused for other ecosystems in future without a rewrite (especially python and node)

Copy link
Contributor

@herndlm herndlm Jan 15, 2023

Choose a reason for hiding this comment

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

While skimming through the code yesterday I thought the filtering could be done directly in the packagist lookup. Was I wrong or did you out it here to be potentially reusable on purpose?
UPDATE: nevermind, understood it I think

Comment on lines +428 to +430
const phpVersions = (
await getPkgReleases(lookupConfig)
)?.releases.map((release) => release.version);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suggest that this is done once per run, for optimization reasons

Comment on lines +431 to +434
if (!phpVersions) {
logger.warn('Could not fetch php releases for compatibility check');
return null;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a huge problem if it ever happens, not sure whether to throw an ExternalHostError or not

Choose a reason for hiding this comment

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

You can cache this right? Because having to look this up for every single PHP run sounds wasteful. And if it happens, blow out and try again later?

Comment on lines +435 to +437
const matchingVersions = phpVersions.filter((version) =>
composerVersioning.matches(version, constraintValue)
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should also be done once per run per constraint

Comment on lines +452 to +455
const releaseMatchingVersions = phpVersions.filter(
(version) =>
composerVersioning.matches(version, releaseConstraint)
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should also be calculated once per run per constraint

Comment on lines +457 to +459
const isMatch = matchingVersions.every((version) =>
releaseMatchingVersions.includes(version)
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could also be cached per run

@rarkins rarkins mentioned this pull request Jan 15, 2023
@herndlm
Copy link
Contributor

herndlm commented Jan 15, 2023

👍 this also closes #2355 right? Because AFAIK there was no way to do this via packagist API.

@rarkins
Copy link
Collaborator Author

rarkins commented Jan 15, 2023

Yeah, they're kind of duplicates

@zharinov zharinov self-requested a review January 16, 2023 08:15
# Conflicts:
#	lib/modules/datasource/packagist/index.ts
#	lib/modules/manager/composer/extract.ts
@@ -14,6 +14,7 @@ export const ComposerRelease = z.object({
.transform((x) => x.url)
.nullable()
.catch(null),
require: z.object({ php: z.string() }).nullable().catch(null),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
require: z.object({ php: z.string() }).nullable().catch(null),
require:
.object({
php: z.string(),
})
.transform((x) => x.php)
.nullable()
.catch(null),

@@ -69,6 +71,12 @@ export function parsePackagesResponses(
dep.releaseTimestamp = composerRelease.time;
}

phpConstraint ??= composerRelease.require?.php;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
phpConstraint ??= composerRelease.require?.php;
phpConstraint ??= composerRelease.require;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we care for just single field inside nested structure, we transform it up for simpler retrieval.

@renovate-release
Copy link
Collaborator

🎉 This issue has been resolved in version 35.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2023
@rarkins rarkins deleted the feat/18715-php-lookup-constraints branch April 22, 2024 05:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP lookup constraints
5 participants