GithubHelp home page GithubHelp logo

php-cs-fixer-ga's Introduction

GitHub Action for PHP-CS-Fixer

NOTE: If you didn't create a .php-cs-fixer.dist.php file, do that first before adding this workflow. An example of this file created by the creators of PHP-CS-Fixer can be found here.

Usage

You can use it as a GitHub Action like this:

# .github/workflows/lint.yml

on: [push, pull_request]
name: Main
jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: PHP-CS-Fixer
      uses: docker://oskarstark/php-cs-fixer-ga

To use a custom config, e.g. --diff and --dry-run options:

# .github/workflows/lint.yml

on: [push, pull_request]
name: Main
jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: PHP-CS-Fixer
      uses: docker://oskarstark/php-cs-fixer-ga
+     with:
+       args: --config=.project.php_cs --diff --dry-run

Usage with cache

Add .php-cs-fixer.cache to .gitignore, then:

on: [push, pull_request]
name: Main
jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/cache@v3
        with:
          path: .php-cs-fixer.cache
          key: ${{ runner.OS }}-${{ github.repository }}-phpcsfixer-${{ github.sha }}
          restore-keys: |
            ${{ runner.OS }}-${{ github.repository }}-phpcsfixer-

      - name: PHP-CS-Fixer
        uses: docker://oskarstark/php-cs-fixer-ga

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

Usage with only changed files

It is also possible to run PHP-CS-Fixer just on your changed files. To achieve this, you can use the tj-actions/changed-files action to retrieve the changed files and subsequently use the result to create extra arguments with ---path-mode=intersection.

on: [push, pull_request]
name: Main
jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v38

      - name: Get extra arguments for PHP-CS-Fixer
        id: phpcs-intersection
        run: |
          CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n')
          if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
          echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
          echo "$EXTRA_ARGS" >> $GITHUB_ENV
          echo "EOF" >> $GITHUB_ENV

      - name: PHP-CS-Fixer
        uses: docker://oskarstark/php-cs-fixer-ga
        with:
          args: --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"

Docker

A Docker image is built automatically and located here: https://hub.docker.com/r/oskarstark/php-cs-fixer-ga

You can run it in any given directory like this:

docker run --rm -it -w=/app -v ${PWD}:/app oskarstark/php-cs-fixer-ga:latest

A picture is worth a thousand words

You can find a working and not working PR here: https://github.com/OskarStark/test-php-cs-fixer-ga/pulls

php-cs-fixer-ga's People

Contributors

andrew-miller-rakuten avatar bastien-phi avatar bocharsky-bw avatar brekitomasson avatar db306 avatar emodric avatar fabiofdsantos avatar franmomu avatar frovere avatar ikari7789 avatar lyrixx avatar michaelw90 avatar nyholm avatar oskarstark avatar relthyg avatar sebkolind avatar skylerkatz avatar tdutrion avatar timwolla avatar toshy 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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php-cs-fixer-ga's Issues

Remove/Reduce docker output

The github action status tab should not be polluted with docker information, but just show the actual php-cs-fixer output

Versioning

I want to share something I just learnt.

Looking at Github actions docs and the actions/checkout action, we can see that one should move tags.

Ie, create tags as we (PHP community) usually do. But also move the v2 tag with the latest release.

The benefit is that I (as a consumer of the action) can use OskarStark/php-cs-fixer-ga@v2 the same way as we use composers: ^2.0 syntax.

Im not sure that this is something we would like do to or if it is necessary. Since the updates here are just following releases of php-cs-fixer. I think it is easier for if one just did:

      - name: PHP-CS-Fixer
        uses: OskarStark/php-cs-fixer-ga@master
        with:
          args: --dry-run --diff-format udiff

Build images for other architectures

Currently, only the image for amd64 is built, which leaves Apple's new M1/M2 chips (arm64) out. An example of how this can be achieved can be found here. As far as I can see, it would be necessary

  • to install Qemu in addition to BuildX
  • define a list of desired architectures
  • to build these architectures

