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"
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 ${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 main
79git checkout -q -b ${minor_branch_name}
80git branch --set-upstream-to=origin/${minor_branch_name} ${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
88git checkout -q -b ${bump_main_branch_name}
89cargo set-version --package zed --bump minor
90cargo check -q
91
92git commit -q --all --message "${next_minor_branch_name} dev"
93
94git checkout -q main
95
96cat <<MESSAGE
97Prepared new Zed versions locally. You will need to push the branches and open a PR for the change to main.
98
99# To push and open a PR to update main:
100
101 git push origin \\
102 ${preview_tag_name} \\
103 ${stable_tag_name} \\
104 ${minor_branch_name} \\
105 ${prev_minor_branch_name} \\
106 ${bump_main_branch_name}
107
108 echo -e "Release Notes:\n\n-N/A" | gh pr create \\
109 --title "Bump Zed to v${major}.${next_minor}" \\
110 --body-file "-" \\
111 --base main \\
112 --head ${bump_main_branch_name} \\
113 --web
114
115# To undo this push:
116
117 git push -f . \\
118 :${preview_tag_name} \\
119 :${stable_tag_name} \\
120 :${minor_branch_name} \\
121 :${bump_main_branch_name} \\
122 ${old_prev_minor_sha}:${prev_minor_branch_name}
123
124MESSAGE