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}
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
90message="${next_minor_branch_name} dev
91
92Release Notes:
93
94- N/A"
95git commit -q --all --message "$message"
96
97git checkout -q main
98
99cat <<MESSAGE
100Prepared new Zed versions locally. You will need to push the branches and open a PR for the change to main.
101
102# To push and open a PR to update main:
103
104 git push origin \\
105 ${preview_tag_name} \\
106 ${stable_tag_name} \\
107 ${minor_branch_name} \\
108 ${prev_minor_branch_name} \\
109 ${bump_main_branch_name}
110
111 gh pr create --base main --head ${bump_main_branch_name}
112
113# To undo this push:
114
115 git push -f . \\
116 :${preview_tag_name} \\
117 :${stable_tag_name} \\
118 :${minor_branch_name} \\
119 :${bump_main_branch_name} \\
120 ${old_prev_minor_sha}:${prev_minor_branch_name}
121
122MESSAGE