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