overtrue / phplint

:bug: A tool that can speed up linting of php files by running several lint processes at once.
MIT License
972 stars 118 forks source link

[Question] How to define PHP version for Github Action #181

Closed mimmi20 closed 1 year ago

mimmi20 commented 1 year ago

Summary

I am using phplint as a Github action, and the action version got updated by Renovate from version 6.1.0 to version 9.0.3.

Now the Github action uses PHP 8.0, but I need it to run on PHP 8.1.

How may I set up the required PHP version?

Expected behaviour

no error

Actual behaviour

image

llaville commented 1 year ago

Hello @mimmi20

I am using phplint as a Github action, and the action version got updated by Renovate from version 6.1.0 to version 9.0.3.

Now the Github action uses PHP 8.0, but I need it to run on PHP 8.1.

How may I set up the required PHP version?

Sorry, but it's not yet possible to choose what PHP runtime to use. But If you just want to verify PHP 8 syntax (whatever feature version used 8.0, 8.1 or 8.2), please instead of

uses: "overtrue/phplint@9.0.3"

=> https://github.com/mimmi20/template/blob/master/.github/workflows/ci.yml#L243

use

uses: "overtrue/phplint@latest"

Digest sha256:fbd2816cea52f98ad38ff3d4ceb8e0054df84cc7c523f1031c4acc189a17dc3f

It now used the PHP 8.2 runtime !

llaville commented 1 year ago

BTW, there is an alternative to PHPLint GitHub Action, if you really want to use a specific PHP runtime.

Keep continue to setup PHP as you did at https://github.com/mimmi20/template/blob/master/.github/workflows/ci.yml#L230

And replace this step https://github.com/mimmi20/template/blob/master/.github/workflows/ci.yml#L242-L243 By a new one that will download the PHAR archive that will of course use the PHP runtime you've defined on shivammathur/setup-php

Something like :

curl -Ls https://github.com/overtrue/phplint/releases/download/9.0.3/phplint.phar -o /usr/local/bin/phplint \
&& chmod +x /usr/local/bin/phplint
llaville commented 1 year ago

My previous comment in images !!!

With PHP 8.2 runtime :

uses-setup-php-82

With PHP 8.1 runtime :

uses-setup-php-81

With PHP 8.0 runtime :

uses-setup-php-80

This is the limit to use PHAR built on release https://github.com/overtrue/phplint/releases/tag/9.0.3 Why: We use my project box-manifest to is the same as https://github.com/box-project/box v4 with a manifest (and BOX v4 min requirement is PHP 8.1)

If you want a PHAR that will run on PHP 8.0, we should compile it with BOX v3 (3.16.0)

llaville commented 1 year ago

@mimmi20 Finally, here is an operational GitHub Actions Workflow that works like a charm !!! (tested on my private repo)

On last line, you can use either a YAML config file or command options (like I did)

---
name: PHPLint

on:
  push:
  workflow_dispatch:

jobs:
  php-lint:
    name: "Linting with overtrue/phplint"

    runs-on: "${{ matrix.operating-system }}"

    strategy:
      fail-fast: false

      matrix:
        operating-system:
          - "ubuntu-20.04"
          - "ubuntu-22.04"

        php-version:
          - "8.1"
          - "8.2"

    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          repository: overtrue/phplint

      - name: "Install PHP"
        uses: shivammathur/setup-php@v2
        with:
          php-version: "${{ matrix.php-version }}"
          coverage: "none"

      - name: "Lint PHP"
        run: |
          curl -Ls https://github.com/overtrue/phplint/releases/download/9.0.3/phplint.phar -o /usr/local/bin/phplint
          chmod +x /usr/local/bin/phplint
          /usr/local/bin/phplint -vvv --no-cache
mimmi20 commented 1 year ago

Thanks