From 463553b9f028982d0b18aa5f332921c7c2597bd3 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sat, 13 Jul 2024 12:54:11 -0400 Subject: [PATCH 1/3] Revert "Revert "setup-homebrew: add brew-gh-api-token setting"" --- setup-homebrew/action.yml | 4 ++++ setup-homebrew/main.mjs | 5 +++-- setup-homebrew/main.sh | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/setup-homebrew/action.yml b/setup-homebrew/action.yml index 2c1ce60f..d5567834 100644 --- a/setup-homebrew/action.yml +++ b/setup-homebrew/action.yml @@ -25,6 +25,10 @@ inputs: description: Token to be used for GitHub authentication (if using private repositories). This token will persist through other steps for the duration of the job. required: false default: "" + brew-gh-api-token: + description: Token to be used for GitHub API operations within `brew`. This is confusingly not the same thing as `token` above. + required: false + default: "${{ github.token }}" stable: description: Use the latest stable `homebrew/brew` tag. required: false diff --git a/setup-homebrew/main.mjs b/setup-homebrew/main.mjs index e29e7f23..06ad4455 100644 --- a/setup-homebrew/main.mjs +++ b/setup-homebrew/main.mjs @@ -1,4 +1,4 @@ -import {exec} from "@actions/exec" +import { exec } from "@actions/exec" import core from "@actions/core" // GitHub Actions does not support shell `post` actions and thus requires a JS wrapper. @@ -10,7 +10,8 @@ try { core.getInput("test-bot"), core.getInput("debug"), core.getInput("token"), - core.getInput("stable") + core.getInput("stable"), + core.getInput("brew-gh-api-token"), ]) } catch (error) { core.setFailed(error.message) diff --git a/setup-homebrew/main.sh b/setup-homebrew/main.sh index 4a44cceb..18c11d75 100755 --- a/setup-homebrew/main.sh +++ b/setup-homebrew/main.sh @@ -8,6 +8,7 @@ TEST_BOT="${3}" DEBUG="${4}" TOKEN="${5}" STABLE="${6}" +BREW_GH_API_TOKEN="${7}" if [[ "${DEBUG}" == "true" ]]; then set -x @@ -122,6 +123,11 @@ if [[ ! "$GITHUB_REPOSITORY" =~ ^.+/(home|linux)brew-core$ ]]; then unset HOMEBREW_NO_INSTALL_FROM_API fi +# Configure HOMEBREW_GITHUB_API_TOKEN (needed for attestations) +if [[ -n "${BREW_GH_API_TOKEN}" ]]; then + echo "HOMEBREW_GITHUB_API_TOKEN=${BREW_GH_API_TOKEN}" >> "${GITHUB_ENV}" +fi + # Use an access token to checkout (private repositories) if [[ -n "${TOKEN}" ]]; then # GNU coreutils will line-wrap long tokens, so delete any newlines. From 2e3a4ced943865b3bb46aeefdaa4bc6d8eb03219 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sat, 13 Jul 2024 13:08:17 -0400 Subject: [PATCH 2/3] setup-homebrew: don't clobber HOMEBREW_GITHUB_API_TOKEN Signed-off-by: William Woodruff --- setup-homebrew/main.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup-homebrew/main.sh b/setup-homebrew/main.sh index 18c11d75..aa9093fe 100755 --- a/setup-homebrew/main.sh +++ b/setup-homebrew/main.sh @@ -123,8 +123,8 @@ if [[ ! "$GITHUB_REPOSITORY" =~ ^.+/(home|linux)brew-core$ ]]; then unset HOMEBREW_NO_INSTALL_FROM_API fi -# Configure HOMEBREW_GITHUB_API_TOKEN (needed for attestations) -if [[ -n "${BREW_GH_API_TOKEN}" ]]; then +# Only do so if the user hasn't already explicitly set HOMEBREW_GITHUB_API_TOKEN. +if [[ -n "${BREW_GH_API_TOKEN}" && -z "${HOMEBREW_GITHUB_API_TOKEN}" ]]; then echo "HOMEBREW_GITHUB_API_TOKEN=${BREW_GH_API_TOKEN}" >> "${GITHUB_ENV}" fi From 40e9946c182a64b3db1bf51be0dcb915f7802aa9 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sat, 13 Jul 2024 13:37:47 -0400 Subject: [PATCH 3/3] Update setup-homebrew/main.sh --- setup-homebrew/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-homebrew/main.sh b/setup-homebrew/main.sh index aa9093fe..ce79598e 100755 --- a/setup-homebrew/main.sh +++ b/setup-homebrew/main.sh @@ -124,7 +124,7 @@ if [[ ! "$GITHUB_REPOSITORY" =~ ^.+/(home|linux)brew-core$ ]]; then fi # Only do so if the user hasn't already explicitly set HOMEBREW_GITHUB_API_TOKEN. -if [[ -n "${BREW_GH_API_TOKEN}" && -z "${HOMEBREW_GITHUB_API_TOKEN}" ]]; then +if [[ -n "${BREW_GH_API_TOKEN}" && -z "${HOMEBREW_GITHUB_API_TOKEN-}" ]]; then echo "HOMEBREW_GITHUB_API_TOKEN=${BREW_GH_API_TOKEN}" >> "${GITHUB_ENV}" fi