symplify / monorepo-builder

Composer tools to maintain a monorepo

Home Page:https://www.tomasvotruba.cz/blog/2019/02/18/how-we-automated-shopsys-packages-release-from-2-days-to-1-console-command/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Namespacing Issue after upgrading from 8.0 to 11.0

DannyDanDan92 opened this issue · comments

Our API currently uses major version 8 of this package. However, we're experiencing issues when trying to upgrade to major version 11. When I update the symplify/monorepo-builder package and run composer update, I can see that it is installing the correct package:

- Installing symplify/monorepo-builder (11.1.28.72): Extracting archive

However when I then go into the vendor/symplify/monorepo-builder/composer.json file, these are the contents:

{
    "name": "symplify/monorepo-builder",
    "description": "Prefixed version of Not only Composer tools to build a Monorepo.",
    "license": "MIT",
    "require": {
        "php": ">=7.2"
    },
    "bin": [
        "bin/monorepo-builder"
    ],
    "extra": {
        "branch-alias": {
            "dev-main": "10.3-dev"
        }
    }
}

When I then compare this to the source code composer.json, it looks completely different. Mine seems to be referring to the prefixed version package which has been abandoned.

Additionally, I have custom Workers which worked on version 8.0 as they implemented the ReleaseWorkerInterface. However, now that I've upgraded from 8.0 to 11.0, running my tests in PHPUnit tells me that the Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface doesn't exist (See below).

1) Peracto\Release\Tests\ReleaseWorker\SkeletonPeractoReleaseWorkerTest::testUpdateVersionDescription with data set #0 ('100.0', '100.0.0')
Error: Interface "Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface" not found

/Users/dgriffiths/PhpstormProjects/peracto/utils/release/src/ReleaseWorker/SkeletonPeractoReleaseWorker.php:8
/Users/dgriffiths/PhpstormProjects/peracto/vendor/symfony/error-handler/DebugClassLoader.php:296
/Users/dgriffiths/PhpstormProjects/peracto/utils/release/tests/ReleaseWorker/SkeletonPeractoReleaseWorkerTest.php:15
/Users/dgriffiths/PhpstormProjects/peracto/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
/Users/dgriffiths/PhpstormProjects/peracto/vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
/Users/dgriffiths/PhpstormProjects/peracto/vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
/Users/dgriffiths/PhpstormProjects/peracto/vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
/Users/dgriffiths/PhpstormProjects/peracto/vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
/Users/dgriffiths/PhpstormProjects/peracto/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:661

Is there any autoloading issues that need to be addressed? As following the documentation for this package out of the box doesn't seem to work, the namespaces do not seem to be being recognised.

Can someone advise how to resolve this problem?

Looking at the class, it seems exists:

https://github.com/symplify/monorepo-builder/blob/11.1.28.72/packages/Release/Contract/ReleaseWorker/ReleaseWorkerInterface.php

The issue probably missing autoload in prefixed composer.json:

{
"name": "symplify/monorepo-builder",
"description": "Prefixed version of Not only Composer tools to build a Monorepo.",
"license": "MIT",
"require": {
"php": ">=7.2"
},
"bin": [
"bin/monorepo-builder"
],
"extra": {
"branch-alias": {
"dev-main": "10.3-dev"
}
}
}

Could you try add manually in the path: vendor/symplify/monorepo-builder/composer.json

    "autoload": {
        "files": [
            "vendor/autoload.php"
        ]
    }

and verify if that works ? If that works, we can patch it to include the vendor/autoload.php in prefixed composer.json.

autoload seems need to be generated after registered in composer.json, so definatelly need new release for that, I will try apply it.

@DannyDanDan92 11.1.29.72 just tagged https://github.com/symplify/monorepo-builder/releases/tag/11.1.29.72 , please verify if that works now, thank you.

@samsonasik Thank you for responding and releasing a new version in attempt to fix this problem.

In a drastic attempt to get this working after the new version release, I ran the following locally:

rm -rf vendor
rm composer.lock
composer install
composer dump-autoload -o

After then running my Unit test again, I'm afraid it presents exactly the same stack trace that I originally posted in this thread.

I also tried to clear my test cache using APP_ENV=test ./bin/console.php cache:clear, just to rule cache out as the issue.

Unfortunately, I don't have any additional debug information to provide at this point.

what error have you get? could you create simple reproducible repository with step to reproduce? Thank you.

@samsonasik Heres the repository: https://github.com/DannyDanDan92/monorepo-builder-test

Once you've clone it, please run the following:

composer install
./vendor/bin/simple-phpunit

This should show the following error:

1) App\Tests\Unit\SkeletonReleaseWorkerTest::testFooBar
Error: Interface "Symplify\MonorepoBuilder\Release\Contract\ReleaseWorker\ReleaseWorkerInterface" not found

/Users/dgriffiths/PhpstormProjects/my_project_directory/src/Worker/SkeletonReleaseWorker.php:8
/Users/dgriffiths/PhpstormProjects/my_project_directory/vendor/symfony/error-handler/DebugClassLoader.php:296
/Users/dgriffiths/PhpstormProjects/my_project_directory/tests/Unit/SkeletonReleaseWorkerTest.php:12

I see, the bootstap prefix should be Symplify\MonorepoBuilder\\ instead of just MonorepoBuilder:

if (strpos($class, 'MonorepoBuilderPrefix') === 0 || strpos($class, 'MonorepoBuilder\\') === 0) {

@DannyDanDan92 11.1.30.72 just released https://github.com/symplify/monorepo-builder/releases/tag/11.1.30.72

That's fixed it,I tested locally and it is working ok:

PHPUnit 9.5.27 by Sebastian Bergmann and contributors.

Testing 
R                                                                   1 / 1 (100%)

Time: 00:00.017, Memory: 10.00 MB

There was 1 risky test:

1) App\Tests\Unit\SkeletonReleaseWorkerTest::testFooBar
This test did not perform any assertions

/Users/samsonasik/www/monorepo-builder-test/tests/Unit/SkeletonReleaseWorkerTest.php:15

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.

Great stuff, thank you!