forked from avengineers/hammocking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·170 lines (136 loc) · 3.67 KB
/
build.sh
File metadata and controls
executable file
·170 lines (136 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
#
# Build script for hammocking project on Linux/macOS
# This is the equivalent of build.ps1 for Unix-like systems
#
set -euo pipefail # Exit on error, undefined vars, pipe failures
# Colors for output
readonly BLUE='\033[0;34m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly RED='\033[0;31m'
readonly NC='\033[0m' # No Color
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Parse arguments
CLEAN=false
INSTALL_ONLY=false
print_usage() {
cat << EOF
Usage: $0 [OPTIONS]
Build and test the hammocking project
OPTIONS:
-c, --clean Clean build (remove all build artifacts)
-i, --install Only install dependencies, don't build
-h, --help Show this help message
EXAMPLES:
$0 # Normal build
$0 --clean # Clean build
$0 --install # Install dependencies only
EOF
}
log_info() {
echo -e "${BLUE}[INFO]${NC} $*"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $*"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $*"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-c|--clean)
CLEAN=true
shift
;;
-i|--install)
INSTALL_ONLY=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
log_error "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Change to script directory
cd "$SCRIPT_DIR"
log_info "Running in: $(pwd)"
# Check if uv is installed
check_uv() {
if ! command -v uv &> /dev/null; then
log_warn "uv not found. Installing..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add uv to PATH for current session
export PATH="$HOME/.local/bin:$PATH"
if ! command -v uv &> /dev/null; then
log_error "Failed to install uv"
log_info "Please install uv manually: https://docs.astral.sh/uv/getting-started/installation/"
exit 1
fi
log_success "uv installed successfully"
else
log_info "uv found: $(uv --version)"
fi
}
# Clean build artifacts
clean_build() {
log_info "Cleaning build artifacts..."
if [ -d ".venv" ]; then
log_info "Removing virtual environment..."
rm -rf .venv
fi
if [ -d "build" ]; then
rm -rf build
fi
# Remove Python cache
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
log_success "Cleanup completed"
}
# Install dependencies
install_dependencies() {
log_info "Installing dependencies..."
check_uv
# Install dependencies with uv
uv sync
log_success "Dependencies installed"
}
# Main build function
main() {
log_info "Starting build process..."
echo ""
# Clean if requested
if [ "$CLEAN" = true ]; then
clean_build
echo ""
fi
# Install dependencies
install_dependencies
echo ""
# If install only, exit here
if [ "$INSTALL_ONLY" = true ]; then
log_success "Installation completed"
exit 0
fi
# Run pypeline (CI-agnostic pipeline runner)
log_info "Running pypeline..."
uv run pypeline run
log_success "===================================="
log_success "Build completed successfully!"
log_success "===================================="
}
# Run main function
main