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.
9# if [[ -n $(git status --short --untracked-files=no) ]]; then
10# echo "can't bump versions with uncommitted changes"
11# exit 1
12# fi
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
41# echo "Checking invariants before taking any actions..."
42# if [[ $patch != 0 ]]; then
43# echo "patch version on main should be zero"
44# exit 1
45# fi
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
62if [[ $(git show ${prev_minor_branch_name}:crates/zed/RELEASE_CHANNEL) != preview ]]; then
63 echo "release channel on branch ${prev_minor_branch_name} should be preview"
64 exit 1
65fi
66
67echo "Promoting existing branch ${prev_minor_branch_name} to stable..."
68git checkout -q ${prev_minor_branch_name}
69git clean -q -dff
70stable_tag_name="v$(script/get-crate-version zed)"
71if git show-ref --quiet refs/tags/${stable_tag_name}; then
72 echo "tag ${preview_tag_name} already exists"
73 exit 1
74fi
75old_prev_minor_sha=$(git rev-parse HEAD)
76echo -n stable > crates/zed/RELEASE_CHANNEL
77git commit -q --all --message "${prev_minor_branch_name} stable"
78git tag ${stable_tag_name}
79
80echo "Creating new preview branch ${minor_branch_name}..."
81git checkout -q main
82git checkout -q -b ${minor_branch_name}
83echo -n preview > crates/zed/RELEASE_CHANNEL
84git commit -q --all --message "${minor_branch_name} preview"
85git tag ${preview_tag_name}
86
87echo "Preparing main for version ${next_minor_branch_name}..."
88git checkout -q main
89git clean -q -dff
90old_main_sha=$(git rev-parse HEAD)
91cargo set-version --package zed --bump minor
92cargo check -q
93git commit -q --all --message "${next_minor_branch_name} dev"
94
95cat <<MESSAGE
96Prepared new Zed versions locally.
97
98To push this:
99
100 git push origin \\
101 ${preview_tag_name} \\
102 ${stable_tag_name} \\
103 ${minor_branch_name} \\
104 ${prev_minor_branch_name} \\
105 main
106
107To undo this:
108
109 git reset --hard ${old_main_sha} && git push -f . \\
110 :${preview_tag_name} \\
111 :${stable_tag_name} \\
112 :${minor_branch_name} \\
113 ${old_prev_minor_sha}:${prev_minor_branch_name}
114
115MESSAGE