diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml index b8e870274..ac3ea49c9 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/release-workflow.yml @@ -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: | diff --git a/.gitignore b/.gitignore index fdfb6f30e..17dd16670 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /confidential/* !/confidential/.htaccess +!/confidential/.meta /data/cache/* !/data/cache/.gitkeep diff --git a/confidential/.meta b/confidential/.meta new file mode 100644 index 000000000..6df6b6fb3 --- /dev/null +++ b/confidential/.meta @@ -0,0 +1,2 @@ +VERSION=3.16.2 +BUILD=dev diff --git a/includes/Http/Controllers/View/AdminController.php b/includes/Http/Controllers/View/AdminController.php index b5f52a4d4..bfd66e612 100644 --- a/includes/Http/Controllers/View/AdminController.php +++ b/includes/Http/Controllers/View/AdminController.php @@ -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; @@ -32,6 +33,7 @@ public function get( PageManager $pageManager, WebsiteHeader $websiteHeader, ServiceModuleManager $serviceModuleManager, + Meta $meta, $pageId = "home" ) { $page = $pageManager->getAdmin($pageId); @@ -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( diff --git a/includes/Providers/AppServiceProvider.php b/includes/Providers/AppServiceProvider.php index 381150b3d..ce7c7008a 100644 --- a/includes/Providers/AppServiceProvider.php +++ b/includes/Providers/AppServiceProvider.php @@ -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; @@ -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); diff --git a/includes/Providers/HeartServiceProvider.php b/includes/Providers/HeartServiceProvider.php index 258bd472a..7c17db113 100644 --- a/includes/Providers/HeartServiceProvider.php +++ b/includes/Providers/HeartServiceProvider.php @@ -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; @@ -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); diff --git a/includes/Providers/SentryServiceProvider.php b/includes/Providers/SentryServiceProvider.php index 565d45f1b..3b1804eb4 100644 --- a/includes/Providers/SentryServiceProvider.php +++ b/includes/Providers/SentryServiceProvider.php @@ -1,9 +1,11 @@ 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()); + }); } } } diff --git a/includes/Routing/UrlGenerator.php b/includes/Routing/UrlGenerator.php index 091a4758a..49a7f1aef 100644 --- a/includes/Routing/UrlGenerator.php +++ b/includes/Routing/UrlGenerator.php @@ -1,6 +1,7 @@ settings = $settings; $this->app = $app; + $this->meta = $meta; } /** @@ -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); } diff --git a/includes/Support/Meta.php b/includes/Support/Meta.php new file mode 100644 index 000000000..82392a89b --- /dev/null +++ b/includes/Support/Meta.php @@ -0,0 +1,41 @@ +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); + } +} diff --git a/includes/Support/MetaParser.php b/includes/Support/MetaParser.php new file mode 100644 index 000000000..fe2e82e9b --- /dev/null +++ b/includes/Support/MetaParser.php @@ -0,0 +1,33 @@ +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(); + } +} diff --git a/includes/System/Application.php b/includes/System/Application.php index 047132655..769bea6ec 100644 --- a/includes/System/Application.php +++ b/includes/System/Application.php @@ -15,8 +15,6 @@ class Application extends Container { - const VERSION = "3.16.2"; - private array $providers = [ AppServiceProvider::class, HeartServiceProvider::class, @@ -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); diff --git a/includes/System/License.php b/includes/System/License.php index eada96679..2ef416189 100644 --- a/includes/System/License.php +++ b/includes/System/License.php @@ -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; @@ -19,6 +20,7 @@ class License private Requester $requester; private CachingRequester $cachingRequester; private UrlGenerator $urlGenerator; + private Meta $meta; /** @var int */ private $externalLicenseId; @@ -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(); @@ -86,7 +90,7 @@ public function getExternalId() return $this->externalLicenseId; } - public function isForever() + public function isForever(): bool { return $this->expiresAt === null; } @@ -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, ], diff --git a/includes/View/Pages/Admin/PageAdminMain.php b/includes/View/Pages/Admin/PageAdminMain.php index 97a289e35..669ae0ad2 100644 --- a/includes/View/Pages/Admin/PageAdminMain.php +++ b/includes/View/Pages/Admin/PageAdminMain.php @@ -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; @@ -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, @@ -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); @@ -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) @@ -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( diff --git a/includes/View/Pages/Admin/PageAdminUpdateWeb.php b/includes/View/Pages/Admin/PageAdminUpdateWeb.php index 1cf9c2496..69cb4c598 100644 --- a/includes/View/Pages/Admin/PageAdminUpdateWeb.php +++ b/includes/View/Pages/Admin/PageAdminUpdateWeb.php @@ -1,9 +1,9 @@ version = $version; - $this->app = $app; + $this->meta = $meta; } public function getPrivilege() @@ -40,7 +40,7 @@ public function getTitle(Request $request) public function getContent(Request $request) { $newestVersion = $this->version->getNewestWeb(); - $currentVersion = $this->app->version(); + $currentVersion = $this->meta->getVersion(); if (version_compare($currentVersion, $newestVersion) >= 0) { return $this->template->render("admin/no_update"); diff --git a/tests/Feature/Verification/CssettiTest.php b/tests/Feature/Verification/CssettiTest.php index 549cf5630..b450e2b6e 100644 --- a/tests/Feature/Verification/CssettiTest.php +++ b/tests/Feature/Verification/CssettiTest.php @@ -56,9 +56,7 @@ public function validates_proper_sms_code() $this->assertFalse($result->isFree()); } - /** - * @test - */ + /** @test */ public function throw_exception_on_bad_code() { // given @@ -73,9 +71,7 @@ public function throw_exception_on_bad_code() $this->cssetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_exception_on_wrong_credentials() { // given @@ -90,9 +86,7 @@ public function throw_exception_on_wrong_credentials() $this->cssetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_server_error_on_unexpected_response() { // given @@ -107,9 +101,7 @@ public function throw_server_error_on_unexpected_response() $this->cssetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_bad_number_on_not_existing_amount_in_the_response() { // given @@ -124,9 +116,7 @@ public function throw_bad_number_on_not_existing_amount_in_the_response() $this->cssetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_bad_number_on_invalid_amount_in_the_response() { // given diff --git a/tests/Feature/Verification/GosettiTest.php b/tests/Feature/Verification/GosettiTest.php index ccaff39cd..b0cf93b85 100644 --- a/tests/Feature/Verification/GosettiTest.php +++ b/tests/Feature/Verification/GosettiTest.php @@ -56,9 +56,7 @@ public function validates_proper_sms_code() $this->assertFalse($result->isFree()); } - /** - * @test - */ + /** @test */ public function throw_exception_on_bad_code() { // given @@ -73,9 +71,7 @@ public function throw_exception_on_bad_code() $this->gosetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_exception_on_wrong_credentials() { // given @@ -90,9 +86,7 @@ public function throw_exception_on_wrong_credentials() $this->gosetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_server_error_on_unexpected_response() { // given @@ -107,9 +101,7 @@ public function throw_server_error_on_unexpected_response() $this->gosetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_bad_number_on_not_existing_amount_in_the_response() { // given @@ -124,9 +116,7 @@ public function throw_bad_number_on_not_existing_amount_in_the_response() $this->gosetti->verifySms("foobar", "72480"); } - /** - * @test - */ + /** @test */ public function throw_bad_number_on_invalid_amount_in_the_response() { // given diff --git a/tests/Unit/Support/MetaTest.php b/tests/Unit/Support/MetaTest.php new file mode 100644 index 000000000..51f2d13a8 --- /dev/null +++ b/tests/Unit/Support/MetaTest.php @@ -0,0 +1,28 @@ +meta = $this->app->make(Meta::class); + } + + /** @test */ + public function version_is_ok() + { + $this->assertEquals("3.16.2", $this->meta->getVersion()); + } + + /** @test */ + public function build_is_ok() + { + $this->assertEquals("dev", $this->meta->getBuild()); + } +} diff --git a/tests/Unit/System/VersionTest.php b/tests/Unit/System/VersionTest.php deleted file mode 100644 index dab2cbf44..000000000 --- a/tests/Unit/System/VersionTest.php +++ /dev/null @@ -1,13 +0,0 @@ -assertEquals("3.16.2", $this->app->version()); - } -}