|
1 | 1 | #!/usr/bin/env bash |
2 | | -# devbox-init.sh - one-time setup for local dev environments |
| 2 | +# devbox-init.sh - Development environment setup for sley CLI |
| 3 | +# Called automatically by devbox shell init_hook |
| 4 | + |
3 | 5 | set -eu |
4 | 6 |
|
5 | | -# -------- Config -------- |
6 | | -. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/common.sh |
| 7 | +# Load common utilities |
| 8 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | +# shellcheck source=lib/common.sh |
| 10 | +source "${SCRIPT_DIR}/lib/common.sh" |
7 | 11 |
|
8 | | -# -------- Start -------- |
9 | | -h1 'Welcome to the sley devbox!' |
| 12 | +h1 "sley CLI - Development Environment Setup" |
10 | 13 |
|
11 | | -log_default "" |
| 14 | +# === Go Dependencies === |
| 15 | +h2 "Go Dependencies" |
12 | 16 |
|
13 | | -# Go dependencies and tools |
14 | | -log_info 'Setting up Go dependencies and tools...' |
15 | | -if [ -f "go.mod" ]; then |
16 | | - log_info 'Downloading Go modules...' |
17 | | - (go mod download) |
18 | | - log_success 'Go modules downloaded' |
| 17 | +if command_exists go; then |
| 18 | + if [ -f "go.mod" ]; then |
| 19 | + log_info "Downloading Go modules..." |
| 20 | + go mod download |
| 21 | + log_success "Go modules downloaded" |
| 22 | + else |
| 23 | + log_warning "go.mod not found - skipping Go module download" |
| 24 | + fi |
19 | 25 | else |
20 | | - log_warning 'go.mod not found - skipping Go module download' |
| 26 | + log_warning "Go not found, skipping module download" |
21 | 27 | fi |
22 | 28 |
|
23 | | -if command -v go >/dev/null 2>&1; then |
24 | | - log_info 'Installing Go tools...' |
| 29 | +# === Go Tools === |
| 30 | +h2 "Go Tools" |
25 | 31 |
|
26 | | - if go install golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest; then |
27 | | - log_success 'go-modernize installed' |
28 | | - else |
29 | | - log_warning 'Failed to install go-modernize' |
30 | | - fi |
| 32 | +if command_exists go; then |
| 33 | + install_go_tool "modernize" "golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest" |
| 34 | + install_go_tool "govulncheck" "golang.org/x/vuln/cmd/govulncheck@latest" |
31 | 35 |
|
32 | | - if go install golang.org/x/vuln/cmd/govulncheck@latest; then |
33 | | - log_success 'govulncheck installed' |
34 | | - else |
35 | | - log_warning 'Failed to install govulncheck' |
36 | | - fi |
37 | | - |
38 | | - # goreportcard-cli requires manual installation: |
39 | | - # git clone https://github.com/gojp/goreportcard.git && cd goreportcard && make install && go install ./cmd/goreportcard-cli |
40 | | - if command -v goreportcard-cli >/dev/null 2>&1; then |
41 | | - log_success 'goreportcard-cli already installed' |
42 | | - else |
43 | | - log_faint 'goreportcard-cli not installed (optional) - see: https://github.com/gojp/goreportcard' |
44 | | - fi |
| 36 | + # goreportcard-cli requires manual installation: |
| 37 | + # git clone https://github.com/gojp/goreportcard.git && cd goreportcard && make install && go install ./cmd/goreportcard-cli |
| 38 | + if command_exists goreportcard-cli; then |
| 39 | + log_faint "goreportcard-cli already installed" |
| 40 | + else |
| 41 | + log_faint "goreportcard-cli not installed (optional) - see: https://github.com/gojp/goreportcard" |
| 42 | + fi |
45 | 43 | else |
46 | | - log_warning 'Go not available - skipping Go tools installation' |
| 44 | + log_warning "Go not available - skipping Go tools installation" |
47 | 45 | fi |
48 | 46 |
|
49 | | -log_default "" |
| 47 | +# === Git Hooks === |
| 48 | +h2 "Git Hooks" |
50 | 49 |
|
51 | | -# Git hooks (prek) |
52 | | -log_info 'Setting up Git hooks with prek...' |
53 | 50 | # Ensure custom hooks are executable |
54 | | -if [ -f scripts/githooks/commit-msg ]; then |
55 | | - chmod +x scripts/githooks/commit-msg |
56 | | -fi |
57 | | -if [ -f scripts/githooks/pre-push ]; then |
58 | | - chmod +x scripts/githooks/pre-push |
59 | | -fi |
60 | | -log_success 'Custom hooks made executable' |
| 51 | +for hook in scripts/githooks/commit-msg scripts/githooks/pre-push; do |
| 52 | + if [ -f "$hook" ]; then |
| 53 | + chmod +x "$hook" |
| 54 | + fi |
| 55 | +done |
| 56 | +log_success "Custom hooks made executable" |
61 | 57 |
|
62 | 58 | if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then |
63 | | - if command -v prek >/dev/null 2>&1; then |
64 | | - # Install prek hooks for commit-msg and pre-push stages |
65 | | - if prek install --hook-type commit-msg --hook-type pre-push; then |
66 | | - log_success 'prek hooks installed (commit-msg, pre-push)' |
| 59 | + if command_exists prek; then |
| 60 | + log_info "Installing git hooks via prek..." |
| 61 | + prek install --hook-type commit-msg --hook-type pre-push && log_success "Git hooks installed (commit-msg, pre-push)" || log_warning "Failed to install git hooks" |
67 | 62 | else |
68 | | - log_warning 'Failed to install prek hooks' |
| 63 | + log_warning "prek not found - run: cargo install prek" |
69 | 64 | fi |
70 | | - else |
71 | | - log_warning 'prek not installed - run: cargo install prek' |
72 | | - fi |
73 | 65 | else |
74 | | - log_warning 'not a git repository - skipping hooks installation' |
| 66 | + log_warning "Not a git repository - skipping hooks installation" |
75 | 67 | fi |
76 | 68 |
|
77 | | -log_default "" |
78 | | -# Helpful commands |
79 | | -h3 'Available just commands:' |
80 | | -cat <<'TXT' |
81 | | - just help - Show help message |
82 | | - just all - Clean and build |
83 | | - just clean - Clean the build directory and Go cache |
84 | | - just test - Run all tests and generate coverage report |
85 | | - just test-force - Clean go tests cache and run all tests |
86 | | - just modernize - Run go-modernize with auto-fix |
87 | | - just check - Run modernize, lint, and test |
88 | | - just lint - Run golangci-lint |
89 | | - just build - Build the binary to build/sley |
90 | | - just install - Install the binary using Go install |
91 | | -
|
92 | | -Quick start: `just check` to run all quality checks! |
93 | | -TXT |
| 69 | +# === Summary === |
| 70 | +h1 "Setup Complete" |
94 | 71 |
|
95 | | -# End |
96 | | -printf '\n%s\n\n' '====================================' |
| 72 | +log_default "" |
| 73 | +log_info "Available commands:" |
| 74 | +log_faint " just build - Build the binary with optimizations (reduced size)" |
| 75 | +log_faint " just install - Install the binary using Go install" |
| 76 | +log_faint " just clean - Clean the build directory and Go cache" |
| 77 | +log_faint " just all - Clean and build" |
| 78 | +log_faint " just fmt - Format code" |
| 79 | +log_faint " just modernize - Run go-modernize with auto-fix" |
| 80 | +log_faint " just lint - Run golangci-lint" |
| 81 | +log_faint " just reportcard - Run goreportcard-cli" |
| 82 | +log_faint " just check - Run modernize, lint, and reportcard" |
| 83 | +log_faint " just security-scan - Run govulncheck" |
| 84 | +log_faint " just test - Run all tests and print code coverage value" |
| 85 | +log_faint " just test-force - Clean go tests cache and run all tests" |
| 86 | +log_faint " just test-coverage - Run all tests and generate coverage report" |
| 87 | +log_faint " just test-race - Run all tests with race detector" |
| 88 | +log_faint " just deps - Run go mod download" |
| 89 | +log_faint " just deps-update - Update dependencies" |
| 90 | +log_faint " just tidy - Run go mod tidy" |
| 91 | +log_default "" |
| 92 | +log_faint "Quick start: just check to run all quality checks!" |
| 93 | +log_default "" |
0 commit comments