blob: ba654e2313bc8070e4da82298f19fd6845724ce3 (
plain)
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
|
#!/bin/bash
set -euo pipefail
# Script to prepare release artifacts
# Builds binaries, creates checksums, and prepares release notes
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BINARY_NAME="oar-p2p"
# Parse command line arguments
VERSION="${1:-}"
OUTPUT_DIR="${2:-$PROJECT_ROOT/dist}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
# Ensure we're in the project root
cd "$PROJECT_ROOT"
# Check if version is provided
if [ -z "$VERSION" ]; then
log_error "Version not provided"
echo "Usage: $0 <version> [output_dir]"
echo "Example: $0 v1.0.0"
exit 1
fi
# Remove 'v' prefix if present for consistency
VERSION_NUMBER="${VERSION#v}"
log_info "Preparing release for version: $VERSION_NUMBER"
# Create output directories
BUILD_DIR="$PROJECT_ROOT/target/release-static"
mkdir -p "$OUTPUT_DIR"
mkdir -p "$BUILD_DIR"
# Build all binaries
log_info "Building static binaries for all platforms..."
if [[ "$OSTYPE" == "darwin"* ]]; then
# On macOS, build all platforms
"$SCRIPT_DIR/build-static.sh" all "$BUILD_DIR"
else
# On Linux, only build Linux binaries
log_warn "Running on Linux - only Linux binaries will be built"
log_info "macOS binaries must be built on macOS or in CI"
"$SCRIPT_DIR/build-static.sh" linux "$BUILD_DIR"
fi
# Function to create tarball for a binary
create_tarball() {
local binary_path="$1"
local binary_name="$(basename "$binary_path")"
local platform_name="${binary_name#$BINARY_NAME-}"
local tarball_name="${BINARY_NAME}-${VERSION_NUMBER}-${platform_name}.tar.gz"
log_info "Creating tarball: $tarball_name"
# Create temporary directory for tarball contents
local temp_dir="$(mktemp -d)"
# Copy binary to temp directory
cp "$binary_path" "$temp_dir/$BINARY_NAME"
chmod +x "$temp_dir/$BINARY_NAME"
# Create README for the tarball
cat > "$temp_dir/README.md" << EOF
# $BINARY_NAME v$VERSION_NUMBER
Platform: ${platform_name}
## Installation
1. Extract the binary:
\`\`\`bash
tar -xzf $tarball_name
\`\`\`
2. Move to a directory in your PATH:
\`\`\`bash
sudo mv $BINARY_NAME /usr/local/bin/
\`\`\`
3. Verify installation:
\`\`\`bash
$BINARY_NAME --version
\`\`\`
## Usage
Run \`$BINARY_NAME --help\` for usage information.
EOF
# Create tarball
tar -czf "$OUTPUT_DIR/$tarball_name" -C "$temp_dir" .
# Cleanup
rm -rf "$temp_dir"
return 0
}
# Create tarballs for all binaries
log_info "Creating release tarballs..."
for binary in "$BUILD_DIR"/${BINARY_NAME}-*; do
if [ -f "$binary" ]; then
create_tarball "$binary"
fi
done
# Generate checksums
log_info "Generating checksums..."
cd "$OUTPUT_DIR"
# Create SHA256 checksums
if command -v sha256sum >/dev/null 2>&1; then
sha256sum *.tar.gz > "checksums-sha256.txt"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 *.tar.gz > "checksums-sha256.txt"
else
log_warn "SHA256 checksum tool not found, skipping checksums"
fi
# Create SHA512 checksums
if command -v sha512sum >/dev/null 2>&1; then
sha512sum *.tar.gz > "checksums-sha512.txt"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 512 *.tar.gz > "checksums-sha512.txt"
fi
# Generate release notes template
log_info "Generating release notes template..."
cat > "$OUTPUT_DIR/RELEASE_NOTES.md" << EOF
# Release Notes - $BINARY_NAME v$VERSION_NUMBER
## What's Changed
<!-- Add your changes here -->
## Installation
### Using curl (Linux/macOS)
\`\`\`bash
# Linux x86_64
curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-linux-x86_64.tar.gz | tar -xz
sudo mv $BINARY_NAME /usr/local/bin/
# macOS Intel
curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-macos-x86_64.tar.gz | tar -xz
sudo mv $BINARY_NAME /usr/local/bin/
# macOS Apple Silicon
curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-macos-aarch64.tar.gz | tar -xz
sudo mv $BINARY_NAME /usr/local/bin/
\`\`\`
## Checksums
### SHA256
\`\`\`
$(cat checksums-sha256.txt 2>/dev/null || echo "Checksums will be generated during release")
\`\`\`
### SHA512
\`\`\`
$(cat checksums-sha512.txt 2>/dev/null || echo "Checksums will be generated during release")
\`\`\`
## Full Changelog
See the full changelog at: https://github.com/diogo464/oar-p2p/compare/v<PREVIOUS_VERSION>...v$VERSION_NUMBER
EOF
# List all artifacts
log_info "Release artifacts created in: $OUTPUT_DIR"
echo -e "${BLUE}Contents:${NC}"
ls -lh "$OUTPUT_DIR"
# Print summary
echo
log_info "Release preparation complete!"
echo -e "${BLUE}Next steps:${NC}"
echo "1. Review and edit the release notes: $OUTPUT_DIR/RELEASE_NOTES.md"
echo "2. Create a git tag: git tag -a v$VERSION_NUMBER -m \"Release v$VERSION_NUMBER\""
echo "3. Push the tag: git push origin v$VERSION_NUMBER"
echo "4. The GitHub Action will automatically create the release and upload artifacts"
|