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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve Phar updater strategies #481

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

owenvoke
Copy link
Member

This depends on #480 to be merged first. 馃憤馃徎 See 477b05c for the actual changes.

What does this do:

  • Adds a new updater.phar_name config key, that, when set, will be used to set the name of the Phar file as stored on GitHub, GitLab, etc.
  • Cleans up the Updater/Provider

This solution appears to work for resolving the mentioned issue, however it could probably do with some testing elsewhere to ensure it doesn't break any existing applications.

Closes laravel-zero/laravel-zero#459

@nunomaduro
Copy link
Member

@owenvoke you need to rebase.

This makes sure that the Phar name is set for the GitHub Releases strategy.
@owenvoke
Copy link
Member Author

@nunomaduro, done. 馃憤馃徎 I have only tested these changes on the repo in the issue, so not sure if we want to do some further testing. 馃し馃徎

@sergix44
Copy link

Any news about this? What is preventing the merge?

@owenvoke
Copy link
Member Author

@sergix44, I think it was just needing further testing (on real-world projects). If you have a project, feel free to test this branch. 馃檪

caendesilva added a commit to hydephp/cli that referenced this pull request Dec 13, 2023
@@ -67,19 +69,27 @@ public function register(): void
$this->app->singleton(Updater::class, function () use ($build) {
$updater = new PharUpdater($build->getPath(), false, PharUpdater::STRATEGY_GITHUB);

$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$name = $composer['name'];
$composer = json_decode(file_get_contents($this->app->basePath('composer.json')), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a way to set the package name without Composer, as there is no real guarantee that the compiled binary is run in a directory with a composer.json file, nor do I think there should need to be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the composer.json within the Phar file. It should always exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's weird, because for me, it tries to load it from the working directory.
hydephp/cli@925f00b It could be due to how my paths are setup though, in which case this is my fault. Gonna check it out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is my bad. My application sets the working base path to be the working directory. For my usages, I would need this to be an absolute path, but that is probably not something Zero should worry about.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: Changing the line to the following works better for me.

$composer = json_decode(file_get_contents(__DIR__.'/../../../../../../composer.json'), true);

@caendesilva
Copy link
Contributor

caendesilva commented Dec 13, 2023

If you have a project, feel free to test this branch. 馃檪

Testing this branch now (hydephp/cli@4e2817a), but I'm erroring on this version.

It tries to download https://github.com/hydephp/cli/raw/v0.5.2/hyde/builds/hyde instead of https://github.com/hydephp/cli/raw/v0.5.2/builds/hyde

Checking for a new version...
=============================


In Updater.php line 338:

  file_get_contents(https://github.com/hydephp/cli/raw/v0.5.2/hyde/builds/hyde): Failed to open stream: HTTP request
  failed! HTTP/1.1 404 Not Found

Edit: I can at least confirm that this branch makes so I don't get the following error:

PHP Fatal error:  Uncaught ErrorException: include(): zlib: data error in phar://C:/Users/Caen/AppData/Roaming/Composer/vendor/hyde/cli/builds/hyde/.box/vendor/composer/ClassLoader.php:576
Stack trace:

[...]

PHP Fatal error:  Uncaught ErrorException: include(phar://C:/Users/Caen/AppData/Roaming/Composer/vendor/hyde/cli/builds/hyde/vendor/composer/../symfony/error-handler/Error/FatalError.php): Failed to open stream: phar error: internal corruption of phar "C:/Users/Caen/AppData/Roaming/Composer/vendor/hyde/cli/builds/hyde" (actual filesize mismatch on file "vendor/symfony/error-handler/Error/FatalError.php") in phar://C:/Users/Caen/AppData/Roaming/Composer/vendor/hyde/cli/builds/hyde/.box/vendor/composer/ClassLoader.php:576

So this should at least fix laravel-zero/laravel-zero#193 (comment)

@sergix44
Copy link

sergix44 commented Dec 13, 2023

If you have a project, feel free to test this branch. 馃檪

Testing this branch now (hydephp/cli@4e2817a), but I'm erroring on this version.

It tries to download https://github.com/hydephp/cli/raw/v0.5.2/hyde/builds/hyde instead of https://github.com/hydephp/cli/raw/v0.5.2/builds/hyde

Checking for a new version...
=============================


In Updater.php line 338:

  file_get_contents(https://github.com/hydephp/cli/raw/v0.5.2/hyde/builds/hyde): Failed to open stream: HTTP request
  failed! HTTP/1.1 404 Not Found

Mine is also a real world project, so 馃し
I dont know how many real world projects are needed before merging this fix, but in the mean time I fixed it like this:
Extend the original update strategy and sent the current phar name: sergix44/hestiacp-companion@f8167e7#diff-d033b3b431c042b24fe0c80c6deed53bf9eb3b69996a6348f57de3a6ed2ae490

And then set it as the update strategy: config/updater.php

Now the self update from the github releases should work as expected

@caendesilva
Copy link
Contributor

@owenvoke

Okay so I've done some more testing, after changing the Composer include to use a base path (see review comment) it seems like this works, in that the release is downloaded.

I still get a Phar corruption error during the installation
image

But what is weird is that the downloaded binary works when I run it, so something must be wrong when verifying the download?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants