diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 13954b41..dfd303ad 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,10 +34,21 @@ jobs: - name: List Installed Dependencies run: composer show -D - - name: Deploy - run: php ./tempest deploy + - name: Get latest GitHub statistics + id: stats env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -e + STARS=$(curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/tempestphp/tempest-framework | jq '.stargazers_count // empty') + TAG=$(curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/tempestphp/tempest-framework/releases/latest | jq -r '.tag_name // empty') + echo "Stars: $STARS" + echo "Latest version: $TAG" + echo "stars=$STARS" >> "$GITHUB_OUTPUT" + echo "latest_tag=$TAG" >> "$GITHUB_OUTPUT" - - + - name: Deploy + run: php ./tempest deploy + env: + TEMPEST_BUILD_STARGAZERS: ${{ steps.stats.outputs.stars }} + TEMPEST_BUILD_LATEST_RELEASE: ${{ steps.stats.outputs.latest_tag }} diff --git a/src/GitHub/GetLatestRelease.php b/src/GitHub/GetLatestRelease.php index c21129f9..a668deb3 100644 --- a/src/GitHub/GetLatestRelease.php +++ b/src/GitHub/GetLatestRelease.php @@ -17,12 +17,8 @@ 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; + if ($latestRelease = env('TEMPEST_BUILD_LATEST_RELEASE')) { + return $latestRelease; } // Default release to the currently running version of Tempest. @@ -30,16 +26,12 @@ public function __invoke(): ?string try { $body = $this->httpClient - ->get( - uri: 'https://api.github.com/repos/tempestphp/tempest-framework/releases/latest', - headers: $headers, - ) + ->get('https://api.github.com/repos/tempestphp/tempest-framework/releases/latest') ->body; return json_decode($body)->tag_name ?? $defaultRelease; - } catch (Throwable $e) { - ll($e); - return Kernel::VERSION; + } catch (Throwable) { + return $defaultRelease; } } } diff --git a/src/GitHub/GetStargazersCount.php b/src/GitHub/GetStargazersCount.php index 301b406e..45b87cae 100644 --- a/src/GitHub/GetStargazersCount.php +++ b/src/GitHub/GetStargazersCount.php @@ -2,6 +2,7 @@ namespace App\GitHub; +use PDO; use Tempest\HttpClient\HttpClient; use Throwable; @@ -16,26 +17,28 @@ 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 ($stargazers = $this->getStargazersCount()) { + return $stargazers > 999 + ? (round($stargazers / 1000, 1) . 'K') + : $stargazers; + } + + return null; + } - if ($githubToken = env('GH_TOKEN')) { - $headers['Authorization'] = 'Bearer ' . $githubToken; + private function getStargazersCount(): ?int + { + if ($stargazers = env('TEMPEST_BUILD_STARGAZERS')) { + return $stargazers; } try { - $body = $this->httpClient->get( - uri: 'https://api.github.com/repos/tempestphp/tempest-framework', - headers: $headers, - )->body; - $stargazers = json_decode($body)->stargazers_count ?? null; + $body = $this->httpClient + ->get(uri: 'https://api.github.com/repos/tempestphp/tempest-framework') + ->body; - return $stargazers > 999 - ? (round($stargazers / 1000, 1) . 'K') - : $stargazers; - } catch (Throwable $e) { - ll($e); + return $stargazers = json_decode($body)->stargazers_count ?? null; + } catch (\Throwable) { return null; } }