Skip to content

Getting error: /usr/local/bin/phpstan: line 2: syntax error: unexpected newline #10

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

Closed
bshaffer opened this issue Dec 7, 2021 · 14 comments

Comments

@bshaffer
Copy link

bshaffer commented Dec 7, 2021

When I use this action to run phpstan in my github actions, I get the following error:

/usr/local/bin/phpstan: line 2: syntax error: unexpected newline

Looking at the debug output, this is from the following command (which run locally, executes as expected):

  Command:  phpstan analyse appengine/flexible/tasks/src --autoload-file=appengine/flexible/tasks/vendor/autoload.php

You can see the full run log here

I have also tried setting the PHP version to 7.4 for both the composer action and the phpstan action, with no luck.

Any thoughts?

name: Lint

on: [push]

jobs:
  phpstan:
    steps:
    - uses: actions/checkout@v2
    - uses: php-actions/composer@v6 # or alternative dependency management
      with:
        args: --working-dir=logging --ignore-platform-reqs

    - uses: php-actions/phpstan@v3
      with:
        php_version: "8.0"
        path: logging/src
        autoload_file: logging/vendor/autoload.php
@g105b
Copy link
Member

g105b commented Dec 7, 2021

Hi @bshaffer ,

Thanks for raising this issue. I'll take a look into it for you later. In the meantime, would you be able to compare to https://github.com/php-actions/example-phpstan as a known working project?

Thanks,
Greg.

@bshaffer
Copy link
Author

bshaffer commented Dec 7, 2021

I ended up calling the binary directly instead of using this action

GoogleCloudPlatform/php-docs-samples#1569

@g105b
Copy link
Member

g105b commented Dec 7, 2021

Interesting. It would still be useful to use this action, so you can get your builds a lot quicker than 2 minutes. For debugging's sake, would you be able to delete the packages created on the repo here: https://github.com/orgs/GoogleCloudPlatform/packages?repo_name=php-docs-samples and then try again? I'm wondering whether there was a build error and something fishy has been cached.

@bshaffer
Copy link
Author

bshaffer commented Dec 9, 2021

@g105b done. Why would this be generating packages though?

@g105b
Copy link
Member

g105b commented Dec 9, 2021

It builds the PHP environment and PhpStan project, and caches the packages on the repository to achieve builds that only take a few seconds to execute. At the time of ghcr.io being a new deal, this was the only way to do it (storing packages on the repository, rather than within php-actions organisation). I'm open to other ways of working.

Did the removal fix the issue for you?

@bshaffer
Copy link
Author

bshaffer commented Dec 9, 2021

Because the repo I'm in has to run in multiple subdirectories (we have ~30 sample directories, each with their own composer.json), I do not think the action will work for me.

Previously I was splitting it out into 30 separate jobs, but this was more trouble than it's worth (the job was generating 30 individual checks that diluted the more important unit test checks). I do not believe it's current form (looping through all relevant directories and running composer install and phpstan in each of them) is supported by this action.

If I'm wrong and this use-case is supported, please let me know!

@g105b
Copy link
Member

g105b commented Dec 10, 2021

Thank you for the update, Brent. This is certainly something I will pay some attention to, as I'd like this action to be as accessible as possible to everyone. Running an individually-installed phpstan on each of the sample directories is indeed a workflow that isn't supported by this action, but maybe there are alternative approaches you could take? For instance, maybe something like this:

    - name: PHPStan
      uses: php-actions/phpstan@v3
      with:
        path: example/dir1 example/dir2 example/dir3 ...etc.

I understand that this might not satisfy your particular use case, but I thought it was worth sharing.

I'll close this issue now but feel free to continue the discussion - always happy to help.

@g105b g105b closed this as completed Dec 10, 2021
@MarcinOrlowski
Copy link

MarcinOrlowski commented Feb 14, 2022

Let me just add $0.03 here and point out that proposed path arguments format:

- name: PHPStan
  uses: php-actions/phpstan@v3
  with:
    path: example/dir1 example/dir2 example/dir3 ...etc.

is counter intuitive, as in yaml you should do normal list instead

path: 
    - example/dir1example/dir2
    - example/dir2
    - example/dir3
    - ...etc

@g105b
Copy link
Member

g105b commented Feb 14, 2022

Thank you @MarcinOrlowski . I've just opened issue #15 to track this.

@keironlowe-edriving
Copy link

keironlowe-edriving commented Mar 31, 2023

@g105b I've been experiencing the same issue, and I believe it's due to certain versions not being available on https://www.getrelease.download/, which you use in the bash script. For example, I need PHPStan version 1.8, but looking at the available releases, nothing before 1.9.0 is available.

As to why those versions are no longer available, I don't know. I've raised a discussion here (phpstan/phpstan#9116).

@g105b
Copy link
Member

g105b commented Mar 31, 2023

Thank you, I'll see if I can resolve as soon as I'm back home next week.

@keironlowe-edriving
Copy link

Thank you, I'll see if I can resolve as soon as I'm back home next week.

Thanks, although I'm not sure there is much you can do, it's the Github API not returning all the releases (https://api.github.com/repos/phpstan/phpstan/releases). Thanks anyway!

@flashlabs
Copy link

Had the same issue, phpstan upgrade to the one listed here helped.
Thanks @keironlowe-edriving 🙏

@g105b
Copy link
Member

g105b commented Nov 9, 2023

Hi all,

You may not be aware but I also maintain and contribute to the https://getrelease.download service (https://github.com/g105b/getrelease.download) - if it's this service that's not playing well when Github's APIs have an issue, it may be worth checking out where it's failing to fix it at the source.

I think what was happening was the Github API had a short outage, and getrelease.download tried to supply a non-existent release, which when executed in the Github Action, came back with the error message "/usr/local/bin/phpstan: line 2: syntax error: unexpected newline" (because it was probably trying to execute just an HTML error 404 page).

Please raise an issue over at the getrelease.download repo if this problem occurs, or if you want to track it there instead.

Thanks!

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

No branches or pull requests

5 participants