From 3b6e0a895b46fe5c26ed80b3d21cb72871f7ed22 Mon Sep 17 00:00:00 2001 From: Aidan Casey Date: Wed, 16 Apr 2025 12:19:28 -0400 Subject: [PATCH 1/2] Fixes stars. --- .github/workflows/deploy.yml | 2 ++ deploy.sh | 2 +- src/GitHub/GetLatestRelease.php | 15 ++++++++++++++- src/GitHub/GetStargazersCount.php | 14 +++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2e4c0a47..13954b41 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,6 +36,8 @@ jobs: - name: Deploy run: php ./tempest deploy + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/deploy.sh b/deploy.sh index d2c12cd9..e5189b74 100644 --- a/deploy.sh +++ b/deploy.sh @@ -17,7 +17,7 @@ php8.4 tempest cache:clear --all php8.4 tempest discovery:generate php8.4 tempest migrate:up --force php8.4 tempest static:clean --force -php8.4 tempest static:generate +php8.4 tempest static:generate --verbose=true # Supervisor sudo supervisorctl restart all diff --git a/src/GitHub/GetLatestRelease.php b/src/GitHub/GetLatestRelease.php index f4a09098..fa4fb8ee 100644 --- a/src/GitHub/GetLatestRelease.php +++ b/src/GitHub/GetLatestRelease.php @@ -6,6 +6,8 @@ use Tempest\HttpClient\HttpClient; use Throwable; +use function Tempest\env; + final class GetLatestRelease { public function __construct( @@ -15,12 +17,23 @@ public function __construct( public function __invoke(): ?string { + // Added by Aidan Casey to combat the GitHub rate limits. + // We will inject the GH_TOKEN using our workflow. + $headers = []; + + if ($githubToken = env('GH_TOKEN')) { + $headers['Authorization'] = 'Bearer ' . $githubToken; + } + // Default release to the currently running version of Tempest. $defaultRelease = sprintf('v%s', Kernel::VERSION); try { $body = $this->httpClient - ->get('https://api.github.com/repos/tempestphp/tempest-framework/releases/latest') + ->get( + uri: 'https://api.github.com/repos/tempestphp/tempest-framework/releases/latest', + headers: $headers + ) ->body; return json_decode($body)->tag_name ?? $defaultRelease; diff --git a/src/GitHub/GetStargazersCount.php b/src/GitHub/GetStargazersCount.php index 371c1f70..37ee1532 100644 --- a/src/GitHub/GetStargazersCount.php +++ b/src/GitHub/GetStargazersCount.php @@ -4,6 +4,7 @@ use Tempest\HttpClient\HttpClient; use Throwable; +use function Tempest\env; final class GetStargazersCount { @@ -14,8 +15,19 @@ public function __construct( public function __invoke(): ?string { + // Added by Aidan Casey to combat the GitHub rate limits. + // We will inject the GH_TOKEN using our workflow. + $headers = []; + + if ($githubToken = env('GH_TOKEN')) { + $headers['Authorization'] = 'Bearer ' . $githubToken; + } + try { - $body = $this->httpClient->get('https://api.github.com/repos/tempestphp/tempest-framework')->body; + $body = $this->httpClient->get( + uri: 'https://api.github.com/repos/tempestphp/tempest-framework', + headers: $headers + )->body; $stargazers = json_decode($body)->stargazers_count ?? null; return $stargazers > 999 From 67c634d37911d0c04a341b7cdc4c6ced5f5e365c Mon Sep 17 00:00:00 2001 From: Aidan Casey Date: Wed, 16 Apr 2025 12:20:18 -0400 Subject: [PATCH 2/2] Styling. --- src/GitHub/GetLatestRelease.php | 2 +- src/GitHub/GetStargazersCount.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GitHub/GetLatestRelease.php b/src/GitHub/GetLatestRelease.php index fa4fb8ee..c21129f9 100644 --- a/src/GitHub/GetLatestRelease.php +++ b/src/GitHub/GetLatestRelease.php @@ -32,7 +32,7 @@ public function __invoke(): ?string $body = $this->httpClient ->get( uri: 'https://api.github.com/repos/tempestphp/tempest-framework/releases/latest', - headers: $headers + headers: $headers, ) ->body; diff --git a/src/GitHub/GetStargazersCount.php b/src/GitHub/GetStargazersCount.php index 37ee1532..301b406e 100644 --- a/src/GitHub/GetStargazersCount.php +++ b/src/GitHub/GetStargazersCount.php @@ -4,6 +4,7 @@ use Tempest\HttpClient\HttpClient; use Throwable; + use function Tempest\env; final class GetStargazersCount @@ -26,7 +27,7 @@ public function __invoke(): ?string try { $body = $this->httpClient->get( uri: 'https://api.github.com/repos/tempestphp/tempest-framework', - headers: $headers + headers: $headers, )->body; $stargazers = json_decode($body)->stargazers_count ?? null;