Skip to content

Commit

Permalink
Download latest release from github (#34)
Browse files Browse the repository at this point in the history
* Download latest release from github

* Rename constant

* CS fix
  • Loading branch information
fracsi authored Dec 15, 2023
1 parent 15a2533 commit 3013811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/TailwindBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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::DEFAULT_VERSION;
} catch (\Throwable) {
return self::DEFAULT_VERSION;
}
}

/**
* @internal
*/
Expand Down
1 change: 1 addition & 0 deletions tests/TailwindBinaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testBinaryIsDownloadedAndProcessCreated()
$fs->mkdir($binaryDownloadDir);

$client = new MockHttpClient([
new MockResponse('{}'),
new MockResponse('fake binary contents'),
]);

Expand Down

0 comments on commit 3013811

Please sign in to comment.