-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start work on self-updater * Parse version from home/build * Fixup * Fix the updater, add logging * Add unit tests * Handle empty current version * phpcs * shellcheck ignore ws.update.php * shellcheck ignore ws.update.php * phpstan fixes * turn off phar.readonly * Fix test action * Pass release version tag to composer compile * Add pretty output for update script * Fixup * Fix phpstan * Move self-update command to plugin * Delete ws.update.php
- Loading branch information
1 parent
d88b2fd
commit 7621db9
Showing
23 changed files
with
571 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
set -e -o pipefail | ||
|
||
composer install | ||
composer compile | ||
composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Updater\Exception; | ||
|
||
use RuntimeException; | ||
|
||
class NoUpdateAvailableException extends RuntimeException | ||
{ | ||
private $currentVersion; | ||
|
||
public function __construct(string $currentVersion) | ||
{ | ||
parent::__construct('There is no update available for workspace.'); | ||
|
||
$this->currentVersion = $currentVersion; | ||
} | ||
|
||
public function getCurrentVersion(): string | ||
{ | ||
return $this->currentVersion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Updater\Exception; | ||
|
||
use RuntimeException; | ||
|
||
class NoVersionDeterminedException extends RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Updater; | ||
|
||
interface Output | ||
{ | ||
public function infof(string $info, ...$args): void; | ||
|
||
public function info(string $info): void; | ||
|
||
public function success(string $success): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Updater\Plugin; | ||
|
||
use my127\Console\Application\Application; | ||
use my127\Console\Application\Plugin\Plugin; | ||
use my127\Workspace\Application as BaseApplication; | ||
use my127\Workspace\Updater\Exception\NoUpdateAvailableException; | ||
use my127\Workspace\Updater\Exception\NoVersionDeterminedException; | ||
use my127\Workspace\Updater\Updater; | ||
use Phar; | ||
use RuntimeException; | ||
|
||
class Command implements Plugin | ||
{ | ||
/** @var Updater */ | ||
private $updater; | ||
|
||
public function __construct(Updater $updater) | ||
{ | ||
$this->updater = $updater; | ||
} | ||
|
||
public function setup(Application $application): void | ||
{ | ||
$application->section('self-update') | ||
->description('Updates the current version of workspace.') | ||
->action($this->action()); | ||
} | ||
|
||
private function action() | ||
{ | ||
return function () { | ||
$pharPath = Phar::running(false); | ||
if (empty($pharPath)) { | ||
echo 'This command can only be executed from within the ws utility.' . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
try { | ||
$this->updater->update(BaseApplication::getVersion(), $pharPath); | ||
} catch (NoUpdateAvailableException $e) { | ||
echo sprintf('You are already running the latest version of workspace: %s', $e->getCurrentVersion()) . PHP_EOL; | ||
exit(1); | ||
} catch (NoVersionDeterminedException $e) { | ||
echo 'Unable to determine your current workspace version. You are likely not using a tagged released.' . PHP_EOL; | ||
exit(1); | ||
} catch (RuntimeException $e) { | ||
echo sprintf('%s. Aborting self-update', $e->getMessage()) . PHP_EOL; | ||
exit(1); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Updater; | ||
|
||
class Release | ||
{ | ||
/** @var string */ | ||
private $url; | ||
|
||
/** @var string */ | ||
private $version; | ||
|
||
public function __construct(string $url, string $version) | ||
{ | ||
$this->url = $url; | ||
$this->version = $version; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function getVersion(): string | ||
{ | ||
return $this->version; | ||
} | ||
|
||
/** | ||
* Will return true if this release is more recent than the version provided. | ||
* | ||
* @param string $version Semver version number, e.g. 1.0.1, 0.2.0-alpha1 etc. | ||
*/ | ||
public function isMoreRecentThan(string $version): bool | ||
{ | ||
return version_compare($this->getVersion(), $version, '>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace my127\Workspace\Updater; | ||
|
||
use Symfony\Component\Console\Input\StringInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Symfony\Component\Console\Style\OutputStyle; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class StdOutput implements Output | ||
{ | ||
/** @var OutputStyle */ | ||
private $output; | ||
|
||
public function __construct() | ||
{ | ||
$this->output = new SymfonyStyle(new StringInput(''), new ConsoleOutput()); | ||
} | ||
|
||
public function infof(string $info, ...$args): void | ||
{ | ||
$this->output->writeln('<info>' . sprintf($info, ...$args) . '</info>'); | ||
} | ||
|
||
public function info(string $info): void | ||
{ | ||
$this->output->writeln('<info>' . $info . '</info>'); | ||
} | ||
|
||
public function success(string $success): void | ||
{ | ||
$this->output->success($success); | ||
} | ||
} |
Oops, something went wrong.