Team Ai
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 21d agoView on Hugging Face
0likes1.2kdownloads
release.sh205 linesDownload Raw Back to scripts
1#!/bin/bash2#3# Release preparation script for llama.cpp.4#5# Bumps the version in CMakeLists.txt on a release candidate branch.6# The branch should then be pushed and a PR created, reviewed, and7# merged. After the PR is merged and the build-cpu workflow has8# completed successfully, the release is finalized by the make-release9# workflow (.github/workflows/make-release.yml), which creates the tag.10#11# Usage:12#   ./scripts/release.sh [major|minor|patch] [--dry-run]13#14# Example:15#   $ ./scripts/release.sh minor16#17# The script:18# 1. Creates a release candidate branch (llama-rc-v<major>.<minor>.<patch>)19# 2. Bumps the version in CMakeLists.txt20# 3. Commits the version bump21#22 23set -e24 25if [ ! -f "CMakeLists.txt" ] || [ ! -d "scripts" ]; then26    echo "Error: Must be run from llama.cpp root directory"27    exit 128fi29 30# Parse command line arguments31VERSION_TYPE=""32DRY_RUN=false33 34for arg in "$@"; do35    case $arg in36        --dry-run)37            DRY_RUN=true38            ;;39        major|minor|patch)40            VERSION_TYPE="$arg"41            ;;42        *)43            echo "Error: Unknown argument '$arg'"44            echo "Usage: $0 [major|minor|patch] [--dry-run]"45            exit 146            ;;47    esac48done49 50# Default to patch if no version type specified51VERSION_TYPE="${VERSION_TYPE:-patch}"52 53# Common validation functions54check_git_status() {55    # Check for uncommitted changes (skip in dry-run)56    if [ "$DRY_RUN" = false ] && ! git diff-index --quiet HEAD --; then57        echo "Error: You have uncommitted changes. Please commit or stash them first."58        exit 159    fi60}61 62check_master_branch() {63    # Ensure we're on master branch64    CURRENT_BRANCH=$(git branch --show-current)65    if [ "$CURRENT_BRANCH" != "master" ]; then66        if [ "$DRY_RUN" = true ]; then67            echo "[dry run] Warning: Not on master branch (currently on: $CURRENT_BRANCH). Continuing with dry-run..."68            echo ""69        else70            echo "Error: Must be on master branch. Currently on: $CURRENT_BRANCH"71            exit 172        fi73    fi74}75 76check_master_up_to_date() {77    # Check if we have the latest from master (skip in dry-run)78    if [ "$DRY_RUN" = false ]; then79        echo "Checking if local master is up-to-date with remote..."80        git fetch origin master81        LOCAL=$(git rev-parse HEAD)82        REMOTE=$(git rev-parse origin/master)83 84        if [ "$LOCAL" != "$REMOTE" ]; then85            echo "Error: Your local master branch is not up-to-date with origin/master."86            echo "Please run 'git pull origin master' first."87            exit 188        fi89        echo "✓ Local master is up-to-date with remote"90        echo ""91    elif [ "$(git branch --show-current)" = "master" ]; then92        echo "[dry run] Warning: Dry-run mode - not checking if master is up-to-date with remote"93        echo ""94    fi95}96 97# In-place sed that works on both GNU (Linux) and BSD (macOS) sed98sed_inplace() {99    if sed --version >/dev/null 2>&1; then100        sed -i "$@"101    else102        sed -i '' "$@"103    fi104}105 106prepare_release() {107    if [ "$DRY_RUN" = true ]; then108        echo "[dry-run] Preparing release (no changes will be made)"109    else110        echo "Starting release preparation..."111    fi112    echo ""113 114    check_git_status115    check_master_branch116    check_master_up_to_date117 118    # Extract current version from CMakeLists.txt119    echo "Step 1: Reading current version..."120    MAJOR=$(grep "set(LLAMA_VERSION_MAJOR" CMakeLists.txt | sed 's/.*MAJOR \([0-9]*\).*/\1/')121    MINOR=$(grep "set(LLAMA_VERSION_MINOR" CMakeLists.txt | sed 's/.*MINOR \([0-9]*\).*/\1/')122    PATCH=$(grep "set(LLAMA_VERSION_PATCH" CMakeLists.txt | sed 's/.*PATCH \([0-9]*\).*/\1/')123 124    echo "Current version: $MAJOR.$MINOR.$PATCH"125 126    # Calculate new version127    case $VERSION_TYPE in128        major)129            NEW_MAJOR=$((MAJOR + 1))130            NEW_MINOR=0131            NEW_PATCH=0132            ;;133        minor)134            NEW_MAJOR=$MAJOR135            NEW_MINOR=$((MINOR + 1))136            NEW_PATCH=0137            ;;138        patch)139            NEW_MAJOR=$MAJOR140            NEW_MINOR=$MINOR141            NEW_PATCH=$((PATCH + 1))142            ;;143    esac144 145    NEW_VERSION="$NEW_MAJOR.$NEW_MINOR.$NEW_PATCH"146    RC_BRANCH="llama-rc-v$NEW_VERSION"147    echo "New release version: $NEW_VERSION"148    echo "Release candidate branch: $RC_BRANCH"149    echo ""150 151    # Create release candidate branch152    echo "Step 2: Creating release candidate branch..."153    if [ "$DRY_RUN" = true ]; then154        echo "  [dry-run] Would create branch: $RC_BRANCH"155    else156        git checkout -b "$RC_BRANCH"157        echo "✓ Created and switched to branch: $RC_BRANCH"158    fi159    echo ""160 161    # Update CMakeLists.txt for release162    echo "Step 3: Updating version in CMakeLists.txt..."163    if [ "$DRY_RUN" = true ]; then164        echo "  [dry-run] Would update LLAMA_VERSION_MAJOR to $NEW_MAJOR"165        echo "  [dry-run] Would update LLAMA_VERSION_MINOR to $NEW_MINOR"166        echo "  [dry-run] Would update LLAMA_VERSION_PATCH to $NEW_PATCH"167    else168        sed_inplace -e "s/set(LLAMA_VERSION_MAJOR [0-9]*)/set(LLAMA_VERSION_MAJOR $NEW_MAJOR)/" CMakeLists.txt169        sed_inplace -e "s/set(LLAMA_VERSION_MINOR [0-9]*)/set(LLAMA_VERSION_MINOR $NEW_MINOR)/" CMakeLists.txt170        sed_inplace -e "s/set(LLAMA_VERSION_PATCH [0-9]*)/set(LLAMA_VERSION_PATCH $NEW_PATCH)/" CMakeLists.txt171    fi172    echo ""173 174    # Commit version bump175    echo "Step 4: Committing version bump..."176    if [ "$DRY_RUN" = true ]; then177        echo "  [dry-run] Would commit: 'llama.cpp : bump version to $NEW_VERSION'"178    else179        git add CMakeLists.txt180        git commit -m "llama.cpp : bump version to $NEW_VERSION"181    fi182    echo ""183 184    echo ""185    if [ "$DRY_RUN" = true ]; then186        echo "[dry-run] Summary (no changes were made):"187        echo "  • Would have created branch: $RC_BRANCH"188        echo "  • Would have updated version to: $NEW_VERSION"189    else190        echo "Release preparation completed!"191        echo "Summary:"192        echo "  • Created branch: $RC_BRANCH"193        echo "  • Updated version to: $NEW_VERSION"194        echo ""195        echo "Next steps:"196        echo "  • Push branch to remote: git push origin $RC_BRANCH"197        echo "  • Create a Pull Request from $RC_BRANCH to master"198        echo "  • After the PR is merged and the build-cpu workflow has passed,"199        echo "    create the release with the make-release workflow"200        echo "    (.github/workflows/make-release.yml)"201    fi202}203 204prepare_release205