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 roll the railcars with uncommitted changes"
11 exit 1
12fi
13if [[ $(git rev-parse --abbrev-ref HEAD) != "main" ]]; then
14 echo "Run this command on the main branch"
15 exit 1
16fi
17git pull -q --ff-only origin main
18git fetch --tags
19
20# Parse the current version
21version=$(script/get-crate-version zed)
22major=$(echo $version | cut -d. -f1)
23minor=$(echo $version | cut -d. -f2)
24patch=$(echo $version | cut -d. -f3)
25prev_minor=$(expr $minor - 1)
26next_minor=$(expr $minor + 1)
27
28minor_branch_name="v${major}.${minor}.x"
29prev_minor_branch_name="v${major}.${prev_minor}.x"
30next_minor_branch_name="v${major}.${next_minor}.x"
31preview_tag_name="v{major}.{minor}.{patch}-pre"
32
33function cleanup {
34 git checkout -q main
35}
36trap cleanup EXIT
37
38echo "Checking invariants before taking any actions..."
39if [[ $patch != 0 ]]; then
40 echo "patch version on main should be zero"
41 exit 1
42fi
43if [[ $(cat crates/zed/RELEASE_CHANNEL) != dev ]]; then
44 echo "release channel on main should be dev"
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 "Stable ${prev_minor_branch_name}"
75git tag ${stable_tag_name}
76
77echo "Creating new preview branch ${minor_branch_name}..."
78git checkout -q -b ${minor_branch_name}
79echo -n preview > crates/zed/RELEASE_CHANNEL
80git commit -q --all --message "Preview ${minor_branch_name}"
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 "Dev ${next_minor_branch_name}"
90
91cat <<MESSAGE
92Locally rolled the railcars.
93
94To push this:
95 git push origin \\
96 ${preview_tag_name} \\
97 ${stable_tag_name} \\
98 ${minor_branch_name} \\
99 ${prev_minor_branch_name} \\
100 main
101
102To undo this:
103 git push -f . \\
104 :${preview_tag_name} \\
105 :${stable_tag_name} \\
106 :${minor_branch_name} \\
107 ${old_prev_minor_sha}:${prev_minor_branch_name} \\
108 ${old_main_sha}:main
109MESSAGE