Do you think this would be possible?

Regression in 3.26.0 update

Today, we updated to 3.26.0 and our CI is now failing 100% of the time. There appears to be some version number mismatch in 3.26.0 where some things point at 3.26.0 and some at 3.40.0

Screenshot 2023-12-06 at 09 16 49 Screenshot 2023-12-06 at 09 18 17

3.25.0...3.26.0

Failure with 2.18.6

Hi,

Using the new 2.18.6 version of the action fails with the following log:

Pull down action image 'oskarstark/php-cs-fixer-ga:2.18.6'
  /usr/bin/docker pull oskarstark/php-cs-fixer-ga:2.18.6
  Error response from daemon: manifest for oskarstark/php-cs-fixer-ga:2.18.6 not found: manifest unknown: manifest unknown
  Warning: Docker pull failed with exit code 1, back off 6.792 seconds before retry.
  /usr/bin/docker pull oskarstark/php-cs-fixer-ga:2.18.6
  Error response from daemon: manifest for oskarstark/php-cs-fixer-ga:2.18.6 not found: manifest unknown: manifest unknown
  Warning: Docker pull failed with exit code 1, back off 6.632 seconds before retry.
  /usr/bin/docker pull oskarstark/php-cs-fixer-ga:2.18.6
  Error response from daemon: manifest for oskarstark/php-cs-fixer-ga:2.18.6 not found: manifest unknown: manifest unknown
Error: Docker pull failed with exit code 1

I suppose this is due to tag for the repo and Docker image missing.

##[error]Docker run failed with exit code 1

I am getting the following when trying to run the fixer for the first time:

PHP-CS-Fixer
5s
##[error]Docker run failed with exit code 1
Run docker://oskarstark/php-cs-fixer-ga
/usr/bin/docker run --name oskarstarkphpcsfixerga_490539 --label 10865d --workdir /github/workspace --rm -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e GITHUB_ACTIONS=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/Bootstrap-App-PHP-MVC/Bootstrap-App-PHP-MVC":"/github/workspace" oskarstark/php-cs-fixer-ga
Loaded config default.

In Finder.php line 569:
                                                                               
  **You must call one of in() or append() methods before iterating over a Finde  
  r.**     

Location of .php_cs

Where should we put the config file?

I'm getting this error

/usr/bin/docker run --name oskarstarkphpcsfixerga_bd9dca --label c27d31 --workdir /github/workspace --rm -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/seedien/seedien":"/github/workspace" oskarstark/php-cs-fixer-ga
PHP CS Fixer 2.16.3 Yellow Bird by Fabien Potencier and Dariusz Ruminski (83baf82)
Loaded config default from "/github/workspace/.php_cs".

In MultiplePcreFilterIterator.php line 86:
                                                              
  preg_match() expects parameter 2 to be string, array given  

`GITHUB_TOKEN` not used?

Taking a look through the code I can't see any usage of the GITHUB_TOKEN secret? If it's not needed, I'm more than happy to raise a PR to remove it from the example workflow etc.

Is it necessary?

Manifest for oskarstark/php-cs-fixer-ga:null

Hi, I saw that you now automatically provide a newest version of PHP CS Fixer, but I'm not sure how this is supposed to work. I get the following errors now with my unchanged config.

