Skip to content

Commit

Permalink
Merge pull request #76 from buggregator/feat/auto-version
Browse files Browse the repository at this point in the history
feat: use latest version from auto-incrementing file
  • Loading branch information
lotyp authored May 10, 2024
2 parents a4e80ea + 681820e commit 54c1e51
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function execute(
): int {
try {
// Print intro
$output->writeln(\sprintf('<fg=yellow;options=bold>%s</> <info>v%s</>', Info::NAME, Info::VERSION));
$output->writeln(\sprintf('<fg=yellow;options=bold>%s</> <info>v%s</>', Info::NAME, Info::version()));
$output->write(Info::LOGO_CLI_COLOR . "\n", true, OutputInterface::OUTPUT_RAW);

/** @var non-empty-string[] $senders */
Expand Down
20 changes: 19 additions & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class Info
{
public const NAME = 'Buggregator Trap';
public const VERSION = '1.7.0';
public const LOGO_CLI_COLOR = <<<CONSOLE
\e[44;97;1m \e[0m
\e[44;97;1m ▄█▀ ▀█▄ \e[0m
Expand All @@ -27,4 +26,23 @@ class Info
CONSOLE;

public const TRAP_ROOT = __DIR__ . '/..';
private const VERSION = 'experimental';

public static function version(): string
{
$versionPath = self::TRAP_ROOT . '/src/version.json';
$versionContents = file_get_contents($versionPath);

if ($versionContents === false) {
return self::VERSION;
}

$versionData = json_decode($versionContents, true);

if (!is_array($versionData) || !isset($versionData['.']) || !is_string($versionData['.'])) {
return self::VERSION;
}

return $versionData['.'];
}
}
2 changes: 1 addition & 1 deletion src/Sender/Frontend/Message/Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function jsonSerialize(): array
{
return [
'client' => $this->client,
'version' => Info::VERSION,
'version' => Info::version(),
'subs' => [
'events' => (object) [],
],
Expand Down
11 changes: 7 additions & 4 deletions src/Sender/Frontend/Message/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
final class Settings implements JsonSerializable
{
public function __construct(
public readonly string $number = Info::VERSION,
) {}
public readonly string $number;

public function __construct()
{
$this->number = Info::version();
}

public function jsonSerialize(): array
{
Expand All @@ -23,7 +26,7 @@ public function jsonSerialize(): array
'enabled' => false,
'login_url' => '/auth/sso/login',
],
'version' => Info::VERSION,
'version' => $this->number,
];
}
}
9 changes: 6 additions & 3 deletions src/Sender/Frontend/Message/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
final class Version implements JsonSerializable
{
public function __construct(
public readonly string $number = Info::VERSION,
) {}
public readonly string $number;

public function __construct()
{
$this->number = Info::version();
}

public function jsonSerialize(): array
{
Expand Down
4 changes: 3 additions & 1 deletion src/Sender/RemoteSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ final class RemoteSender extends SocketSender
{
private string $uuid;

private readonly string $clientVersion;

public function __construct(
string $uuid = null,
string $host = '127.0.0.1',
int $port = 9912,
private readonly string $clientVersion = Info::VERSION,
) {
$this->clientVersion = Info::version();
$this->uuid = $uuid ?? Uuid::generate();

parent::__construct($host, $port);
Expand Down

0 comments on commit 54c1e51

Please sign in to comment.