Giter Site home page Giter Site logo

phpstan-ga's Introduction

GithubAction for PHPStan

Usage

You can use it as a Github Action like this:

# .github/workflows/test.yml 

on:
  push:
    branches:
      - master
  pull_request:

name: Test

jobs:
  phpstan:
    name: PHPStan

    runs-on: ubuntu-latest

    steps:
    - name: "Checkout"
      uses: actions/checkout@v3

    - name: PHPStan
      uses: docker://oskarstark/phpstan-ga
      with:
        args: analyse src/

to use a specific level:

      uses: docker://oskarstark/phpstan-ga
      with:
-        args: analyse src/
+        args: analyse src/ --level=5

to install dev dependencies:

      uses: docker://oskarstark/phpstan-ga
+     env:
+       REQUIRE_DEV: true
      with:
        args: analyse src/

to allow dev dependencies:

      uses: docker://oskarstark/phpstan-ga
+     env:
+       ALLOW_DEV: true
      with:
        args: analyse src/

to skip checking the platform requirements:

      uses: docker://oskarstark/phpstan-ga
+     env:
+        CHECK_PLATFORM_REQUIREMENTS: false
      with:
        args: analyse src/

to use a phpstan.neon.dist configuration file, just drop the phpstan.neon.dist in your repository root and it will be taken into account.

You can copy/paste the .github folder (under examples/) to your project and thats all!

Docker

A Docker-Image is built automatically and located here: https://hub.docker.com/r/oskarstark/phpstan-ga

You can run it in any given directory like this:

docker run --rm -it -w=/app -v ${PWD}:/app oskarstark/phpstan-ga:latest analyse src/ --level=5

phpstan-ga's People

Contributors

alessandrominoccheri avatar core23 avatar davidgrayston avatar dbu avatar dependabot[bot] avatar garak avatar greg0ire avatar lyrixx avatar nyholm avatar oskarstark avatar preimers avatar staabm avatar szepeviktor avatar tdutrion avatar valentinloiseau avatar wirone avatar zaherg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpstan-ga's Issues

Weird error

I'm not sure if this is the right place to report this, but I'm getting the following error only when running github actions (the same version of phpstan is running on my local environment without problems):

https://github.com/dustin10/VichUploaderBundle/runs/2387875172?check_suite_focus=true

in case you can't expand the erroring section, the error is related to this line: https://github.com/dustin10/VichUploaderBundle/blob/1.17.1/tests/Fixtures/App/app/AppKernel.php#L10

and the error is

ParseError (syntax error, unexpected '|', expecting variable
(T_VARIABLE)) thrown while looking for class
Symfony\Bundle\FrameworkBundle\FrameworkBundle.

that looks absolutely incomprehensible to me

Automatically push the docker image

@OskarStark what do you think about adding a step into Github actions to push automatically the docker image?
I have seen in the docker hub that you push the image every minor usually.
Instead, we can create a step that every time you create a new release of phpstan-ga automatically pushes the docker.

We are using your same strategy here: https://github.com/phparkitect/arkitect-github-actions
But I have to remember every time to push the docker manually.

What do you think?

Composer install step silently fails

Steps to reproduce:

  1. Create a composer-application with requirements:
    {
        "require": {
            "php": "^7.3",
            "nunomaduro/larastan": "^0.7.5"
        }
    }
    We don't actually need larastan here, but it introduces a configuration file in vendor that we are going to load.
  2. Create a phpstan.neon file in the root directory with:
    includes:
     - vendor/nunomaduro/larastan/extension.neon
  3. Run the github action

Expected: an error message indicating that the composer install failed
Happened: an error message indicating that the vendor/nunomaduro/larastan/extension.neon file is missing.

Took me a bit of fiddling with the paths to debug it, but when you run the container locally, it actually throws an error that the composer install command failed, and then happily proceeds to run the analysis. I think it might be better if we add a check on whether composer install actually succeeded, and then bug out immediately? :)

Tags new versions

Async AWs uses this github action (thank you โค๏ธ)

The issue is, we use fixed versions (it prevents red CI on pull requests when a new version of phpstan detects new issue in the codebase)
But the last available tag is 1.0.1
Is it possible to tag the docker image (and/or this repo) when you release a new version that upgrade phpstan?

php extensions

I started playing with this action today and pretty quickly run into a 'dead end' as far as php extension based sources is concerned.

the check errors because the php-docker container does not contain the required php extensions (or at least they are not loaded/configured):

