diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 13954b4..04ea118 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,10 +34,38 @@ 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 + + # Get stargazers + STARS=$(curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/tempestphp/tempest-framework | jq '.stargazers_count // empty') + STARS_K="" + if [ -n "$STARS" ]; then + if [ "$STARS" -gt 999 ]; then + STARS_K=$(awk "BEGIN { printf \"%.1fK\", $STARS/1000 }") + else + STARS_K=$STARS + fi + fi + + # Get latest release tag + 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_K" + echo "Latest Version: $TAG" + + # Push these values to the output + echo "stars=$STARS_K" >> "$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 c21129f..8ba59d1 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,10 +26,7 @@ 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; diff --git a/src/GitHub/GetStargazersCount.php b/src/GitHub/GetStargazersCount.php index 301b406..204aa0f 100644 --- a/src/GitHub/GetStargazersCount.php +++ b/src/GitHub/GetStargazersCount.php @@ -16,19 +16,14 @@ 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 ($stargazers = env('TEMPEST_BUILD_STARGAZERS')) { + return $stargazers; } try { - $body = $this->httpClient->get( - uri: 'https://api.github.com/repos/tempestphp/tempest-framework', - headers: $headers, - )->body; + $body = $this->httpClient + ->get(uri: 'https://api.github.com/repos/tempestphp/tempest-framework') + ->body; $stargazers = json_decode($body)->stargazers_count ?? null; return $stargazers > 999