Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download latest release from github #34

Merged
merged 3 commits into from
Dec 15, 2023
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
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