denzyldick / phanalist

Performant static analyzer for PHP, which is extremely easy to use. It helps you catch common mistakes in your PHP code.
https://denzyldick.github.io/phanalist/
MIT License
127 stars 5 forks source link

Running in CI (github actions) #57

Closed mleczakm closed 6 months ago

mleczakm commented 6 months ago

Describe the bug I found it difficult to run script inside docker based on php:8.3-cli-alpine to use it in github actions. I've tried install it as composer dependency, it results in:

> phanalist
Detecting architecture.
CPU architecture: x86_64

Running phanalist on architecture: x86_64
sh: ./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist: not found

or in

/var/www/html $ sh ./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist
./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist: line 2: y
                                                                               �
                                                                                ���������ti: not found
./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist: line 1: ./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist: ELF: not foundline 2: 
y
�P: not found./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist: 
line 2: syntax error: unterminated quoted string

when script run directly, or in

Run curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/denzyldick/phanalist/main/bin/init.sh | sh
info: Downloading ${_url} ...
info: Saved ${_bin}
/__w/_temp/743ad242-cc1a-4bac-9405-d97a32c876ed.sh: line 2: /root/phanalist: not found

when run as github actions step inside same container on Github Actions:

      - name: Testing stateless ability
        run: |
          curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/denzyldick/phanalist/main/bin/init.sh | sh
          /root/phanalist

To Reproduce

  1. Build container with php based on php:8.3-cli-alpine
  2. Try to run script using either shell script or composer dependency

Expected behavior It should be possible to run script on cli alpine image with sh only using composer OR dependencies should be better described.

Desktop (please complete the following information):

Additional context As a workaround I managed to successfully run phanalist by copying it from docker container:

 FROM php:8.3-cli-alpine as php-base
#...
COPY --from=ghcr.io/denzyldick/phanalist:latest /bin/phanalist /usr/bin/phanalist
SerheyDolgushev commented 6 months ago

@mleczakm thanks for reporting! :)

I just tried to do the following:

  1. Created docker/aarch64-php8.3-cli-alpine:
    FROM --platform=linux/aarch64 php:8.3-cli-alpine
    COPY release/aarch64-unknown-linux-musl/phanalist /usr/bin/phanalist
  2. Build the image:
    docker build -f docker/aarch64-php8.3-cli-alpine -t aarch64php83alpine .
  3. Run phanalist:
    docker run aarch64php83alpine /usr/bin/phanalist -h

And I got the expected output:

A static analyser for your PHP project

Usage: phanalist [OPTIONS]

Options:
  -c, --config <CONFIG>                [default: ./phanalist.yaml]
  -s, --src <SRC>                      [default: ./src]
  -r, --rules <RULES>                  The list of rules to use (by default it is used from config)
  -o, --output-format <OUTPUT_FORMAT>  Possible options: text, json [default: text]
      --summary-only                   Output only summary
  -q, --quiet                          Do not output the results
  -h, --help                           Print help
  -V, --version                        Print version

It confirms that the released binary runs fine in php:8.3-cli-alpine. I am pretty sure it will also work for linux/x86_64 platform, but release/x86_64-unknown-linux-musl/phanalist needs to be used in that case.

And seems like there are 2 issues in your report:

  1. Composer runs ./vendor/denzyl/phanalist/release/x86_64-unknown-linux-gnu/phanalist for php:8.3-cli-alpine. Instead it should run release/aarch64-unknown-linux-musl/phanalist /usr/bin/phanalist (musl, but not gnu). @denzyldick can you please look into it?
  2. There are some issues with downloading compiled binary as part of GitHub action. @mleczakm can you please provide the output of the download? Is it actually saved into /root/phanalist?

The simplest solution here might be to download release/x86_64-unknown-linux-musl/phanalist in your GitHub actions. And use that:

curl https://raw.githubusercontent.com/denzyldick/phanalist/main/release/x86_64-unknown-linux-musl/phanalist -o phanalist
./phanalist -h

@mleczakm can you please try it?

mleczakm commented 6 months ago

Fetching binary directly works, but I created fix to init.sh to cover all this problems anyway. Pull request is waiting for action :)

SerheyDolgushev commented 6 months ago

Thanks a lot! https://github.com/denzyldick/phanalist/pull/61 is merged, and it seems to resolve this issue.