char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Georgi Gerganovscripts : add release.sh for release preparation (#27497)c4b0225d8

char/aliceai-t5-moe
6.4 KiB204 linesraw
1#!/bin/bash
2#
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, and
7# merged. After the PR is merged and the build-cpu workflow has
8# completed successfully, the release is finalized by the make-release
9# 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 minor
16#
17# The script:
18# 1. Creates a release candidate branch (llama-rc-v<major>.<minor>.<patch>)
19# 2. Bumps the version in CMakeLists.txt
20# 3. Commits the version bump
21#
22
23set -e
24
25if [ ! -f "CMakeLists.txt" ] || [ ! -d "scripts" ]; then
26    echo "Error: Must be run from llama.cpp root directory"
27    exit 1
28fi
29
30# Parse command line arguments
31VERSION_TYPE=""
32DRY_RUN=false
33
34for arg in "$@"; do
35    case $arg in
36        --dry-run)
37            DRY_RUN=true
38            ;;
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 1
46            ;;
47    esac
48done
49
50# Default to patch if no version type specified
51VERSION_TYPE="${VERSION_TYPE:-patch}"
52
53# Common validation functions
54check_git_status() {
55    # Check for uncommitted changes (skip in dry-run)
56    if [ "$DRY_RUN" = false ] && ! git diff-index --quiet HEAD --; then
57        echo "Error: You have uncommitted changes. Please commit or stash them first."
58        exit 1
59    fi
60}
61
62check_master_branch() {
63    # Ensure we're on master branch
64    CURRENT_BRANCH=$(git branch --show-current)
65    if [ "$CURRENT_BRANCH" != "master" ]; then
66        if [ "$DRY_RUN" = true ]; then
67            echo "[dry run] Warning: Not on master branch (currently on: $CURRENT_BRANCH). Continuing with dry-run..."
68            echo ""
69        else
70            echo "Error: Must be on master branch. Currently on: $CURRENT_BRANCH"
71            exit 1
72        fi
73    fi
74}
75
76check_master_up_to_date() {
77    # Check if we have the latest from master (skip in dry-run)
78    if [ "$DRY_RUN" = false ]; then
79        echo "Checking if local master is up-to-date with remote..."
80        git fetch origin master
81        LOCAL=$(git rev-parse HEAD)
82        REMOTE=$(git rev-parse origin/master)
83
84        if [ "$LOCAL" != "$REMOTE" ]; then
85            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 1
88        fi
89        echo "✓ Local master is up-to-date with remote"
90        echo ""
91    elif [ "$(git branch --show-current)" = "master" ]; then
92        echo "[dry run] Warning: Dry-run mode - not checking if master is up-to-date with remote"
93        echo ""
94    fi
95}
96
97# In-place sed that works on both GNU (Linux) and BSD (macOS) sed
98sed_inplace() {
99    if sed --version >/dev/null 2>&1; then
100        sed -i "$@"
101    else
102        sed -i '' "$@"
103    fi
104}
105
106prepare_release() {
107    if [ "$DRY_RUN" = true ]; then
108        echo "[dry-run] Preparing release (no changes will be made)"
109    else
110        echo "Starting release preparation..."
111    fi
112    echo ""
113
114    check_git_status
115    check_master_branch
116    check_master_up_to_date
117
118    # Extract current version from CMakeLists.txt
119    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 version
127    case $VERSION_TYPE in
128        major)
129            NEW_MAJOR=$((MAJOR + 1))
130            NEW_MINOR=0
131            NEW_PATCH=0
132            ;;
133        minor)
134            NEW_MAJOR=$MAJOR
135            NEW_MINOR=$((MINOR + 1))
136            NEW_PATCH=0
137            ;;
138        patch)
139            NEW_MAJOR=$MAJOR
140            NEW_MINOR=$MINOR
141            NEW_PATCH=$((PATCH + 1))
142            ;;
143    esac
144
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 branch
152    echo "Step 2: Creating release candidate branch..."
153    if [ "$DRY_RUN" = true ]; then
154        echo "  [dry-run] Would create branch: $RC_BRANCH"
155    else
156        git checkout -b "$RC_BRANCH"
157        echo "✓ Created and switched to branch: $RC_BRANCH"
158    fi
159    echo ""
160
161    # Update CMakeLists.txt for release
162    echo "Step 3: Updating version in CMakeLists.txt..."
163    if [ "$DRY_RUN" = true ]; then
164        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    else
168        sed_inplace -e "s/set(LLAMA_VERSION_MAJOR [0-9]*)/set(LLAMA_VERSION_MAJOR $NEW_MAJOR)/" CMakeLists.txt
169        sed_inplace -e "s/set(LLAMA_VERSION_MINOR [0-9]*)/set(LLAMA_VERSION_MINOR $NEW_MINOR)/" CMakeLists.txt
170        sed_inplace -e "s/set(LLAMA_VERSION_PATCH [0-9]*)/set(LLAMA_VERSION_PATCH $NEW_PATCH)/" CMakeLists.txt
171    fi
172    echo ""
173
174    # Commit version bump
175    echo "Step 4: Committing version bump..."
176    if [ "$DRY_RUN" = true ]; then
177        echo "  [dry-run] Would commit: 'llama.cpp : bump version to $NEW_VERSION'"
178    else
179        git add CMakeLists.txt
180        git commit -m "llama.cpp : bump version to $NEW_VERSION"
181    fi
182    echo ""
183
184    echo ""
185    if [ "$DRY_RUN" = true ]; then
186        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    else
190        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    fi
202}
203
204prepare_release