Skip to content
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

Phar only package / shim #5998

Closed
gjuric opened this issue Sep 12, 2021 · 18 comments
Closed

Phar only package / shim #5998

gjuric opened this issue Sep 12, 2021 · 18 comments

Comments

@gjuric
Copy link

gjuric commented Sep 12, 2021

Feature request

It would be nice to have a phar only composer package, the same way phpstan/phpstan is installed (previously phpstan/phpstan-shim) or psalm (via psalm/phar). That would skip the need to have a separate composer file in tools/php-cs-fixer as advised in the installation instructions.

@SpacePossum
Copy link
Contributor

Hi and thanks for proposing this,

Is this different than the current phar release we do?

https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.1.0/doc/installation.rst#locally

Download the php-cs-fixer.phar file and store it somewhere on your computer.

@gjuric
Copy link
Author

gjuric commented Sep 13, 2021

Yes, it's different because version (and installation) of phar is then managed by composer. As far as I can tell it is just a separate repository with the phar file published.

For example, phpstan's development is made in https://github.com/phpstan/phpstan-src but installation is made from https://github.com/phpstan/phpstan where only the phar is published. Same things with psalm, development is made in https://github.com/vimeo/psalm but there is separate phar only repo: https://github.com/psalm/phar

@gjuric
Copy link
Author

gjuric commented Sep 13, 2021

I've created a repository to show what I mean. You can test it out by running composer require --dev gjuric/php-cs-fixer-phar

@keradus
Copy link
Member

keradus commented Sep 21, 2021

To be honest it's on my TODO list, sth like php-cs-fixer/shim, but not top prio

@keradus
Copy link
Member

keradus commented Sep 21, 2021

I'm not sure if we should make main composer repo to be the shim (=phar) , as some folks are downloading the tool for custom fixers purpose.

we also have a mess of friendsofphp namespaces not fully focusing on PHP CS Fixer, and moving main repo to php-cs-fixer org would be a mess (ppl are still installing fabbot/php-cs-fixer we abandoned years ago)

@gjuric
Copy link
Author

gjuric commented Sep 22, 2021

I understand, on the other hand having a new org would be a chance to clear up the stale issues and PRs :)

If you need any help with it please let me know.

@keradus
Copy link
Member

keradus commented Sep 22, 2021

take a look at generator branch of our website: https://github.com/php-cs-fixer/php-cs-fixer.github.io
CI (now, Travis, maybe GitHub Actions one day) runs daily and checks for new releases in main repo - if any, it's updating the main branch.

i can imagine sth similar for shim - generator branch triggers job daily and create new shim tags for any new (and >=3.0) tags of main repo. would you be willing to propose such automation? if so, I can create a dummy repo in our namespace, where you can raise the PR proposal ;)

@gjuric
Copy link
Author

gjuric commented Sep 23, 2021

OK, I will take a look at how to create a Github Action that runs daily, runs self-update on the phar and if the updated phar is newer tags a commit.

I can play with it in my own brunch until I make it work, once I am done you can create a dummy repo.

@spideyfusion
Copy link

@gjuric Have you made any progress on this? I would be willing to lend a hand if needed.

Having a shim release variant would be super convenient for including the tool into existing projects without requiring developers to alter their scripts and directory structure.

We have been using irstea/php-cs-fixer-shim up until now, but sadly, it doesn't appear to be maintained anymore.

@gjuric
Copy link
Author

gjuric commented Oct 6, 2021

If you have the time to take a go at it go ahead, I am in the process of moving offices so my time is limited at the moment.

@gjuric
Copy link
Author

gjuric commented Oct 7, 2021

You can see my PoC in https://github.com/gjuric/PHP-CS-Fixer-phar/blob/6c43975202a3c4751fce417a1db564f648cf03b7/build.sh but I am having issues making Github run this action on schedule.

@gjuric
Copy link
Author

gjuric commented Oct 8, 2021

@keradus I've managed to make it work, although there are couple of issues:

  1. Github Actions that are run on a schedule can only run on the default branch
  2. I made it work for v3 only, I believe this should be fine
  3. composer.json requirements would need to be modified manually since the dependencies need to by stripped from the source version, but there is still a PHP dependency that we would have to update in the future

You can see an example of a successful build and an "empty" build.

How would you like to proceed?

@keradus
Copy link
Member

keradus commented Oct 8, 2021

I love you picked it up!
Let me give a sad warning on start - I definitely like the idea and love to support, but cannot guarantee everyday commitment into review/discussion/testing. I hope some more folks from community can help ;)

  1. Github Actions that are run on a schedule can only run on the default branch

I believe we need to find how we want to handle it. Maybe .gitattributes to not expose the generation part to shim releases? also, pls link the docs for that limitation, I would love to get familiar.

  1. I made it work for v3 only, I believe this should be fine

let's make it for v3.0.0 + only indeed

  1. composer.json requirements would need to be modified manually since the dependencies need to by stripped from the source version, but there is still a PHP dependency that we would have to update in the future

if you read source data from friendsofphp/php-cs-fixer, you can actually read composer.json data and apply to php-cs-fixer/shim composer.json.

You can see my PoC in https://github.com/gjuric/PHP-CS-Fixer-phar/

Also, shortly took a look at your proposal. We have a tendency to release multiple versions same hour, eg we did it with just 2 new versions of 3.2.0 and 3.2.1.
Your proposal would pick up 3.2.1, but would ignore 3.2.0. I believe we should cover this case

How would you like to proceed?

Please, raise a PR at https://github.com/PHP-CS-Fixer/shim and let's continue the discussion on PR level.
Also, please share not only code/files, but also describe the approach you suggest to use.

@keradus
Copy link
Member

keradus commented Oct 31, 2021

@gjuric , would you like to continue on this topic ?

@keradus
Copy link
Member

keradus commented Feb 7, 2022

hey folks, would you like to try out https://github.com/PHP-CS-Fixer/shim and share your experience with it?

@keradus keradus changed the title Phar only package Phar only package / shim Feb 7, 2022
@trsteel88
Copy link

Looks good. Thanks @keradus

@gjuric
Copy link
Author

gjuric commented May 4, 2022

I've been using it for a while and it works great, there is only one small issue.

It would be nice if the file was called php-cs-fixer.phar instead of php-cs-fixer so PhpStorm parses the context of the phar file and does not complain when working on .php-cs-fixer.dist.php that PhpCsFixer\Finder or PhpCsFixer\Config does not exist. Also auto-complete for those classes would then work as well.

If you want to keep the vendor/bin/php-cs-fixer file maybe you could do the same thins as phpstan does, see here and here.

@gjuric
Copy link
Author

gjuric commented Dec 16, 2022

I've been running the shim release for almost a year now and it works great, so I will close this issue and open a new one regarding my last comment.

@gjuric gjuric closed this as completed Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants