Skip to content

Commit

Permalink
Meta (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
budziam authored Feb 7, 2021
1 parent 28fbc0b commit 993ac5b
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ jobs:
run: ./remove_unnecessary_files.sh
-
run: pre-commit run --all-files || true
-
name: Save build version
run: sed -i "s/BUILD=.*/BUILD=php${{ matrix.php_version }}/" ./confidential/.meta
-
id: build_artifact
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/confidential/*
!/confidential/.htaccess
!/confidential/.meta

/data/cache/*
!/data/cache/.gitkeep
Expand Down
2 changes: 2 additions & 0 deletions confidential/.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VERSION=3.16.2
BUILD=dev
4 changes: 3 additions & 1 deletion includes/Http/Controllers/View/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Managers\WebsiteHeader;
use App\Routing\UrlGenerator;
use App\ServiceModules\Interfaces\IServiceUserServiceAdminDisplay;
use App\Support\Meta;
use App\Support\Template;
use App\System\Application;
use App\System\Auth;
Expand All @@ -32,6 +33,7 @@ public function get(
PageManager $pageManager,
WebsiteHeader $websiteHeader,
ServiceModuleManager $serviceModuleManager,
Meta $meta,
$pageId = "home"
) {
$page = $pageManager->getAdmin($pageId);
Expand Down Expand Up @@ -133,7 +135,7 @@ public function get(
"scripts" => $websiteHeader->getScripts(),
"styles" => $websiteHeader->getStyles(),
]);
$currentVersion = $app->version();
$currentVersion = $meta->getVersion();
$logoutAction = $url->to("/admin/login");

return new Response(
Expand Down
2 changes: 2 additions & 0 deletions includes/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Support\FileSystem;
use App\Support\FileSystemContract;
use App\Support\Mailer;
use App\Support\Meta;
use App\Support\Path;
use App\Support\Template;
use App\System\Application;
Expand Down Expand Up @@ -48,6 +49,7 @@ public function register(Application $app)
$app->singleton(ExternalConfigProvider::class);
$app->singleton(GroupManager::class);
$app->singleton(License::class);
$app->singleton(Meta::class);
$app->singleton(PageManager::class);
$app->singleton(PaymentModuleManager::class);
$app->singleton(ServerAuth::class);
Expand Down
6 changes: 6 additions & 0 deletions includes/Providers/HeartServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\ServiceModules\ExtraFlags\ExtraFlagsServiceModule;
use App\ServiceModules\MybbExtraGroups\MybbExtraGroupsServiceModule;
use App\ServiceModules\Other\OtherServiceModule;
use App\Support\Meta;
use App\System\Application;
use App\Verification\PaymentModules\CashBill;
use App\Verification\PaymentModules\Cssetti;
Expand Down Expand Up @@ -96,6 +97,11 @@ public function register(Application $app)
});
}

public function boot(Meta $meta)
{
$meta->load();
}

private function registerPaymentModules(PaymentModuleManager $paymentModuleManager)
{
$paymentModuleManager->register(CashBill::class);
Expand Down
25 changes: 20 additions & 5 deletions includes/Providers/SentryServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
namespace App\Providers;

use App\Support\Meta;
use App\System\Application;
use App\System\ExternalConfigProvider;
use Sentry;
use Sentry\State\Scope;

class SentryServiceProvider
{
Expand All @@ -14,23 +16,36 @@ public function register(Application $app)
/** @var ExternalConfigProvider $configProvider */
$configProvider = $app->make(ExternalConfigProvider::class);

return new \Raven_Client([
/** @var Meta $meta */
$meta = $app->make(Meta::class);

$client = new \Raven_Client([
"dsn" => getenv("SENTRY_DSN") ?: $configProvider->sentryDSN(),
"release" => $app->version(),
"release" => $meta->getVersion(),
]);

$client->tags_context([
"build" => $meta->getBuild(),
]);

return $client;
});
}
}

public function boot(Application $app, ExternalConfigProvider $configProvider)
public function boot(Meta $meta, ExternalConfigProvider $configProvider)
{
if (!is_testing() && class_exists(\Sentry\SentrySdk::class)) {
if (!is_testing() && class_exists(Sentry\SentrySdk::class)) {
Sentry\init([
"dsn" => getenv("SENTRY_DSN") ?: $configProvider->sentryDSN(),
"release" => $app->version(),
"release" => $meta->getVersion(),
"traces_sample_rate" => $configProvider->sentrySampleRate() ?: 1.0,
"send_default_pii" => true,
]);

Sentry\configureScope(function (Scope $scope) use ($meta) {
$scope->setTag("build", $meta->getBuild());
});
}
}
}
10 changes: 8 additions & 2 deletions includes/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace App\Routing;

use App\Support\Meta;
use App\System\Application;
use App\System\Settings;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -9,12 +10,14 @@ class UrlGenerator
{
private Settings $settings;
private Application $app;
private Meta $meta;
private ?string $version = null;

public function __construct(Settings $settings, Application $app)
public function __construct(Settings $settings, Application $app, Meta $meta)
{
$this->settings = $settings;
$this->app = $app;
$this->meta = $meta;
}

/**
Expand Down Expand Up @@ -66,7 +69,10 @@ public function getShopUrl()
private function getVersion()
{
if (!$this->version) {
$version = hash("sha256", $this->settings->getSecret() . "#" . $this->app->version());
$version = hash(
"sha256",
$this->settings->getSecret() . "#" . $this->meta->getVersion()
);
$this->version = substr($version, 0, 7);
}

Expand Down
41 changes: 41 additions & 0 deletions includes/Support/Meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace App\Support;

class Meta
{
private MetaParser $metaParser;
private Path $path;
private array $meta;

public function __construct(MetaParser $metaParser, Path $path)
{
$this->metaParser = $metaParser;
$this->path = $path;
}

public function load()
{
$path = $this->path->to("confidential/.meta");
$this->meta = $this->metaParser->parse($path);
}

public function getVersion(): string
{
return $this->get("VERSION", "unknown");
}

public function getBuild(): string
{
return $this->get("BUILD", "unknown");
}

/**
* @param string $key
* @param string|null $default
* @return mixed|null
*/
public function get($key, $default = null)
{
return array_get($this->meta, $key, $default);
}
}
33 changes: 33 additions & 0 deletions includes/Support/MetaParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace App\Support;

class MetaParser
{
private FileSystemContract $fileSystem;

public function __construct(FileSystemContract $fileSystem)
{
$this->fileSystem = $fileSystem;
}

/**
* @param string $path
* @return array
*/
public function parse($path): array
{
$lines = explode(PHP_EOL, $this->fileSystem->get($path));

return collect($lines)
->flatMap(function ($line) {
$exploded = explode("=", $line);

if (count($exploded) != 2) {
return [];
}

return [trim($exploded[0]) => trim($exploded[1])];
})
->all();
}
}
7 changes: 0 additions & 7 deletions includes/System/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

class Application extends Container
{
const VERSION = "3.16.2";

private array $providers = [
AppServiceProvider::class,
HeartServiceProvider::class,
Expand All @@ -34,11 +32,6 @@ public function __construct($basePath)
$this->bootstrap();
}

public function version(): string
{
return self::VERSION;
}

private function registerBindings(): void
{
$this->instance(Container::class, $this);
Expand Down
12 changes: 8 additions & 4 deletions includes/System/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Exceptions\RequestException;
use App\Requesting\Requester;
use App\Routing\UrlGenerator;
use App\Support\Meta;
use App\Translation\TranslationManager;
use App\Translation\Translator;

Expand All @@ -19,6 +20,7 @@ class License
private Requester $requester;
private CachingRequester $cachingRequester;
private UrlGenerator $urlGenerator;
private Meta $meta;

/** @var int */
private $externalLicenseId;
Expand All @@ -36,19 +38,21 @@ public function __construct(
Settings $settings,
Requester $requester,
CachingRequester $cachingRequester,
UrlGenerator $urlGenerator
UrlGenerator $urlGenerator,
Meta $meta
) {
$this->langShop = $translationManager->shop();
$this->settings = $settings;
$this->requester = $requester;
$this->cachingRequester = $cachingRequester;
$this->urlGenerator = $urlGenerator;
$this->meta = $meta;
}

/**
* @throws LicenseRequestException
*/
public function validate()
public function validate(): void
{
try {
$response = $this->loadLicense();
Expand Down Expand Up @@ -86,7 +90,7 @@ public function getExternalId()
return $this->externalLicenseId;
}

public function isForever()
public function isForever(): bool
{
return $this->expiresAt === null;
}
Expand Down Expand Up @@ -126,7 +130,7 @@ private function request()
[
"url" => $shopUrl,
"name" => $this->settings["shop_name"] ?: $shopUrl,
"version" => app()->version(),
"version" => $this->meta->getVersion(),
"language" => $this->langShop->getCurrentLanguage(),
"php_version" => PHP_VERSION,
],
Expand Down
12 changes: 6 additions & 6 deletions includes/View/Pages/Admin/PageAdminMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
use App\Routing\UrlGenerator;
use App\Server\Platform;
use App\Support\Database;
use App\Support\Meta;
use App\Support\PriceTextService;
use App\Support\Template;
use App\Support\Version;
use App\System\Application;
use App\System\License;
use App\Translation\TranslationManager;
use App\View\Html\RawHtml;
Expand All @@ -31,9 +31,9 @@ class PageAdminMain extends PageAdmin
private PriceTextService $priceTextService;
private TransactionRepository $transactionRepository;
private UrlGenerator $url;
private Application $app;
private ServerManager $serverManager;
private Database $db;
private Meta $meta;

public function __construct(
Template $template,
Expand All @@ -45,9 +45,9 @@ public function __construct(
PriceTextService $priceTextService,
TransactionRepository $transactionRepository,
UrlGenerator $url,
Application $app,
ServerManager $serverManager,
Database $db
Database $db,
Meta $meta
) {
parent::__construct($template, $translationManager);

Expand All @@ -58,9 +58,9 @@ public function __construct(
$this->priceTextService = $priceTextService;
$this->transactionRepository = $transactionRepository;
$this->url = $url;
$this->app = $app;
$this->serverManager = $serverManager;
$this->db = $db;
$this->meta = $meta;
}

public function getTitle(Request $request)
Expand Down Expand Up @@ -112,7 +112,7 @@ private function getNotes()
$newestAmxXVersion = $this->version->getNewestAmxmodx();
$newestSmVersion = $this->version->getNewestSourcemod();

if ($newestVersion && version_compare($this->app->version(), $newestVersion) < 0) {
if ($newestVersion && version_compare($this->meta->getVersion(), $newestVersion) < 0) {
$updateWebLink = $this->url->to("/admin/update_web");

$notes[] = $this->createNote(
Expand Down
Loading

0 comments on commit 993ac5b

Please sign in to comment.