phpstan / phpstan-symfony

Symfony extension for PHPStan
MIT License
700 stars 89 forks source link

Can't use plugin in Github action #94

Closed vv12131415 closed 4 years ago

vv12131415 commented 4 years ago

I'm trying to install this plugin in separate bundle. But when I use it in github actions (https://github.com/OskarStark/phpstan-ga) I see something like this.


In Resolver.php line 443:

  Service 'rules.84' (type of PHPStan\Rules\Symfony\ContainerInterfacePrivate  
  ServiceRule): Multiple services of type PHPStan\Symfony\ServiceMap found: 0  
  304, 0327 (needed by $symfonyServiceMap in __construct())                    

In Autowiring.php line 50:

  Multiple services of type PHPStan\Symfony\ServiceMap found: 0304, 0327  

When I run it locally it does work perfectly, but not in github actions.

The project is https://github.com/sonata-project/SonataAdminBundle

If I need to move this to https://github.com/OskarStark/phpstan-ga I will.

ondrejmirtes commented 4 years ago

You're somehow registering the extension multiple times. If you share the branch where it happen I can take a look.

OskarStark/phpstan-ga isn't necessary.

vv12131415 commented 4 years ago

https://github.com/vladyslavstartsev/SonataAdminBundle/tree/phpstan-symfony-ga-fail

https://github.com/vladyslavstartsev/SonataAdminBundle/actions/runs/210655545

ondrejmirtes commented 4 years ago

I see the job is using the phpstan-ga action:

  phpstan:
    name: PHPStan
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: PHPStan
        uses: "docker://oskarstark/phpstan-ga"
        env:
          REQUIRE_DEV: true
        with:
          args: analyse -c .phpstan/phpstan.neon.dist

The problem comes from that - the action also contains the phpstan-symfony extension and on top of that, it uses phpstan/extension-installer. That's unfriendly because if you want to run PHPStan locally, it also dictates your project to use phpstan/extension-installer so that you don't include extension.neon and rules.neon manually. Which is unfortunately because not everyone wants or can use phpstan/extension-installer, making this action unusable.

I'd recommend you to run PHPStan in GitHub Actions as any other PHP code:

  static-analysis:
    name: "Static analysis"

    runs-on: "ubuntu-latest"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2.3.1"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@2.4.1"
        with:
          coverage: "none"
          php-version: "7.4"

      - name: "Cache dependencies"
        uses: "actions/cache@v2.1.0"
        with:
          path: "~/.composer/cache"
          key: "php-7.4-composer-${{ hashFiles('**/composer.json') }}"
          restore-keys: "php-7.4-composer-"

      - name: "Install dependencies"
        run: "composer update --prefer-dist --no-interaction --no-progress --no-suggest"

      - name: "PHPStan"
        run: "vendor/bin/phpstan analyse -c .phpstan/phpstan.neon.dist"
ondrejmirtes commented 4 years ago

The phpstan-ga action also isn't usable if the versions of PHPStan and extensions in it are different than in your composer.json. I'd say that it's only for basic usage for people that don't have PHPStan installed in their projects or don't use Composer.

vv12131415 commented 4 years ago

@ondrejmirtes thanks a lot!

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.