image

would it be possible to e.g. use a docker container which contains the most used/popular php extensions (or maybe those which are bundled with ubuntu by default or similar)

using different php versions

I can see this action uses a php 7.3 docker container.

as the results of a phpstan scan depend on the used php version it would be great if this action would support/document how one can run the action using php 7.2/7.1/7.0 etc.

'check suite has disabled re-running individual checks'

not sure why this happens, but it seems the phpstan-ga action is not re-runnable.

dont know whether this is something you can influence on your end, but it would be usefull to re-trigger a check (e.g. because the underlying docker image is updated/changed)

image

entrypoint.sh: line 26: syntax error: bad substitution

Since the last Update 1.10.0 I'm getting this error:

PHPStan - PHP Static Analysis Tool 1.10.45
Installed PHPStan extensions
  No dependencies installed. Try running composer install or update.
/entrypoint.sh: line 26: syntax error: bad substitution

Makes me wonder as line 26 doesn't contain any code: https://github.com/OskarStark/phpstan-ga/blob/master/entrypoint.sh

I tried downgrading like this in my yml file:
uses: docker://oskarstark/[email protected]

It failed because the docker image can't be pulled:

Pull down action image 'oskarstark/[email protected]'
Error: Docker pull failed with exit code 1

I also tried different ubuntu versions as I thought it could be that sh doesn't point to bash anymore, but it didn't help. Thanks for your awesome work anyway ๐Ÿ™‚๐Ÿ‘

Here is the full action setup:

  phpstan:
    name: phpstan
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup PHP environment
        uses: shivammathur/setup-php@v2
        with:
          coverage: none

      - name: Get Composer Cache Directory
        id: composer-cache
        run: |
          echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-composer-  

      - name: PHPStan
        uses: docker://oskarstark/phpstan-ga
        env:
          CHECK_PLATFORM_REQUIREMENTS: false
          REQUIRE_DEV: true
        with:
          args: analyse packages/ --level 8
    timeout-minutes: 20

When removing The PHP setup and cache steps it yields the same error:

  phpstan:
    name: phpstan
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: PHPStan
        uses: docker://oskarstark/phpstan-ga
        env:
          CHECK_PLATFORM_REQUIREMENTS: false
          REQUIRE_DEV: true
        with:
          args: analyse packages/ --level 8
    timeout-minutes: 20

allow more composer options?

In a project of mine, I need to allow minimum stability "dev" in composer, to be ready when my vendor will release a stable version.
This is not possible, or I may be missing something.

If not possible yet, it would be nice to have the possibility to run the following

composer config minimum-stability dev
composer config prefer-stable true

trigger_error is causing an error

I have a file with a line like the following

<?php
@\trigger_error('an error...', \E_USER_DEPRECATED);

Such file causes no errors in my local run of phpstan (version 0.12.90, the latest so far, with clean cache).
When my GitHub action is run, instead, that line is causing an error (and the action fails).

This is the job definition:

phpstan:
    runs-on: ubuntu-20.04
    name: PHPStan
    steps:
        - name: Checkout
          uses: actions/checkout@v2
        - name: PHPStan
          uses: docker://oskarstark/phpstan-ga
          env:
              REQUIRE_DEV: true
          with:
              args: analyse

Blocked plugin

phpstan/extension-installer (installed globally) contains a Composer plugin which is blocked by your allow-plugins config. You may add it to the list if you consider it safe. See https://getcomposer.org/allow-plugins
You can run "composer global config --no-plugins allow-plugins.phpstan/extension-installer [true|false]" to enable it (true) or keep it disabled and suppress this warning (false)

I tried to add in a step the suggested command: composer global config --no-plugins allow-plugins.phpstan/extension-installer true, no luck.

The following is my full config:

name: build

on: [push, pull_request]

env:
  COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
    phpstan:
        runs-on: ubuntu-20.04
        name: PHPStan
        steps:
            - name: Checkout
              uses: actions/checkout@v2
            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: 8.1
            - run: |
                composer require --no-update liip/imagine-bundle:"^2.0"
                composer global config --no-plugins allow-plugins.phpstan/extension-installer true
            - name: Update project dependencies
              uses: ramsey/composer-install@v1
            - name: PHPStan
              uses: docker://oskarstark/phpstan-ga
              env:
                  CHECK_PLATFORM_REQUIREMENTS: false
                  REQUIRE_DEV: true
              with:
                  args: analyse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.