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

Add PHPStan Github Action #38

Merged
merged 1 commit into from
Dec 19, 2019
Merged

Add PHPStan Github Action #38

merged 1 commit into from
Dec 19, 2019

Conversation

rvanlaak
Copy link
Member

@rvanlaak rvanlaak commented Dec 5, 2019

PHPStan baseline is added to ignore current state. Baseline file should get removed together with #39

@rvanlaak rvanlaak mentioned this pull request Dec 5, 2019
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you

.github/workflows/static-code-analysis.yml Outdated Show resolved Hide resolved
phpstan.neon Outdated Show resolved Hide resolved
.github/workflows/static-code-analysis.yml Show resolved Hide resolved
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method DOMNode\\:\\:setAttribute\\(\\)\\.$#"
Copy link

Choose a reason for hiding this comment

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

Is it because of the dom extension missing on the phpqa image?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not. Had this inconsistency on another project as well. Typehinting it as DOMElement instead solves this error.

The object actually isn't a DOMNode. This is because of the return signature on appendChild in PHP core.

Copy link

Choose a reason for hiding this comment

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

Btw, would be great to document how to use jakzal/phpqa with github actions. I'd appreciate a PR if you have some spare time. Otherwise I'll try to do it in the next couple of weeks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will send you a PR once this one is ready 👍

Locally the baseline file gets used. Any idea why it's not used by Github checks?

Copy link

Choose a reason for hiding this comment

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

Make sure you're testing with the latest image locally. PHPStan was recently updated.

This was referenced Dec 6, 2019
@rvanlaak rvanlaak force-pushed the githubaction-phpstan branch 2 times, most recently from 4b7f002 to 2195817 Compare December 6, 2019 14:22
@rvanlaak
Copy link
Member Author

rvanlaak commented Dec 6, 2019

Having problems with getting the tests green. Although using make static passes locally, it fails remotely.

My current assumption is that a working directory volume isn't mounted under /project. Can't get the volume nor analyzing the checked out working directory right.

@odolbeau probably the same applies to #40 as tests are way too fast there. Can you make the cs-fixer output more verbose?

@odolbeau
Copy link
Member

odolbeau commented Dec 7, 2019

@rvanlaak I introduced a "error" on purpose on #40 & it looks like it's working like a charm: https://github.com/php-translation/symfony-storage/pull/40/checks?check_run_id=337944668

@jakzal
Copy link

jakzal commented Dec 7, 2019

Why do we need to mount the /project? Doesn’t github actions mount the working directory automatically?

Have you tried:

    working-directory: ${{ github.workspace }}

I read somewhere it might not work with uses.

If everything fails we can add a WORKING_DIRECTORY env variable to jakzal/phpqa and change the working path in the entry point.

composer.json Outdated
@@ -10,6 +10,7 @@
],
"require": {
"php": "^7.2",
"ext-intl": "*",
Copy link
Member

Choose a reason for hiding this comment

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

Is this really a hard requirement?

@odolbeau
Copy link
Member

@rvanlaak Could we consider using https://github.com/OskarStark/phpstan-ga for this Github action in order to move forward please?
We can obviously keep https://github.com/jakzal/phpqa usage in README. :)

runs-on: ubuntu-latest
services:
volumes:
- .:/project
Copy link

@jakzal jakzal Dec 11, 2019

Choose a reason for hiding this comment

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

I just did a quick test on one of my projects. You don't need to mount any directories, github will do it for you.

This is all you need:

name: Static code analysis

on: [pull_request]

jobs:
  phpstan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Run PHPStan
        uses: docker://jakzal/phpqa:php7.3-alpine
        with:
          args: sh -c 'composer install && phpstan analyze src/ -l 1'

Copy link

Choose a reason for hiding this comment

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

Actually, I think to make it work jakzal/phpqa needs to be updated to run composer etc.

- name: Run PHPStan
uses: docker://jakzal/phpqa:php7.3-alpine
with:
args: sh -c 'composer install && phpstan analyze src/'
Copy link

Choose a reason for hiding this comment

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

I have updated jakzal/phpqa to install composer dependencies if it is run as a github action (jakzal/phpqa#185).

As soon as docker hub builds images all you will need is args: phpstan analyze src/.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Then I'll change the action to running phpstan using the minimum required amount of code, and wait until the images are pushed before rerunning the build 👍

@rvanlaak
Copy link
Member Author

@jakzal thanks for letting the image run composer install 👏

@odolbeau @Nyholm PR is ready. Was able to remove lots of baseline items since the BC layer was removed in #39

Copy link
Member

@odolbeau odolbeau left a comment

Choose a reason for hiding this comment

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

Looks good for me, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants