Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions build/src/php/VersionUpdater/DependencyProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace PhelWeb\VersionUpdater;

use Gacela\Framework\AbstractProvider;
use Gacela\Framework\Container\Container;
use Phel\Console\ConsoleFacade;
use Phel\Shared\Facade\ConsoleFacadeInterface;

/**
* @method Factory getFactory()
*/
final class DependencyProvider extends AbstractProvider
{
public const string FACADE_PHEL_CONSOLE = 'FACADE_PHEL_CONSOLE';

public function provideModuleDependencies(Container $container): void
{
$container->set(self::FACADE_PHEL_CONSOLE, function (Container $container) {
return $container->getLocator()->get(ConsoleFacade::class);
});
}
}
20 changes: 20 additions & 0 deletions build/src/php/VersionUpdater/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace PhelWeb\VersionUpdater;

use Gacela\Framework\AbstractFacade;

/**
* @method Factory getFactory()
*/
final class Facade extends AbstractFacade
{
public function updateTomlFile(): void
{
$this->getFactory()
->createPhelVersionUpdater()
->update();
}
}
34 changes: 34 additions & 0 deletions build/src/php/VersionUpdater/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace PhelWeb\VersionUpdater;

use Gacela\Framework\AbstractFactory;
use Gacela\Framework\Config\Config;
use Phel\Shared\Facade\ConsoleFacadeInterface;
use PhelWeb\VersionUpdater\Infrastructure\PhelVersionUpdater;

/**
* @method Config getConfig()
*/
final class Factory extends AbstractFactory
{
public function createPhelVersionUpdater(): PhelVersionUpdater
{
return new PhelVersionUpdater(
$this->getPhelConsoleFacade(),
$this->getConfigFileLocation(),
);
}

private function getPhelConsoleFacade(): ConsoleFacadeInterface
{
return $this->getProvidedDependency(DependencyProvider::FACADE_PHEL_CONSOLE);
}

private function getConfigFileLocation(): string
{
return $this->getConfig()->getAppRootDir() . '/../config.toml';
}
}
34 changes: 34 additions & 0 deletions build/src/php/VersionUpdater/Infrastructure/PhelVersionUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace PhelWeb\VersionUpdater\Infrastructure;

use Phel\Shared\Facade\ConsoleFacadeInterface;

final readonly class PhelVersionUpdater
{
private const string REGEX_PHEL_VERSION_FINDER = '/^phel_version\s*=\s*"[^"]*"/m';

public function __construct(
private ConsoleFacadeInterface $consoleFacade,
private string $configFile,
) {
}

public function update(): void
{
$configContent = file_get_contents($this->configFile);

$phelVersion = $this->consoleFacade->getVersion();
$updatedContent = preg_replace(
self::REGEX_PHEL_VERSION_FINDER,
'phel_version = "' . $phelVersion . '"',
$configContent
);

if ($updatedContent !== $configContent) {
file_put_contents($this->configFile, $updatedContent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace PhelWebTests\VersionUpdater\Integration;

use Phel\Shared\Facade\ConsoleFacadeInterface;
use PhelWeb\VersionUpdater\Infrastructure\PhelVersionUpdater;
use PHPUnit\Framework\TestCase;

final class PhelVersionUpdaterTest extends TestCase
{
/** @var false|resource */
private $file;

protected function setUp(): void
{
$this->file = tmpfile();
fwrite($this->file, 'phel_version = "v.0.9"');
}

protected function tearDown(): void
{
fclose($this->file);
}

public function test_update_phel_version(): void
{
$consoleFacade = $this->createAnonConsoleFacade();

$path = stream_get_meta_data($this->file)['uri'];
$phelVersionUpdater = new PhelVersionUpdater($consoleFacade, $path);
$phelVersionUpdater->update();

$content = file_get_contents($path);

$expected = 'phel_version = "v1.0"';

self::assertSame($expected, $content);
}

private function createAnonConsoleFacade(): ConsoleFacadeInterface
{
return new class implements ConsoleFacadeInterface {

public function getVersion(): string
{
return 'v1.0';
}

public function runConsole(): void
{
// ignore
}
};
}
}
14 changes: 14 additions & 0 deletions build/update-phel-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use Gacela\Framework\Gacela;
use Phel\Phel;
use PhelWeb\VersionUpdater\Facade as VersionUpdaterFacade;

Gacela::bootstrap(__DIR__, Phel::configFn());

$facade = new VersionUpdaterFacade();
$facade->updateTomlFile();
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"php build/api-page.php",
"php build/api-search.php"
],
"test": "./vendor/bin/phpunit"
"test": "./vendor/bin/phpunit",
"post-install-cmd": [
"php build/update-phel-version.php"
],
"post-update-cmd": [
"php build/update-phel-version.php"
]
}
}
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ extra_syntaxes_and_themes = ["syntaxes"]
# Put all your custom variables here

repo_content_url = "https://github.com/phel-lang/phel-lang.org/blob/master/content/"
phel_version = "0.23.1"
phel_version = "v0.23.1"

2 changes: 1 addition & 1 deletion templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h3>Community</h3>
<div class="footer-badges">
<span class="footer-badge">PHP 8.3+ Required</span>
<span class="footer-badge-separator">•</span>
<span class="footer-badge footer-badge-version">v{{ config.extra.phel_version }}</span>
<span class="footer-badge footer-badge-version">{{ config.extra.phel_version }}</span>
</div>
</div>
</div>
Expand Down
Loading