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