Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·285 lines (227 loc) · 6.21 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·285 lines (227 loc) · 6.21 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/env bash
# LogView Build Script
# Builds distribution wheel and generates checksums for release
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print colored output
info() {
echo -e "${BLUE}ℹ${NC} $1"
}
success() {
echo -e "${GREEN}✓${NC} $1"
}
warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
error() {
echo -e "${RED}✗${NC} $1" >&2
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check prerequisites
check_prerequisites() {
info "Checking build prerequisites..."
if ! command_exists python3; then
error "Python 3 is required to build"
exit 1
fi
# Check if build module is installed
if ! python3 -c "import build" 2>/dev/null; then
info "Installing build module..."
python3 -m pip install --upgrade build
fi
success "Prerequisites OK"
}
# Clean previous builds
clean_build() {
info "Cleaning previous build artifacts..."
rm -rf dist/ build/
rm -rf ./*.egg-info
success "Clean complete"
}
# Read version from VERSION file
get_version() {
if [[ ! -f VERSION ]]; then
error "VERSION file not found"
exit 1
fi
local version
version=$(cat VERSION)
# Validate semver format (MAJOR.MINOR.PATCH with optional pre-release/build)
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
error "Invalid version format in VERSION file: $version"
error "Expected semver format: MAJOR.MINOR.PATCH (e.g., 0.2.0)"
exit 1
fi
echo "$version"
}
# Build wheel
build_wheel() {
info "Building wheel..."
if python3 -m build --wheel; then
success "Wheel built successfully"
else
error "Wheel build failed"
exit 1
fi
}
# Build source distribution
build_sdist() {
info "Building source distribution..."
if python3 -m build --sdist; then
success "Source distribution built successfully"
else
error "Source distribution build failed"
exit 1
fi
}
# Generate checksums
generate_checksums() {
info "Generating checksums..."
if [[ ! -d dist ]]; then
error "dist/ directory not found"
exit 1
fi
cd dist
# Find all distribution files using find (safe and explicit)
local files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <(find . -maxdepth 1 \( -name "*.whl" -o -name "*.tar.gz" \) -print0)
if [[ ${#files[@]} -eq 0 ]]; then
warning "No .whl or .tar.gz files found, skipping checksum generation"
cd ..
return
fi
# Generate SHA256 checksums for found files
if command_exists shasum; then
if shasum -a 256 "${files[@]}"; then
shasum -a 256 "${files[@]}" > SHA256SUMS
else
error "Checksum generation failed"
cd ..
exit 1
fi
elif command_exists sha256sum; then
if sha256sum "${files[@]}"; then
sha256sum "${files[@]}" > SHA256SUMS
else
error "Checksum generation failed"
cd ..
exit 1
fi
else
warning "shasum/sha256sum not found, skipping checksum generation"
cd ..
return
fi
cd ..
success "Checksums generated: dist/SHA256SUMS"
}
# List build artifacts
list_artifacts() {
echo ""
info "Build artifacts:"
echo ""
if [[ -d dist ]]; then
ls -lh dist/
fi
echo ""
}
# Verify wheel contents
verify_wheel() {
info "Verifying wheel contents..."
local wheel_file
wheel_file=$(find dist -name "*.whl" | head -n 1)
if [[ -z "$wheel_file" ]]; then
error "No wheel file found"
exit 1
fi
info "Wheel file: $wheel_file"
# Check if unzip is available
if command_exists unzip; then
info "Wheel contents:"
unzip -l "$wheel_file" | grep -E "logview/(.*\.py|py\.typed)" | head -20
if [[ $(unzip -l "$wheel_file" | grep -c "logview/") -gt 20 ]]; then
info "... ($(unzip -l "$wheel_file" | grep -c "logview/") total files)"
fi
else
warning "unzip not found, skipping wheel content verification"
fi
success "Wheel verification complete"
}
# Create release notes template
create_release_notes() {
local version
version=$(get_version)
info "Creating release notes template..."
cat > RELEASE_NOTES.md << EOF
# LogView v${version}
## What's New
<!-- Describe new features and changes -->
## Bug Fixes
<!-- List bug fixes -->
## Installation
### Quick Install (Recommended)
\`\`\`bash
curl -fsSL https://raw.githubusercontent.com/agileguy/logview/v${version}/install.sh | bash
\`\`\`
### Using pip
\`\`\`bash
pip install logview==${version}
# With GCP/GKE support
pip install logview[all]==${version}
\`\`\`
### Using pipx
\`\`\`bash
pipx install logview==${version}
\`\`\`
## Checksums
\`\`\`
$(cat dist/SHA256SUMS 2>/dev/null || echo "Checksums will be added during release")
\`\`\`
## Full Changelog
See [CHANGELOG.md](https://github.com/agileguy/logview/blob/main/CHANGELOG.md) for detailed changes.
EOF
success "Release notes template created: RELEASE_NOTES.md"
}
# Main build flow
main() {
echo ""
info "LogView Build Script"
echo ""
local version
version=$(get_version)
info "Building version: $version"
echo ""
check_prerequisites
clean_build
build_wheel
build_sdist
generate_checksums
verify_wheel
list_artifacts
create_release_notes
echo ""
success "Build complete!"
echo ""
info "Next steps:"
info " 1. Review dist/ artifacts"
info " 2. Test local installation: pip install dist/logview-${version}-py3-none-any.whl"
info " 3. Update RELEASE_NOTES.md with changes"
info " 4. Create git tag: git tag v${version}"
info " 5. Push tag: git push origin v${version}"
info " 6. Upload to PyPI: twine upload dist/*"
info " 7. Test install.sh AFTER PyPI publication:"
info " curl -fsSL https://raw.githubusercontent.com/agileguy/logview/v${version}/install.sh | bash"
info " 8. Create GitHub release with dist/ artifacts and RELEASE_NOTES.md"
echo ""
}
main "$@"