1#!/usr/bin/env 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"
 31bump_main_branch_name="set-minor-version-to-${major}.${next_minor}"
 32
 33git fetch origin ${prev_minor_branch_name}:${prev_minor_branch_name}
 34git fetch origin --tags
 35cargo check -q
 36
 37function cleanup {
 38  git checkout -q main
 39}
 40trap cleanup EXIT
 41
 42echo "Checking invariants before taking any actions..."
 43if [[ $(cat crates/zed/RELEASE_CHANNEL) != dev && $(cat crates/zed/RELEASE_CHANNEL) != nightly ]]; then
 44  echo "release channel on main should be dev or nightly"
 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 ${stable_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 main
 79git checkout -q -b ${minor_branch_name}
 80echo -n preview > crates/zed/RELEASE_CHANNEL
 81git commit -q --all --message "${minor_branch_name} preview"
 82git tag ${preview_tag_name}
 83
 84echo "Preparing main for version ${next_minor_branch_name}..."
 85git checkout -q main
 86git clean -q -dff
 87git checkout -q -b ${bump_main_branch_name}
 88cargo set-version --package zed --bump minor
 89cargo check -q
 90
 91git commit -q --all --message "${next_minor_branch_name} dev"
 92
 93git checkout -q main
 94
 95cat <<MESSAGE
 96Prepared new Zed versions locally. You will need to push the branches and open a PR for the change to main.
 97
 98# To push and open a PR to update main:
 99
100    git push -u origin \\
101      ${preview_tag_name} \\
102      ${stable_tag_name} \\
103      ${minor_branch_name} \\
104      ${prev_minor_branch_name} \\
105      ${bump_main_branch_name}
106
107    echo -e "Release Notes:\n\n- N/A" | gh pr create \\
108      --title "Bump Zed to v${major}.${next_minor}" \\
109      --body-file "-" \\
110      --base main \\
111      --head ${bump_main_branch_name} \\
112      --web
113
114# To undo this push:
115
116    git push -f . \\
117      :${preview_tag_name} \\
118      :${stable_tag_name} \\
119      :${minor_branch_name} \\
120      :${bump_main_branch_name} \\
121      ${old_prev_minor_sha}:${prev_minor_branch_name}
122
123MESSAGE