-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(hooks): add Husky git hooks for ui/goose2 #8577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
709aec5
7a4d063
4170a56
71e9a38
df76bc1
705b8eb
9e94160
5fc9153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # Only auto-format desktop TS code if relevant files are modified | ||
| if git diff --cached --name-only | grep -q "^ui/desktop/"; then | ||
| if git diff --cached --no-renames --name-only | grep -q "^ui/desktop/"; then | ||
| if [ -d "ui/desktop" ]; then | ||
| cd ui/desktop && pnpm exec lint-staged | ||
| (cd ui/desktop && pnpm exec lint-staged) | ||
| else | ||
| echo "Warning: ui/desktop directory does not exist, skipping lint-staged" | ||
| fi | ||
| fi | ||
|
|
||
| # Run goose2 checks if any staged files are under ui/goose2/ | ||
| if git diff --cached --no-renames --name-only | grep -q '^ui/goose2/'; then | ||
| if [ -d "ui/goose2" ]; then | ||
| REPO_ROOT="$(pwd)" | ||
| echo "Running goose2 pre-commit checks..." | ||
|
|
||
| # Auto-format only staged files and re-stage them | ||
| STAGED_FILES=$(git diff --cached --no-renames --diff-filter=ACMR --name-only | grep '^ui/goose2/' | sed 's|^ui/goose2/||' || true) | ||
| if [ -n "$STAGED_FILES" ]; then | ||
| cd ui/goose2 | ||
| echo "$STAGED_FILES" | xargs npx biome format --write | ||
| echo "$STAGED_FILES" | xargs npx biome check --fix | ||
| cd "$REPO_ROOT" | ||
| git diff --cached --no-renames --diff-filter=ACMR --name-only | grep '^ui/goose2/' | xargs git add | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Re-staging with Useful? React with 👍 / 👎. |
||
| fi | ||
|
|
||
| # Run checks (biome check + file sizes + i18n + typecheck) | ||
| just goose2 check | ||
| else | ||
| echo "Warning: ui/goose2 directory does not exist, skipping goose2 checks" | ||
| fi | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env bash | ||
| # Run goose2 pre-push checks if any commits being pushed include goose2 changes. | ||
|
|
||
| # --- Helper functions --- | ||
|
|
||
| # Check if any ref being pushed includes changes under a given path prefix. | ||
| # Reads git's pre-push stdin (local_ref local_oid remote_ref remote_oid). | ||
| push_touches() { | ||
| local prefix="$1" | ||
| local z40="0000000000000000000000000000000000000000" | ||
|
|
||
| while read local_ref local_oid remote_ref remote_oid; do | ||
| [ "$local_oid" = "$z40" ] && continue # deleting ref | ||
|
|
||
| if [ "$remote_oid" = "$z40" ]; then | ||
| # New branch — compare against the merge base with the default branch | ||
| range="$(git merge-base HEAD main 2>/dev/null || echo "$local_oid")...$local_oid" | ||
|
matt2e marked this conversation as resolved.
|
||
| else | ||
| range="$remote_oid...$local_oid" | ||
| fi | ||
|
|
||
| if git diff --no-renames --name-only "$range" -- 2>/dev/null | grep -q "^${prefix}"; then | ||
| return 0 | ||
| fi | ||
| done | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| # Run commands in parallel, exit 1 if any fail. | ||
| # Usage: run_parallel "label1" "cmd1" "label2" "cmd2" ... | ||
| run_parallel() { | ||
| local -a labels=() pids=() | ||
| while [[ $# -ge 2 ]]; do | ||
|
matt2e marked this conversation as resolved.
|
||
| labels+=("$1"); shift | ||
| ( eval "$1" ) & pids+=($!); shift | ||
| done | ||
|
|
||
| local -a failed=() | ||
| for i in "${!pids[@]}"; do | ||
| wait "${pids[$i]}" || failed+=("${labels[$i]}") | ||
| done | ||
|
|
||
| if [[ ${#failed[@]} -gt 0 ]]; then | ||
| echo "Failed: ${failed[*]}" | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| # --- Hook body --- | ||
|
|
||
| push_touches "ui/goose2/" || exit 0 | ||
|
|
||
| echo "Detected ui/goose2/ changes — running pre-push checks..." | ||
|
|
||
| run_parallel \ | ||
| "fmt-check" "just goose2 fmt-check" \ | ||
| "clippy" "just goose2 clippy" \ | ||
| "check" "just goose2 check" \ | ||
| "test" "just goose2 test" \ | ||
| "build" "just goose2 build" \ | ||
| "tauri-check" "just goose2 tauri-check" | ||
|
|
||
| exit_code=$? | ||
|
|
||
| if [ $exit_code -eq 0 ]; then | ||
| echo "All goose2 pre-push checks passed." | ||
| else | ||
| echo "goose2 pre-push checks failed." | ||
| exit 1 | ||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.