Felipe97/llama-cpp-compiled
01.2k
1#!/bin/bash2# Run all pre-release checks and determine the release version.3#4# Usage: make-release-checks.sh [--dry-run]5# --dry-run: warn on failures instead of aborting6#7# Env (when running in GitHub Actions):8# GH_TOKEN, GITHUB_REPOSITORY, GITHUB_OUTPUT9# RELEASE_BRANCH: when set, HEAD must belong to origin/RELEASE_BRANCH and must10# not be older than 3 days from the branch HEAD (skipped when unset)11set -euo pipefail12 13SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"14REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"15 16DRY_RUN=false17CHECKS_PASSED=true18for arg in "$@"; do19 case "$arg" in20 --dry-run) DRY_RUN=true ;;21 *) echo "Unknown argument: $arg"; exit 1 ;;22 esac23done24 25MAJOR=$(grep "set(LLAMA_VERSION_MAJOR" "$REPO_ROOT/CMakeLists.txt" | sed 's/.*MAJOR \([0-9]*\).*/\1/')26MINOR=$(grep "set(LLAMA_VERSION_MINOR" "$REPO_ROOT/CMakeLists.txt" | sed 's/.*MINOR \([0-9]*\).*/\1/')27PATCH=$(grep "set(LLAMA_VERSION_PATCH" "$REPO_ROOT/CMakeLists.txt" | sed 's/.*PATCH \([0-9]*\).*/\1/')28VERSION="v${MAJOR}.${MINOR}.${PATCH}"29echo "Determined version: ${VERSION}"30if [[ -n "${GITHUB_OUTPUT:-}" ]]; then31 echo "version=${VERSION}" >> "$GITHUB_OUTPUT"32fi33 34SHA=$(git rev-parse HEAD)35 36echo "Checking that commit ${SHA} belongs to the release branch..."37if [[ -z "${RELEASE_BRANCH:-}" ]]; then38 echo "Warning: RELEASE_BRANCH not set - skipping commit check (local run)"39else40 TIP="origin/${RELEASE_BRANCH}"41 COMMIT_ERR=""42 if ! git rev-parse --verify "${TIP}" >/dev/null 2>&1; then43 COMMIT_ERR="branch ${RELEASE_BRANCH} not found on remote"44 elif ! git merge-base --is-ancestor "${SHA}" "${TIP}"; then45 COMMIT_ERR="commit ${SHA} is not part of branch ${RELEASE_BRANCH}"46 else47 COMMIT_TS=$(git show -s --format=%ct "${SHA}")48 TIP_TS=$(git show -s --format=%ct "${TIP}")49 AGE_DAYS=$(( (TIP_TS - COMMIT_TS) / 86400 ))50 if (( TIP_TS - COMMIT_TS > 3 * 86400 )); then51 COMMIT_ERR="commit ${SHA} is ${AGE_DAYS} day(s) older than the HEAD of ${RELEASE_BRANCH} (max: 3)"52 fi53 fi54 if [[ -n "${COMMIT_ERR}" ]]; then55 if [[ "$DRY_RUN" == "true" ]]; then56 echo "Warning: ${COMMIT_ERR} (dry run, continuing)."57 CHECKS_PASSED=false58 else59 echo "Error: ${COMMIT_ERR}"60 exit 161 fi62 else63 echo "Commit ${SHA} is on branch ${RELEASE_BRANCH} and within 3 days of its HEAD - OK"64 fi65fi66 67echo "Checking that tag ${VERSION} does not already exist..."68if git ls-remote --tags origin "${VERSION}" | grep -q "${VERSION}"; then69 echo "Error: tag ${VERSION} already exists on remote"70 exit 171fi72echo "Tag ${VERSION} does not exist on remote - OK"73 74echo "Checking release.yml status for commit ${SHA}..."75if [[ -z "${GITHUB_REPOSITORY:-}" ]]; then76 echo "Warning: GITHUB_REPOSITORY not set - skipping CI check (local run)"77else78 RUNS=$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/release.yml/runs?per_page=100" \79 --jq "[.workflow_runs[] | select(.head_sha == \"${SHA}\" and .conclusion == \"success\")] | length")80 if [[ "$RUNS" -eq 0 ]]; then81 if [[ "$DRY_RUN" == "true" ]]; then82 echo "Warning: no successful release.yml run found for HEAD (${SHA}) (dry run, continuing)."83 CHECKS_PASSED=false84 else85 echo "Error: no successful release.yml run found for HEAD (${SHA})"86 echo "The nightly build must complete successfully before making a release."87 exit 188 fi89 else90 echo "Found successful release.yml run for HEAD."91 fi92fi93 94MAJOR=$(grep "set(GGML_VERSION_MAJOR" "$REPO_ROOT/ggml/CMakeLists.txt" | sed 's/.*MAJOR \([0-9]*\).*/\1/')95MINOR=$(grep "set(GGML_VERSION_MINOR" "$REPO_ROOT/ggml/CMakeLists.txt" | sed 's/.*MINOR \([0-9]*\).*/\1/')96PATCH=$(grep "set(GGML_VERSION_PATCH" "$REPO_ROOT/ggml/CMakeLists.txt" | sed 's/.*PATCH \([0-9]*\).*/\1/')97GGML_VERSION="v${MAJOR}.${MINOR}.${PATCH}"98echo "Local ggml version: ${GGML_VERSION}"99 100if ! git clone --depth 1 --branch "${GGML_VERSION}" https://github.com/ggml-org/ggml.git upstream-ggml 2>/dev/null; then101 echo "Warning: tag ${GGML_VERSION} not found in upstream ggml - skipping comparison"102else103 echo "Comparing local ggml/ src and include with upstream ${GGML_VERSION}..."104 DIFF=$(diff -rq "$REPO_ROOT/ggml/src" upstream-ggml/src 2>&1 || true)105 DIFF+=$(diff -rq "$REPO_ROOT/ggml/include" upstream-ggml/include 2>&1 || true)106 DIFF+=$(diff "$REPO_ROOT/ggml/CMakeLists.txt" upstream-ggml/CMakeLists.txt 2>&1 || true)107 rm -rf upstream-ggml108 if [[ -n "$DIFF" ]]; then109 echo "local ggml/ differs from upstream ${GGML_VERSION}:"110 echo "$DIFF"111 if [[ "$DRY_RUN" == "true" ]]; then112 echo "Warning: would abort release due to ggml mismatch (dry run, continuing)."113 CHECKS_PASSED=false114 else115 echo "Error: ggml must match upstream before making a release."116 exit 1117 fi118 else119 echo "local ggml/ matches upstream ${GGML_VERSION}"120 fi121fi122 123echo "Checking container images for commit ${SHA}..."124NIGHTLY_TAG="$(git tag --points-at "${SHA}" | grep -E '(^|-)b[0-9]+(-[0-9a-f]{7})?$' | head -n 1 || true)"125if [[ -z "${NIGHTLY_TAG}" ]]; then126 echo "Warning: no nightly tag points at ${SHA} - skipping container image check"127elif [[ -z "${GITHUB_REPOSITORY:-}" ]]; then128 echo "Warning: GITHUB_REPOSITORY not set - skipping container image check (local run)"129else130 CONTAINER_REPO="${GITHUB_REPOSITORY,,}" # lower-case owner/repo for ghcr.io131 GHCR_TOKEN="$(curl -fsSL \132 "https://ghcr.io/token?scope=repository:${CONTAINER_REPO}:pull&service=ghcr.io" \133 | grep -oP '"token"\s*:\s*"\K[^"]+')"134 135 VARIANTS=("" "-cuda" "-cuda13" "-vulkan" "-rocm" "-intel" "-musa" "-openvino")136 TYPES=("full" "light" "server")137 CONTAINER_ERR=""138 for type in "${TYPES[@]}"; do139 for variant in "${VARIANTS[@]}"; do140 tag="${type}${variant}-${NIGHTLY_TAG}"141 STATUS="$(curl -s -o /dev/null -w "%{http_code}" \142 -H "Authorization: Bearer ${GHCR_TOKEN}" \143 -H "Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json" \144 "https://ghcr.io/v2/${CONTAINER_REPO}/manifests/${tag}")"145 if [[ "${STATUS}" == "200" ]]; then146 echo " ${tag} - OK"147 else148 echo " ${tag} - MISSING"149 CONTAINER_ERR+=" ${tag}"150 fi151 done152 done153 154 if [[ -n "${CONTAINER_ERR}" ]]; then155 if [[ "$DRY_RUN" == "true" ]]; then156 echo "Warning: missing container images for ${NIGHTLY_TAG}:${CONTAINER_ERR} (dry run, continuing)."157 CHECKS_PASSED=false158 else159 echo "Error: missing container images for ${NIGHTLY_TAG}:${CONTAINER_ERR}"160 echo "The Docker workflow must complete successfully before making a release."161 exit 1162 fi163 else164 echo "All container images found for ${NIGHTLY_TAG} - OK"165 fi166fi167 168echo "Checking API/ABI compatibility..."169set +e170bash "$SCRIPT_DIR/check-release-apiabi.sh"171APIABI_RESULT=$?172set -e173if [[ $APIABI_RESULT -ne 0 ]]; then174 if [[ "$DRY_RUN" == "true" ]]; then175 echo "Warning: API/ABI check found backwards-incompatible changes (dry run, continuing)."176 CHECKS_PASSED=false177 else178 echo "Error: API/ABI check found backwards-incompatible changes."179 exit 1180 fi181else182 echo "API/ABI compatibility check passed - OK"183fi184 185if [[ -n "${GITHUB_OUTPUT:-}" ]]; then186 echo "checks_passed=${CHECKS_PASSED}" >> "$GITHUB_OUTPUT"187fi188 