bump-zed-minor-versions

  1#!/bin/bash
  2
  3set -eu
  4
  5# Ensure cargo-edit is installed
  6which cargo-set-version > /dev/null || cargo install cargo-edit
  7
  8# Ensure we're in a clean state on an up-to-date `main` branch.
  9if [[ -n $(git status --short --untracked-files=no) ]]; then
 10  echo "can't bump versions with uncommitted changes"
 11  exit 1
 12fi
 13if [[ $(git rev-parse --abbrev-ref HEAD) != "main" ]]; then
 14  echo "this command must be run on main"
 15  exit 1
 16fi
 17git pull -q --ff-only origin main
 18git fetch --tags
 19cargo check -q
 20
 21# Parse the current version
 22version=$(script/get-crate-version zed)
 23major=$(echo $version | cut -d. -f1)
 24minor=$(echo $version | cut -d. -f2)
 25patch=$(echo $version | cut -d. -f3)
 26prev_minor=$(expr $minor - 1)
 27next_minor=$(expr $minor + 1)
 28
 29minor_branch_name="v${major}.${minor}.x"
 30prev_minor_branch_name="v${major}.${prev_minor}.x"
 31next_minor_branch_name="v${major}.${next_minor}.x"
 32preview_tag_name="v${major}.${minor}.${patch}-pre"
 33
 34function cleanup {
 35  git checkout -q main
 36}
 37trap cleanup EXIT
 38
 39echo "Checking invariants before taking any actions..."
 40if [[ $patch != 0 ]]; then
 41  echo "patch version on main should be zero"
 42  exit 1
 43fi
 44if [[ $(cat crates/zed/RELEASE_CHANNEL) != dev ]]; then
 45  echo "release channel on main should be dev"
 46  exit 1
 47fi
 48if git show-ref --quiet refs/tags/${preview_tag_name}; then
 49  echo "tag ${preview_tag_name} already exists"
 50  exit 1
 51fi
 52if git show-ref --quiet refs/heads/${minor_branch_name}; then
 53  echo "branch ${minor_branch_name} already exists"
 54  exit 1
 55fi
 56if ! git show-ref --quiet refs/heads/${prev_minor_branch_name}; then
 57  echo "previous branch ${minor_branch_name} doesn't exist"
 58  exit 1
 59fi
 60if [[ $(git show ${prev_minor_branch_name}:crates/zed/RELEASE_CHANNEL) != preview ]]; then
 61  echo "release channel on branch ${prev_minor_branch_name} should be preview"
 62  exit 1
 63fi
 64
 65echo "Promoting existing branch ${prev_minor_branch_name} to stable..."
 66git checkout -q ${prev_minor_branch_name}
 67git clean -q -dff
 68stable_tag_name="v$(script/get-crate-version zed)"
 69if git show-ref --quiet refs/tags/${stable_tag_name}; then
 70  echo "tag ${preview_tag_name} already exists"
 71  exit 1
 72fi
 73old_prev_minor_sha=$(git rev-parse HEAD)
 74echo -n stable > crates/zed/RELEASE_CHANNEL
 75git commit -q --all --message "${prev_minor_branch_name} stable"
 76git tag ${stable_tag_name}
 77
 78echo "Creating new preview branch ${minor_branch_name}..."
 79git checkout -q main
 80git checkout -q -b ${minor_branch_name}
 81echo -n preview > crates/zed/RELEASE_CHANNEL
 82git commit -q --all --message "${minor_branch_name} preview"
 83git tag ${preview_tag_name}
 84
 85echo "Preparing main for version ${next_minor_branch_name}..."
 86git checkout -q main
 87git clean -q -dff
 88old_main_sha=$(git rev-parse HEAD)
 89cargo set-version --package zed --bump minor
 90cargo check -q
 91git commit -q --all --message "${next_minor_branch_name} dev"
 92
 93cat <<MESSAGE
 94Prepared new Zed versions locally.
 95
 96To push this:
 97
 98    git push origin \\
 99      ${preview_tag_name} \\
100      ${stable_tag_name} \\
101      ${minor_branch_name} \\
102      ${prev_minor_branch_name} \\
103      main
104
105To undo this:
106
107    git reset --hard ${old_main_sha} && git push -f . \\
108      :${preview_tag_name} \\
109      :${stable_tag_name} \\
110      :${minor_branch_name} \\
111      ${old_prev_minor_sha}:${prev_minor_branch_name}
112
113MESSAGE