From 79f797b879fc8b92db8a0c02bd3afafba4b34a1a Mon Sep 17 00:00:00 2001 From: Harshit Singh Bhandari <24b4506@iitb.ac.in> Date: Fri, 5 Jun 2026 21:34:05 +0530 Subject: [PATCH] Auto-install hawkeye in ensure-hawkeye-exists.sh (#1644) - Fixes #1642. - The `ensure-hawkeye-exists.sh` now actually ensures that hawkeye is installed. If it is not installed, the script informs that the installation uses `curl | sh` and asks the user to confirm before proceeding. - Automated workflows can bypass the prompt by invoking the script with the `-y`/`--auto-install` option, or by setting the environment variable `HAWKEYE_AUTO_INSTALL=1`. - Export HAWKEYE_AUTO_INSTALL=1 in every Git workflow job that runs make check, to ensure license/format checks don't stall. --- .github/workflows/common.yml | 2 + Makefile | 1 + scripts/ensure-hawkeye-exists.sh | 75 ++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index 0f62ae01..3ff184d5 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -35,6 +35,8 @@ jobs: fetch-depth: 0 - name: Check formatting + env: + HAWKEYE_AUTO_INSTALL: "1" run: | ./scripts/install-hawkeye.sh make fmt diff --git a/Makefile b/Makefile index fae34241..f91bdee9 100644 --- a/Makefile +++ b/Makefile @@ -326,6 +326,7 @@ pre-commit: echo 'PRECOMMIT_NOFMT=$${PRECOMMIT_NOFMT} $$(git rev-parse --git-path hooks/pre-commit.fmt)' >> /tmp/pre-commit.new mv /tmp/pre-commit.new $(HOOKS_DIR)/pre-commit chmod +x $(HOOKS_DIR)/pre-commit + @./scripts/ensure-hawkeye-exists.sh .PHONY: serve-docs serve-docs: diff --git a/scripts/ensure-hawkeye-exists.sh b/scripts/ensure-hawkeye-exists.sh index 56d7986b..65693935 100755 --- a/scripts/ensure-hawkeye-exists.sh +++ b/scripts/ensure-hawkeye-exists.sh @@ -13,12 +13,79 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -e + +auto_install=0 + +for arg in "$@"; do + case "$arg" in + --auto-install|-y) + auto_install=1 + ;; + -h|--help) + cat <&2 + echo "see '$(basename "$0") --help' for usage" >&2 + exit 2 + ;; + esac +done + +if [[ "${HAWKEYE_AUTO_INSTALL:-}" == "1" ]]; then + auto_install=1 +fi + echo "Checking existence of hawkeye..." if command -v .local/bin/hawkeye >/dev/null 2>&1; then echo "hawkeye found!" -else - echo "hawkeye not found in PATH" - echo "please install hawkeye. For convenience, you can run scripts/install-hawkeye.sh" - exit 1 + exit 0 fi + +cat </hawkeye-installer.sh | sh + +and performs the installation by passing the downloaded content to \`sh\`. + +(See scripts/install-hawkeye.sh for the pinned version.) +EOF + +if [[ "$auto_install" -eq 1 ]]; then + echo + echo "Auto-install enabled; proceeding." +elif [[ ! -t 0 ]]; then + echo + echo "Non-interactive context detected. Refusing to install silently." >&2 + echo "Set HAWKEYE_AUTO_INSTALL=1 or pass --auto-install to proceed." >&2 + exit 1 +else + echo + read -r -p "Proceed with install? [y/N] " response + case "$response" in + [yY][eE][sS]|[yY]) + ;; + *) + echo "please install hawkeye. For convenience, you can run scripts/install-hawkeye.sh" + exit 1 + ;; + esac +fi + +exec "$(dirname "$0")/install-hawkeye.sh"