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..c21129f9 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..301b406e 100644 --- a/src/GitHub/GetStargazersCount.php +++ b/src/GitHub/GetStargazersCount.php @@ -5,6 +5,8 @@ use Tempest\HttpClient\HttpClient; use Throwable; +use function Tempest\env; + final class GetStargazersCount { public function __construct( @@ -14,8 +16,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