From aa9997c9f17e801a1010ac9d7628dfe92c64749b Mon Sep 17 00:00:00 2001 From: Fracsi Date: Fri, 8 Dec 2023 12:26:13 +0100 Subject: [PATCH 1/3] Download latest release from github --- src/TailwindBinary.php | 13 ++++++++++++- tests/TailwindBinaryTest.php | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TailwindBinary.php b/src/TailwindBinary.php index 6cd58dc..17ddaed 100644 --- a/src/TailwindBinary.php +++ b/src/TailwindBinary.php @@ -53,7 +53,7 @@ public function createProcess(array $arguments = []): Process private function downloadExecutable(): void { - $url = sprintf('https://github.com/tailwindlabs/tailwindcss/releases/download/%s/%s', self::VERSION, self::getBinaryName()); + $url = sprintf('https://github.com/tailwindlabs/tailwindcss/releases/download/%s/%s', $this->getLatestVersion(), self::getBinaryName()); $this->output?->note(sprintf('Downloading TailwindCSS binary from %s', $url)); @@ -89,6 +89,17 @@ private function downloadExecutable(): void chmod($targetPath, 0777); } + private function getLatestVersion(): string + { + try { + $response = $this->httpClient->request('GET', 'https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest'); + + return $response->toArray()['name'] ?? self::VERSION; + } catch (\Throwable) { + return self::VERSION; + } + } + /** * @internal */ diff --git a/tests/TailwindBinaryTest.php b/tests/TailwindBinaryTest.php index d28af54..3d38500 100644 --- a/tests/TailwindBinaryTest.php +++ b/tests/TailwindBinaryTest.php @@ -27,6 +27,7 @@ public function testBinaryIsDownloadedAndProcessCreated() $fs->mkdir($binaryDownloadDir); $client = new MockHttpClient([ + new MockResponse('{}'), new MockResponse('fake binary contents'), ]); From 57bffceb0bd911d6d83c19ccaa3067cd2df5e2cb Mon Sep 17 00:00:00 2001 From: Fracsi Date: Fri, 15 Dec 2023 09:01:41 +0100 Subject: [PATCH 2/3] Rename constant --- src/TailwindBinary.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TailwindBinary.php b/src/TailwindBinary.php index 17ddaed..e64596e 100644 --- a/src/TailwindBinary.php +++ b/src/TailwindBinary.php @@ -21,7 +21,7 @@ */ class TailwindBinary { - private const VERSION = 'v3.3.5'; + private const DEFAULT_VERSION = 'v3.3.5'; private HttpClientInterface $httpClient; public function __construct( @@ -94,9 +94,11 @@ private function getLatestVersion(): string try { $response = $this->httpClient->request('GET', 'https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest'); - return $response->toArray()['name'] ?? self::VERSION; + return $response->toArray()['name'] ?? self::DEFAULT_VERSION + ; } catch (\Throwable) { - return self::VERSION; + return self::DEFAULT_VERSION + ; } } From 0751a91be1e2f5ef81c0d0b3ddeb4721fc48ad2b Mon Sep 17 00:00:00 2001 From: Fracsi Date: Fri, 15 Dec 2023 12:18:05 +0100 Subject: [PATCH 3/3] CS fix --- src/TailwindBinary.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/TailwindBinary.php b/src/TailwindBinary.php index e64596e..beb75f7 100644 --- a/src/TailwindBinary.php +++ b/src/TailwindBinary.php @@ -94,11 +94,9 @@ private function getLatestVersion(): string try { $response = $this->httpClient->request('GET', 'https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest'); - return $response->toArray()['name'] ?? self::DEFAULT_VERSION - ; + return $response->toArray()['name'] ?? self::DEFAULT_VERSION; } catch (\Throwable) { - return self::DEFAULT_VERSION - ; + return self::DEFAULT_VERSION; } }