PHP-CS-Fixer icon indicating copy to clipboard operation
PHP-CS-Fixer copied to clipboard

Added docs for using GitHubActions caching to speedup CI

Open staabm opened this issue 4 years ago • 4 comments

closes https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4938

staabm avatar May 08 '20 08:05 staabm

ohh my.. getting a green build for a README.rst change is a real pain in the ass.

staabm avatar May 08 '20 19:05 staabm

Thanks for working on this! I haven't used github action yet so I cannot comment on the content itself. The readme is already very long IMHO, therefore I'm +0 on this change. I would love to see it be added to https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/3475 as that provides more dedicated doc files by topic.

SpacePossum avatar May 12 '20 16:05 SpacePossum

ohh my.. getting a green build for a README.rst change is a real pain in the ass.

@staabm what is the problem? It is very easy.

kubawerlos avatar May 26 '20 18:05 kubawerlos

For me, this cache solution has 3 problems:

  • It's very inefficient and potentially useless when it comes to concurrent multi-branch development (e.g. multiple devs working on lots of branches)
  • Time/storage/etc is still spent on creating cache when no files are changed that would affect the run of PHP CS Fixer
  • It requires a separate directory for the cache file. GitHub Actions cache v2 is capable of path representing a file - so this example seems weirdly overcomplicated for no reason.

Something that has a lock file such as composer doesn't have these issues because they don't get updated too frequently and hits the primary key so a new cache file isn't created every commit.

Implementing cache for PHP CS Fixer previously, I took a branch and file hash based approach. For example:

      - uses: actions/cache@v2
        with:
          path: .php_cs.cache
          key: ${{ runner.os }}-php-cs-fixer-${{ github.ref }}-${{ hashFiles('**/src/**', '**/tests/**') }}
          restore-keys: |
            ${{ runner.os }}-php-cs-fixer-${{ github.ref }}-
            ${{ runner.os }}-php-cs-fixer-refs/heads/main-

This will use the latest cache for that branch, then will failover to the main branch's latest cache. It will also only create a new cache when there are changes to files inside one of the directories which PHP CS Fixer will analyse - in this case src and tests.

There are probably other improvements that could be made or considered also, such as including the hash of the config file.

jackbentley avatar Oct 29 '21 17:10 jackbentley