aboutsummaryrefslogtreecommitdiff
path: root/scripts/prepare-release.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/prepare-release.sh')
-rwxr-xr-xscripts/prepare-release.sh206
1 files changed, 206 insertions, 0 deletions
diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh
new file mode 100755
index 0000000..ba654e2
--- /dev/null
+++ b/scripts/prepare-release.sh
@@ -0,0 +1,206 @@
1#!/bin/bash
2set -euo pipefail
3
4# Script to prepare release artifacts
5# Builds binaries, creates checksums, and prepares release notes
6
7SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
9BINARY_NAME="oar-p2p"
10
11# Parse command line arguments
12VERSION="${1:-}"
13OUTPUT_DIR="${2:-$PROJECT_ROOT/dist}"
14
15# Colors for output
16RED='\033[0;31m'
17GREEN='\033[0;32m'
18YELLOW='\033[1;33m'
19BLUE='\033[0;34m'
20NC='\033[0m' # No Color
21
22log_info() {
23 echo -e "${GREEN}[INFO]${NC} $1"
24}
25
26log_error() {
27 echo -e "${RED}[ERROR]${NC} $1" >&2
28}
29
30log_warn() {
31 echo -e "${YELLOW}[WARN]${NC} $1"
32}
33
34# Ensure we're in the project root
35cd "$PROJECT_ROOT"
36
37# Check if version is provided
38if [ -z "$VERSION" ]; then
39 log_error "Version not provided"
40 echo "Usage: $0 <version> [output_dir]"
41 echo "Example: $0 v1.0.0"
42 exit 1
43fi
44
45# Remove 'v' prefix if present for consistency
46VERSION_NUMBER="${VERSION#v}"
47
48log_info "Preparing release for version: $VERSION_NUMBER"
49
50# Create output directories
51BUILD_DIR="$PROJECT_ROOT/target/release-static"
52mkdir -p "$OUTPUT_DIR"
53mkdir -p "$BUILD_DIR"
54
55# Build all binaries
56log_info "Building static binaries for all platforms..."
57if [[ "$OSTYPE" == "darwin"* ]]; then
58 # On macOS, build all platforms
59 "$SCRIPT_DIR/build-static.sh" all "$BUILD_DIR"
60else
61 # On Linux, only build Linux binaries
62 log_warn "Running on Linux - only Linux binaries will be built"
63 log_info "macOS binaries must be built on macOS or in CI"
64 "$SCRIPT_DIR/build-static.sh" linux "$BUILD_DIR"
65fi
66
67# Function to create tarball for a binary
68create_tarball() {
69 local binary_path="$1"
70 local binary_name="$(basename "$binary_path")"
71 local platform_name="${binary_name#$BINARY_NAME-}"
72 local tarball_name="${BINARY_NAME}-${VERSION_NUMBER}-${platform_name}.tar.gz"
73
74 log_info "Creating tarball: $tarball_name"
75
76 # Create temporary directory for tarball contents
77 local temp_dir="$(mktemp -d)"
78
79 # Copy binary to temp directory
80 cp "$binary_path" "$temp_dir/$BINARY_NAME"
81 chmod +x "$temp_dir/$BINARY_NAME"
82
83 # Create README for the tarball
84 cat > "$temp_dir/README.md" << EOF
85# $BINARY_NAME v$VERSION_NUMBER
86
87Platform: ${platform_name}
88
89## Installation
90
911. Extract the binary:
92 \`\`\`bash
93 tar -xzf $tarball_name
94 \`\`\`
95
962. Move to a directory in your PATH:
97 \`\`\`bash
98 sudo mv $BINARY_NAME /usr/local/bin/
99 \`\`\`
100
1013. Verify installation:
102 \`\`\`bash
103 $BINARY_NAME --version
104 \`\`\`
105
106## Usage
107
108Run \`$BINARY_NAME --help\` for usage information.
109
110EOF
111
112 # Create tarball
113 tar -czf "$OUTPUT_DIR/$tarball_name" -C "$temp_dir" .
114
115 # Cleanup
116 rm -rf "$temp_dir"
117
118 return 0
119}
120
121# Create tarballs for all binaries
122log_info "Creating release tarballs..."
123for binary in "$BUILD_DIR"/${BINARY_NAME}-*; do
124 if [ -f "$binary" ]; then
125 create_tarball "$binary"
126 fi
127done
128
129# Generate checksums
130log_info "Generating checksums..."
131cd "$OUTPUT_DIR"
132
133# Create SHA256 checksums
134if command -v sha256sum >/dev/null 2>&1; then
135 sha256sum *.tar.gz > "checksums-sha256.txt"
136elif command -v shasum >/dev/null 2>&1; then
137 shasum -a 256 *.tar.gz > "checksums-sha256.txt"
138else
139 log_warn "SHA256 checksum tool not found, skipping checksums"
140fi
141
142# Create SHA512 checksums
143if command -v sha512sum >/dev/null 2>&1; then
144 sha512sum *.tar.gz > "checksums-sha512.txt"
145elif command -v shasum >/dev/null 2>&1; then
146 shasum -a 512 *.tar.gz > "checksums-sha512.txt"
147fi
148
149# Generate release notes template
150log_info "Generating release notes template..."
151cat > "$OUTPUT_DIR/RELEASE_NOTES.md" << EOF
152# Release Notes - $BINARY_NAME v$VERSION_NUMBER
153
154## What's Changed
155
156<!-- Add your changes here -->
157
158## Installation
159
160### Using curl (Linux/macOS)
161
162\`\`\`bash
163# Linux x86_64
164curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-linux-x86_64.tar.gz | tar -xz
165sudo mv $BINARY_NAME /usr/local/bin/
166
167# macOS Intel
168curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-macos-x86_64.tar.gz | tar -xz
169sudo mv $BINARY_NAME /usr/local/bin/
170
171# macOS Apple Silicon
172curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-macos-aarch64.tar.gz | tar -xz
173sudo mv $BINARY_NAME /usr/local/bin/
174\`\`\`
175
176## Checksums
177
178### SHA256
179\`\`\`
180$(cat checksums-sha256.txt 2>/dev/null || echo "Checksums will be generated during release")
181\`\`\`
182
183### SHA512
184\`\`\`
185$(cat checksums-sha512.txt 2>/dev/null || echo "Checksums will be generated during release")
186\`\`\`
187
188## Full Changelog
189
190See the full changelog at: https://github.com/diogo464/oar-p2p/compare/v<PREVIOUS_VERSION>...v$VERSION_NUMBER
191
192EOF
193
194# List all artifacts
195log_info "Release artifacts created in: $OUTPUT_DIR"
196echo -e "${BLUE}Contents:${NC}"
197ls -lh "$OUTPUT_DIR"
198
199# Print summary
200echo
201log_info "Release preparation complete!"
202echo -e "${BLUE}Next steps:${NC}"
203echo "1. Review and edit the release notes: $OUTPUT_DIR/RELEASE_NOTES.md"
204echo "2. Create a git tag: git tag -a v$VERSION_NUMBER -m \"Release v$VERSION_NUMBER\""
205echo "3. Push the tag: git push origin v$VERSION_NUMBER"
206echo "4. The GitHub Action will automatically create the release and upload artifacts" \ No newline at end of file