Pull down action image 'oskarstark/php-cs-fixer-ga:null'
  /usr/bin/docker pull oskarstark/php-cs-fixer-ga:null
  Error response from daemon: manifest for oskarstark/php-cs-fixer-ga:null not found: manifest unknown: manifest unknown
  Warning: Docker pull failed with exit code 1, back off 6.43[2](https://github.com/netgen-layouts/layouts-core/actions/runs/6095240765/job/16538389536#step:2:2) seconds before retry.
  /usr/bin/docker pull oskarstark/php-cs-fixer-ga:null
  Error response from daemon: manifest for oskarstark/php-cs-fixer-ga:null not found: manifest unknown: manifest unknown
  Warning: Docker pull failed with exit code 1, back off 5.4[3](https://github.com/netgen-layouts/layouts-core/actions/runs/6095240765/job/16538389536#step:2:3)8 seconds before retry.
  /usr/bin/docker pull oskarstark/php-cs-fixer-ga:null
  Error response from daemon: manifest for oskarstark/php-cs-fixer-ga:null not found: manifest unknown: manifest unknown
Error: Docker pull failed with exit code 1

actually fix cs via github action

would it be possible to actually fix the codestyling using php-cs-fixer with this action (e.g. by typing a certain command via a comment or similar)?

Look just on the pushed files

This is great tool because i can use php-cs-fixer without installing it on the project! :)
But i have one question, is it possible to check by gha just a files that was just pushed? I try to append this to my project, but as i see it checks EVERY file on the project, but i want to fix only "new", just pushed files.

Thanks in advance for answer!

PHP 8.3

PHP CS Fixer 3.40.0 (45a4530) I ate three cookies ๐Ÿช by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.2.13
Files that were not fixed due to errors reported during linting before fixing:

so it's failed when I update the code to PHP 8.3

Finder.php error

image
For some reason, Finder.php is my pain for every single check. I don't know how to fix this.

Please add tag for v3.22.0

The latest is currently v3.20.0 so it's a couple of versions behind.
v3.22.0 has added some new fixers and deprecated old ones. But if you replace the deprecated fixers, the run fails on Github Actions which runs 3.20.0

Not working on ubuntu-22.04

I tried to use the newer Ubuntu version, and I got the following errors:

Pull down action image 'oskarstark/phpstan-ga'
/usr/bin/docker pull oskarstark/phpstan-ga
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Using default tag: latest
Warning: Docker pull failed with exit code 1, back off 7.814 seconds before retry.
/usr/bin/docker pull oskarstark/phpstan-ga
Using default tag: latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Warning: Docker pull failed with exit code 1, back off 3.291 seconds before retry.
/usr/bin/docker pull oskarstark/phpstan-ga
Using default tag: latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Error: Docker pull failed with exit code 1

3.0.0-rc.1 failing tests

Is there a way to revert to an earlier version of php CS. There are some bugs that are causing the workflow to fail.

on: [push]
name: Main
jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs --diff --dry-run

How to use stable/tagged versions?

Lieber Oskar,

we've been using this action for years now (including auto-committing and pushing the fixups) and it is making our lives so much easier. Thank you for your work and for maintaining it!

There is one issue I came across recently and I wonder whether you have any ideas how to deal with it.

Some time ago, I had the impression that PHP-CS-Fixer was a bit unstable regarding its defaults and the way how it fixed particular CS issues. In some cases, it might change the code style in one way, only to revert it in the next release (probably a bug?). Or, new defaults are included and change the code in a way you don't like, so you have to update the config to keep it "stable".

All this lead to a desire to run this action with a stable, traceable version of PHP-CS-Fixer and being able to update to another version explicitly, without getting PHP-CS-Fixer updates out of the blue. Thus, I've been specifying uses: docker://oskarstark/php-cs-fixer-ga:3.26.0, but realized that doesn't cut it either.

Clearly the issue is that you need some kind of tagging and release numbering scheme that covers changes you make to this repo here (i. e. actions definition, build process, the entrypoint.sh script and similar). But in addition to that, we also have to deal with the version numbers/releases that go into the Docker image. Mostly this is the actual version of PHP-CS-Fixer being included, but potentially other libraries might matter as well (probably we can neglect this). And, of course, on top of this all goes the requirement that for new upstream releases, new action versions will be shipped automatically, not through a manual process.

Do you have any ideas how this could be addressed? Do you know of any examples of how people solve this "version of the upstream tool plus versioning of the build process" issue through release numbering?

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.