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 [[ $(cat crates/zed/RELEASE_CHANNEL) != dev && $(cat crates/zed/RELEASE_CHANNEL) != nightly ]]; then
43 echo "release channel on main should be dev or nightly"
44 exit 1
45fi
46if git show-ref --quiet refs/tags/${preview_tag_name}; then
47 echo "tag ${preview_tag_name} already exists"
48 exit 1
49fi
50if git show-ref --quiet refs/heads/${minor_branch_name}; then
51 echo "branch ${minor_branch_name} already exists"
52 exit 1
53fi
54if ! git show-ref --quiet refs/heads/${prev_minor_branch_name}; then
55 echo "previous branch ${minor_branch_name} doesn't exist"
56 exit 1
57fi
58if [[ $(git show ${prev_minor_branch_name}:crates/zed/RELEASE_CHANNEL) != preview ]]; then
59 echo "release channel on branch ${prev_minor_branch_name} should be preview"
60 exit 1
61fi
62
63echo "Promoting existing branch ${prev_minor_branch_name} to stable..."
64git checkout -q ${prev_minor_branch_name}
65git clean -q -dff
66stable_tag_name="v$(script/get-crate-version zed)"
67if git show-ref --quiet refs/tags/${stable_tag_name}; then
68 echo "tag ${preview_tag_name} already exists"
69 exit 1
70fi
71old_prev_minor_sha=$(git rev-parse HEAD)
72echo -n stable > crates/zed/RELEASE_CHANNEL
73git commit -q --all --message "${prev_minor_branch_name} stable"
74git tag ${stable_tag_name}
75
76echo "Creating new preview branch ${minor_branch_name}..."
77git checkout -q main
78git checkout -q -b ${minor_branch_name}
79echo -n preview > crates/zed/RELEASE_CHANNEL
80git commit -q --all --message "${minor_branch_name} preview"
81git tag ${preview_tag_name}
82
83echo "Preparing main for version ${next_minor_branch_name}..."
84git checkout -q main
85git clean -q -dff
86old_main_sha=$(git rev-parse HEAD)
87cargo set-version --package zed --bump minor
88cargo check -q
89git commit -q --all --message "${next_minor_branch_name} dev"
90
91cat <<MESSAGE
92Prepared new Zed versions locally.
93
94To push this:
95
96 git push origin \\
97 ${preview_tag_name} \\
98 ${stable_tag_name} \\
99 ${minor_branch_name} \\
100 ${prev_minor_branch_name} \\
101 main
102
103To undo this:
104
105 git reset --hard ${old_main_sha} && git push -f . \\
106 :${preview_tag_name} \\
107 :${stable_tag_name} \\
108 :${minor_branch_name} \\
109 ${old_prev_minor_sha}:${prev_minor_branch_name}
110
111MESSAGE