Skip to content

Auto-install hawkeye in ensure-hawkeye-exists.sh#1644

Merged
jglogan merged 1 commit into
apple:mainfrom
harshitsinghbhandari:fix/hawkeye-auto-install
Jun 5, 2026
Merged

Auto-install hawkeye in ensure-hawkeye-exists.sh#1644
jglogan merged 1 commit into
apple:mainfrom
harshitsinghbhandari:fix/hawkeye-auto-install

Conversation

@harshitsinghbhandari

Copy link
Copy Markdown
Contributor

Summary

scripts/ensure-hawkeye-exists.sh previously checked for hawkeye and exited 1 with a message asking the contributor to install it manually. Since make pre-commit doesn't run the installer either, every fresh contributor hits the same wall on their first commit — make pre-commit succeeds, but the very next commit attempt fails on make check with no signal from the earlier step that anything was missing.

This change makes ensure-hawkeye-exists.sh install hawkeye when it's missing, by exec-ing the existing scripts/install-hawkeye.sh. "Ensure" now does what the name suggests.

If you'd prefer the install to stay opt-in (e.g. so contributors stay in explicit control of curl | sh flows), I'm happy to convert this to an alternative shape — having make pre-commit depend on a target that installs hawkeye, or having make pre-commit print a clear note that hawkeye must be installed separately.

Fixes #1642.

Test plan

  • Delete .local/bin/hawkeye, run scripts/ensure-hawkeye-exists.sh — installs hawkeye and exits 0.
  • Run scripts/ensure-hawkeye-exists.sh when hawkeye is already present — prints "hawkeye found!" and exits 0 (unchanged).
  • make check succeeds after a single end-to-end make pre-commit + commit cycle on a fresh checkout.

@jglogan

jglogan commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Hi @harshitsinghbhandari! Thanks for filing the issues and the PRs. Let me look over your worktree hook fix first, and then I'll think a bit more regarding the curl | sh issue.

@harshitsinghbhandari

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look! Happy to reshape this PR toward either approach based on what you think makes sense — keeping ensure-hawkeye-exists.sh as a pure check and routing the install through a Makefile target / contributor doc is just as viable.

@jglogan

jglogan commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

If you'd prefer the install to stay opt-in (e.g. so contributors stay in explicit control of curl | sh flows)

@harshitsinghbhandari This is a good point. curl | sh is considered by plenty of people to be a security anti-pattern.

I'm not a fan of it myself, and we shouldn't be doing it without their knowledge. What do you think about the following UX:

  • The ensure script UX is interactive by default (telling the user what it's going to run and giving them the chance to bail)
  • The ensure script reads an environment variable that allows the user to say yes non-interactively
  • The existing pre-commit make target runs the ensure script, similarly to the license/format targets.

We'd need to double-check that any non-interactive workflows (I'm thinking mainly about our Git workflows where each build runs on a freshly imaged machine) explicitly install hawkeye non-interactively so that subsequent steps that run the license/format checks don't stall waiting for input.

@harshitsinghbhandari

Copy link
Copy Markdown
Contributor Author

@jglogan — agreed on all three points. Here's the plan:

scripts/ensure-hawkeye-exists.sh:

  • If hawkeye is missing, print exactly what would be downloaded and from where (https://github.com/korandoru/hawkeye/releases/download/v6.5.1/...), then prompt [y/N].
  • Two ways to skip the prompt (matches convention in most tools):
    • CLI flag: --auto-install (or -y)
    • Env var: HAWKEYE_AUTO_INSTALL=1
    • Precedence: flag > env var > prompt (default).
  • If declined, exit 1 with the original "please run install-hawkeye.sh" message.

Makefile:

  • pre-commit target runs ./scripts/ensure-hawkeye-exists.sh after installing the hook, so contributors hit the consent prompt at make pre-commit time.
  • check-licenses / update-licenses left as-is.

CI / GitHub Actions:

  • Export HAWKEYE_AUTO_INSTALL=1 at the workflow level in any job that runs make check, so license/format checks don't stall.

Will push the implementation shortly.

@harshitsinghbhandari harshitsinghbhandari force-pushed the fix/hawkeye-auto-install branch 2 times, most recently from bc7af87 to 3430c40 Compare June 4, 2026 22:35
@jglogan

jglogan commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
  • If hawkeye is missing, print exactly what would be downloaded and from where

What would be downloaded and where, and that what's downloaded will be passwd into sh.

@jglogan jglogan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment about describing to the user what the hawkeye installer does.

Comment thread scripts/ensure-hawkeye-exists.sh
@harshitsinghbhandari harshitsinghbhandari force-pushed the fix/hawkeye-auto-install branch from 3430c40 to dfaddfc Compare June 5, 2026 00:08
`make pre-commit` previously installed the hook but did not check for
hawkeye, so the very next commit attempt would fail. v1 of this change
auto-installed hawkeye via `exec install-hawkeye.sh` when it was
missing, but `curl | sh` without prior user consent is a security
anti-pattern.

This change instead:

- Makes the missing-hawkeye path interactive by default: print exactly
  what would be downloaded and from where, then prompt `[y/N]`.
- Supports two ways to skip the prompt non-interactively (matching the
  convention used by terraform, kubectl, apt-get, etc.):
    - CLI flag: `--auto-install` (or `-y`)
    - Env var:  HAWKEYE_AUTO_INSTALL=1
  Precedence: flag > env var > prompt (default).
- Refuses to install silently when stdin is not a TTY *and* neither
  consent mechanism was provided, with a clear error pointing at both
  knobs. This protects piped or CI invocations that forgot to opt in.
- Wires `make pre-commit` to run the ensure script after installing
  the hook, so contributors hit the consent prompt at setup time rather
  than at their first commit.
- Exports HAWKEYE_AUTO_INSTALL=1 in the GitHub Actions `Check
  formatting` step so license/format checks don't stall on the prompt.

Fixes apple#1642.
@harshitsinghbhandari harshitsinghbhandari force-pushed the fix/hawkeye-auto-install branch from dfaddfc to d19291d Compare June 5, 2026 00:12
@harshitsinghbhandari

Copy link
Copy Markdown
Contributor Author

Applied your suggestion in d19291d. The prompt is now:

Checking existence of hawkeye...

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.)

Proceed with install? [y/N]

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Code Coverage

Tier Line Coverage
Unit 34.63%
Integration 19.75%
Combined 53.75%

@jglogan jglogan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshitsinghbhandari Looks good, thank you for cleaning this up!

@jglogan jglogan merged commit 79f797b into apple:main Jun 5, 2026
5 of 6 checks passed
@harshitsinghbhandari harshitsinghbhandari deleted the fix/hawkeye-auto-install branch June 5, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 'make pre-commit' installs the hook but does not install hawkeye, so first commit always fails

2 participants