diff options
Diffstat (limited to 'scripts/prepare-release.sh')
| -rwxr-xr-x | scripts/prepare-release.sh | 206 |
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 | ||
| 2 | set -euo pipefail | ||
| 3 | |||
| 4 | # Script to prepare release artifacts | ||
| 5 | # Builds binaries, creates checksums, and prepares release notes | ||
| 6 | |||
| 7 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| 8 | PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| 9 | BINARY_NAME="oar-p2p" | ||
| 10 | |||
| 11 | # Parse command line arguments | ||
| 12 | VERSION="${1:-}" | ||
| 13 | OUTPUT_DIR="${2:-$PROJECT_ROOT/dist}" | ||
| 14 | |||
| 15 | # Colors for output | ||
| 16 | RED='\033[0;31m' | ||
| 17 | GREEN='\033[0;32m' | ||
| 18 | YELLOW='\033[1;33m' | ||
| 19 | BLUE='\033[0;34m' | ||
| 20 | NC='\033[0m' # No Color | ||
| 21 | |||
| 22 | log_info() { | ||
| 23 | echo -e "${GREEN}[INFO]${NC} $1" | ||
| 24 | } | ||
| 25 | |||
| 26 | log_error() { | ||
| 27 | echo -e "${RED}[ERROR]${NC} $1" >&2 | ||
| 28 | } | ||
| 29 | |||
| 30 | log_warn() { | ||
| 31 | echo -e "${YELLOW}[WARN]${NC} $1" | ||
| 32 | } | ||
| 33 | |||
| 34 | # Ensure we're in the project root | ||
| 35 | cd "$PROJECT_ROOT" | ||
| 36 | |||
| 37 | # Check if version is provided | ||
| 38 | if [ -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 | ||
| 43 | fi | ||
| 44 | |||
| 45 | # Remove 'v' prefix if present for consistency | ||
| 46 | VERSION_NUMBER="${VERSION#v}" | ||
| 47 | |||
| 48 | log_info "Preparing release for version: $VERSION_NUMBER" | ||
| 49 | |||
| 50 | # Create output directories | ||
| 51 | BUILD_DIR="$PROJECT_ROOT/target/release-static" | ||
| 52 | mkdir -p "$OUTPUT_DIR" | ||
| 53 | mkdir -p "$BUILD_DIR" | ||
| 54 | |||
| 55 | # Build all binaries | ||
| 56 | log_info "Building static binaries for all platforms..." | ||
| 57 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
| 58 | # On macOS, build all platforms | ||
| 59 | "$SCRIPT_DIR/build-static.sh" all "$BUILD_DIR" | ||
| 60 | else | ||
| 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" | ||
| 65 | fi | ||
| 66 | |||
| 67 | # Function to create tarball for a binary | ||
| 68 | create_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 | |||
| 87 | Platform: ${platform_name} | ||
| 88 | |||
| 89 | ## Installation | ||
| 90 | |||
| 91 | 1. Extract the binary: | ||
| 92 | \`\`\`bash | ||
| 93 | tar -xzf $tarball_name | ||
| 94 | \`\`\` | ||
| 95 | |||
| 96 | 2. Move to a directory in your PATH: | ||
| 97 | \`\`\`bash | ||
| 98 | sudo mv $BINARY_NAME /usr/local/bin/ | ||
| 99 | \`\`\` | ||
| 100 | |||
| 101 | 3. Verify installation: | ||
| 102 | \`\`\`bash | ||
| 103 | $BINARY_NAME --version | ||
| 104 | \`\`\` | ||
| 105 | |||
| 106 | ## Usage | ||
| 107 | |||
| 108 | Run \`$BINARY_NAME --help\` for usage information. | ||
| 109 | |||
| 110 | EOF | ||
| 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 | ||
| 122 | log_info "Creating release tarballs..." | ||
| 123 | for binary in "$BUILD_DIR"/${BINARY_NAME}-*; do | ||
| 124 | if [ -f "$binary" ]; then | ||
| 125 | create_tarball "$binary" | ||
| 126 | fi | ||
| 127 | done | ||
| 128 | |||
| 129 | # Generate checksums | ||
| 130 | log_info "Generating checksums..." | ||
| 131 | cd "$OUTPUT_DIR" | ||
| 132 | |||
| 133 | # Create SHA256 checksums | ||
| 134 | if command -v sha256sum >/dev/null 2>&1; then | ||
| 135 | sha256sum *.tar.gz > "checksums-sha256.txt" | ||
| 136 | elif command -v shasum >/dev/null 2>&1; then | ||
| 137 | shasum -a 256 *.tar.gz > "checksums-sha256.txt" | ||
| 138 | else | ||
| 139 | log_warn "SHA256 checksum tool not found, skipping checksums" | ||
| 140 | fi | ||
| 141 | |||
| 142 | # Create SHA512 checksums | ||
| 143 | if command -v sha512sum >/dev/null 2>&1; then | ||
| 144 | sha512sum *.tar.gz > "checksums-sha512.txt" | ||
| 145 | elif command -v shasum >/dev/null 2>&1; then | ||
| 146 | shasum -a 512 *.tar.gz > "checksums-sha512.txt" | ||
| 147 | fi | ||
| 148 | |||
| 149 | # Generate release notes template | ||
| 150 | log_info "Generating release notes template..." | ||
| 151 | cat > "$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 | ||
| 164 | curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-linux-x86_64.tar.gz | tar -xz | ||
| 165 | sudo mv $BINARY_NAME /usr/local/bin/ | ||
| 166 | |||
| 167 | # macOS Intel | ||
| 168 | curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-macos-x86_64.tar.gz | tar -xz | ||
| 169 | sudo mv $BINARY_NAME /usr/local/bin/ | ||
| 170 | |||
| 171 | # macOS Apple Silicon | ||
| 172 | curl -L https://github.com/diogo464/oar-p2p/releases/download/v$VERSION_NUMBER/${BINARY_NAME}-${VERSION_NUMBER}-macos-aarch64.tar.gz | tar -xz | ||
| 173 | sudo 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 | |||
| 190 | See the full changelog at: https://github.com/diogo464/oar-p2p/compare/v<PREVIOUS_VERSION>...v$VERSION_NUMBER | ||
| 191 | |||
| 192 | EOF | ||
| 193 | |||
| 194 | # List all artifacts | ||
| 195 | log_info "Release artifacts created in: $OUTPUT_DIR" | ||
| 196 | echo -e "${BLUE}Contents:${NC}" | ||
| 197 | ls -lh "$OUTPUT_DIR" | ||
| 198 | |||
| 199 | # Print summary | ||
| 200 | echo | ||
| 201 | log_info "Release preparation complete!" | ||
| 202 | echo -e "${BLUE}Next steps:${NC}" | ||
| 203 | echo "1. Review and edit the release notes: $OUTPUT_DIR/RELEASE_NOTES.md" | ||
| 204 | echo "2. Create a git tag: git tag -a v$VERSION_NUMBER -m \"Release v$VERSION_NUMBER\"" | ||
| 205 | echo "3. Push the tag: git push origin v$VERSION_NUMBER" | ||
| 206 | echo "4. The GitHub Action will automatically create the release and upload artifacts" \ No newline at end of file | ||
