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

Feature: Use composer/semver to detect PHP version ranges #119

Draft
wants to merge 3 commits into
base: 1.23.x
Choose a base branch
from

Conversation

boesing
Copy link
Member

@boesing boesing commented Aug 10, 2022

Q A
Bugfix yes
BC Break no
New Feature yes

Description

By using composers own composer/semver library, we are able to detect PHP version ranges from almost every composer-compatible constraint.

Fixes #87

…version ranges

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing boesing linked an issue Aug 10, 2022 that may be closed by this pull request
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing boesing requested a review from Ocramius August 10, 2022 19:05
@@ -25,6 +27,16 @@ ADD laminas-ci.schema.json /action/
COPY --from=compiler /usr/local/source/dist/main.js /action/
RUN chmod u+x /action/main.js

# Setup PHP
Copy link
Member Author

Choose a reason for hiding this comment

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

I know, what the fuck. But since I am not aware on how to actually merge multiple container together, I've thought I can do it like this.

This will:

  1. ensure that renovate is able to bump versions
  2. provide alpine PHP version within this container
  3. allows us to run PHP natively within the matrix container while the container itself is optimized for nodejs

I hope we can keep it like this as I tried to install php8-cli via apk which is PHP 8.1.1 which is not supported by the "boxed" PHAR of my composer-semver docker image...

Choose a reason for hiding this comment

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

Does the matrix container run any PHP? What happens with PHP 8.0 or PHP 7.4 runs? nm, I see where it's used now

package.json Show resolved Hide resolved
@@ -5,9 +5,9 @@
},
"type": "commonjs",
"devDependencies": {
"@types/node": "^18.6.4",

Choose a reason for hiding this comment

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

did you move this or a tool? Only I've seen tools move it the other way around before.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this was due to a merge conflict. So maybe I did that.

@@ -25,6 +27,16 @@ ADD laminas-ci.schema.json /action/
COPY --from=compiler /usr/local/source/dist/main.js /action/
RUN chmod u+x /action/main.js

# Setup PHP

Choose a reason for hiding this comment

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

Does the matrix container run any PHP? What happens with PHP 8.0 or PHP 7.4 runs? nm, I see where it's used now

src/config/app.ts Show resolved Hide resolved

export function satisfies(version: string, constraint: string): boolean {
try {
execSync(`/usr/local/bin/composer-semver.phar semver:match "${version}" "${constraint}" > /dev/null`);
Copy link
Member

Choose a reason for hiding this comment

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

There are some edge case differences between how composer and npm resolve semantic versions (or so I'm led to believe), but I don't see why we aren't using the official semver module used by npm https://www.npmjs.com/package/semver and not even require PHP here

Choose a reason for hiding this comment

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

To clarify, I know this PR is removing it and replacing it with composer, I'm just wondering why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we do parse composer.json, that file could provide constraints which are mostly supported by composer but i.e. not by the NPM package.

I have not tested this yet, but composer provides some quirks:

There might be other quirks but since I do not want to hassle with these in this component since we should focus on detecting the correct supported version(s) based on what is supported by composer, we should use composers own logic to detect whats allowed and what not.
But thats just my opinion here.

Choose a reason for hiding this comment

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

That first one would be a valid constraint in node aswell FYI. I did look through the docs for both npm and composer and the comma vs space was the only one I found. Which IMO is npm's mistake here as I know of other examples where a comma is perfectly valid (e.g. go).

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no strong opinion on this, I just would prefer not to manipulate the constraint to "make it work" 😅
But I am open for every other suggestion. Should we report this upstream?

Choose a reason for hiding this comment

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

what about calling the php container via docker here instead? I'm not that familiar with how DinD works on github specifically but something like:

execShell('docker run php /usr/local/bin/composer-semver.phar semver:match "${version}" "${constraint}" > /dev/null'). After adding composer-semver to the php container instead?

Copy link
Member

Choose a reason for hiding this comment

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

Won't work; you're operating inside a container, so the container can not operate as a docker host.

As far as other suggestions... I don't have any. I used the NPM semver package originally, as I assumed it was compatible with how Composer handled semver. Knowing that they're different, we can either:

  • Call on a PHP executable (as proposed here)
  • Write our own TS utility that passes the same tests as composer/semver (lots more effort, plus it can go out-of-date)

It might make sense to re-do this action such that it uses a dedicated container where we use a PHP application, as we've done with the CI action and the automatic releases action.

Copy link
Member Author

Choose a reason for hiding this comment

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

Won't work; you're operating inside a container, so the container can not operate as a docker host.

Thats actually not true. It definitely works, I am just not sure if it works within GHA.
One has to mount the docker socket to the container tho.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am still wondering if we should just report upstream that they can't handle , in the constraint?
Maybe its a fixable issue for them?

Choose a reason for hiding this comment

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

Issue opened npm/node-semver#468, we can see what they say

@internalsystemerror
Copy link
Member

Everything checks out though. Looks good to merge if we decide to go down this route, but I'm not convinced its necessary.

COPY --from=php /usr/local/etc/* /usr/local/etc
COPY --from=php /usr/local/lib/php/* /usr/local/lib/php
COPY --from=php /usr/lib/* /usr/lib
COPY --from=php /lib/* /lib

Choose a reason for hiding this comment

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

it's these parts that worry me mixing the languages. if they both rely on a linked lib in different versions for instance.

Copy link
Member

Choose a reason for hiding this comment

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

Similar thoughts: would prefer a composer install happening with our base image, but we can improve on that later

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need for composer install, thats actually to execute the composer-semver.phar I am building with https://github.com/boesing/composer-semver-docker

But the more I think about this, the more it annoys me that it has to be that hacky...

COPY --from=php /usr/local/etc/* /usr/local/etc
COPY --from=php /usr/local/lib/php/* /usr/local/lib/php
COPY --from=php /usr/lib/* /usr/lib
COPY --from=php /lib/* /lib
Copy link
Member

Choose a reason for hiding this comment

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

Similar thoughts: would prefer a composer install happening with our base image, but we can improve on that later

@@ -0,0 +1,11 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

instead of issue-86, would it make sense to name this according to what it does?

@boesing
Copy link
Member Author

boesing commented Aug 11, 2022

I've raised an "issue" in the NPM semver implementation:
DefinitelyTyped/DefinitelyTyped#61669

@internalsystemerror
Copy link
Member

As I understand it, that repository is for the typescript mappings for everything @types/ related, including @types/semver. The implementation for the semver library would be https://github.com/npm/node-semver. I've opened an issue for that one here npm/node-semver#468. 🤞

@boesing boesing marked this pull request as draft August 11, 2022 22:15
@internalsystemerror
Copy link
Member

It appears there are some other differences, so I think we have to go this route after all.

@Ocramius Ocramius changed the base branch from 1.14.x to 1.15.x August 18, 2022 11:52
@boesing boesing changed the base branch from 1.15.x to 1.23.x December 23, 2022 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants