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.
This commit is contained in:
Harshit Singh Bhandari
2026-06-05 09:04:05 -07:00
committed by GitHub
parent 48cb23e3b7
commit 79f797b879
3 changed files with 74 additions and 4 deletions
+2
View File
@@ -35,6 +35,8 @@ jobs:
fetch-depth: 0
- name: Check formatting
env:
HAWKEYE_AUTO_INSTALL: "1"
run: |
./scripts/install-hawkeye.sh
make fmt
+1
View File
@@ -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:
+71 -4
View File
@@ -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 <<EOF
Usage: $(basename "$0") [--auto-install|-y]
Checks for a working hawkeye installation under .local/bin/.
If hawkeye is missing, prompts before running scripts/install-hawkeye.sh.
Skip the prompt non-interactively in either of two ways:
--auto-install, -y pass on the command line
HAWKEYE_AUTO_INSTALL=1 set in the environment
EOF
exit 0
;;
*)
echo "unknown argument: $arg" >&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 <<EOF
hawkeye is not installed.
scripts/install-hawkeye.sh will install it by running:
curl -LsSf https://github.com/korandoru/hawkeye/releases/download/<version>/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"