fred/script/bump-zed-minor-versions
Julia Ryan 4a7c84f490
Fix nix build (#26270)
This PR includes lots of small fixes to get our `build.nix` and
`shell.nix` back to a working state.

I've tested this by running `cargo run` (inside the devshell) and `nix
run` on x86 nixos and arm64 darwin machines. I'd appreciate it if others
could test building inside the devshell to double-check that it's not
just working because I happen to have some system-level packages
installed, as well as seeing if it works on other platforms (non-nixos
linux, arm linux, x86 darwin).

I couldn't get the full test suite (`cargo nextest run --workspace`)
passing in the devshell on darwin, but they _are_ all passing on nixos.
nixpkgs [disables some of our
tests](92d11f06d5/pkgs/by-name/ze/zed-editor/package.nix (L226-L234))
that apparently fail or are flakey on hydra, but they don't know why.
I'm going to punt on debugging those for now, especially given that they
seem to be working for me. I'm also unsure of whether we actually want
the nix checkPhase to run the full test suite (it's currently not
passing `--workspace`) given that we have separate CI that should
enforce that those pass on all PRs.

Here's an overview of the changes made:
- Fix our `generate-licenses` script
- Relaxes the `cargo-about` version requirement slightly so it doesn't
try to install an older binary when the nixpkgs one is newer than our
requirement
- Add a workaround for [this cargo-about
issue](https://github.com/zed-industries/zed/issues/19971) obviating the
need for the patching done in the nixpkgs package
- Set the new `--frozen` flag to avoid network access/mutating the
lockfile
- Use dynamic webrtc lib from nixpkgs, and fixes up the build script in
webrtc-sys that hardcodes it to be statically linked.
- Use `inputsFrom` in `shell.nix` and avoid duplicating everything from
`build.nix`
- Add a temporary workaround for an [upstream crane
bug](https://github.com/ipetkov/crane/issues/808).
- Fix shebangs in our `script` dir to not hard-code `/bin/bash`

There are still a bunch of issues that aren't resolved here, I'll make a
tracking issue for those and try to land this first just to get back to
an unbroken state. Eventually among other things I'd like to use a
`libgit2` from `staticPkgs` and musl cross compilation to build the
remote server under nix, and then add that as a separate flake output
and include it in the shell's `inputsFrom` list.

Thanks @niklaskorz, @GaetanLepage, @bbigras and all the other nixpkgs
maintainers that have kept the `zed-editor` package working and up to
date! I seriously considered just making our flake `overrideAttrs` the
package in nixpkgs given how well maintained it is.

Thanks @WeetHet for your volunteer maintinance of this flake. I
referenced #24953 while working on these fixes, and I'd love to
collaborate on adding some of those pieces like treefmt and a github
action. If you're interested I'd really appreciate some help debugging
why crane's `buildDepsOnly` isn't working for us. I'm assuming it'd make
our `nix build` times go way down from the improved dep caching if we
could get it working.

Thanks @rrbutani for all the help on this PR 💙.

Release Notes:

- N/A

---------

Co-authored-by: Rahul Butani <rrbutani@users.noreply.github.com>
Co-authored-by: Rahul Butani <rr.butani@gmail.com>
2025-03-10 01:06:11 -07:00

124 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu
# Ensure cargo-edit is installed
which cargo-set-version > /dev/null || cargo install cargo-edit
# Ensure we're in a clean state on an up-to-date `main` branch.
if [[ -n $(git status --short --untracked-files=no) ]]; then
echo "can't bump versions with uncommitted changes"
exit 1
fi
if [[ $(git rev-parse --abbrev-ref HEAD) != "main" ]]; then
echo "this command must be run on main"
exit 1
fi
git pull -q --ff-only origin main
# Parse the current version
version=$(script/get-crate-version zed)
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
patch=$(echo $version | cut -d. -f3)
prev_minor=$(expr $minor - 1)
next_minor=$(expr $minor + 1)
minor_branch_name="v${major}.${minor}.x"
prev_minor_branch_name="v${major}.${prev_minor}.x"
next_minor_branch_name="v${major}.${next_minor}.x"
preview_tag_name="v${major}.${minor}.${patch}-pre"
bump_main_branch_name="set-minor-version-to-${major}.${next_minor}"
git fetch origin ${prev_minor_branch_name}:${prev_minor_branch_name}
git fetch origin --tags
cargo check -q
function cleanup {
git checkout -q main
}
trap cleanup EXIT
echo "Checking invariants before taking any actions..."
if [[ $(cat crates/zed/RELEASE_CHANNEL) != dev && $(cat crates/zed/RELEASE_CHANNEL) != nightly ]]; then
echo "release channel on main should be dev or nightly"
exit 1
fi
if git show-ref --quiet refs/tags/${preview_tag_name}; then
echo "tag ${preview_tag_name} already exists"
exit 1
fi
if git show-ref --quiet refs/heads/${minor_branch_name}; then
echo "branch ${minor_branch_name} already exists"
exit 1
fi
if ! git show-ref --quiet refs/heads/${prev_minor_branch_name}; then
echo "previous branch ${minor_branch_name} doesn't exist"
exit 1
fi
if [[ $(git show ${prev_minor_branch_name}:crates/zed/RELEASE_CHANNEL) != preview ]]; then
echo "release channel on branch ${prev_minor_branch_name} should be preview"
exit 1
fi
echo "Promoting existing branch ${prev_minor_branch_name} to stable..."
git checkout -q ${prev_minor_branch_name}
git clean -q -dff
stable_tag_name="v$(script/get-crate-version zed)"
if git show-ref --quiet refs/tags/${stable_tag_name}; then
echo "tag ${stable_tag_name} already exists"
exit 1
fi
old_prev_minor_sha=$(git rev-parse HEAD)
echo -n stable > crates/zed/RELEASE_CHANNEL
git commit -q --all --message "${prev_minor_branch_name} stable"
git tag ${stable_tag_name}
echo "Creating new preview branch ${minor_branch_name}..."
git checkout -q main
git checkout -q -b ${minor_branch_name}
echo -n preview > crates/zed/RELEASE_CHANNEL
git commit -q --all --message "${minor_branch_name} preview"
git tag ${preview_tag_name}
echo "Preparing main for version ${next_minor_branch_name}..."
git checkout -q main
git clean -q -dff
git checkout -q -b ${bump_main_branch_name}
cargo set-version --package zed --bump minor
cargo check -q
git commit -q --all --message "${next_minor_branch_name} dev"
git checkout -q main
cat <<MESSAGE
Prepared new Zed versions locally. You will need to push the branches and open a PR for the change to main.
# To push and open a PR to update main:
git push origin \\
${preview_tag_name} \\
${stable_tag_name} \\
${minor_branch_name} \\
${prev_minor_branch_name} \\
${bump_main_branch_name}
echo -e "Release Notes:\n\n-N/A" | gh pr create \\
--title "Bump Zed to v${major}.${next_minor}" \\
--body-file "-" \\
--base main \\
--head ${bump_main_branch_name} \\
--web
# To undo this push:
git push -f . \\
:${preview_tag_name} \\
:${stable_tag_name} \\
:${minor_branch_name} \\
:${bump_main_branch_name} \\
${old_prev_minor_sha}:${prev_minor_branch_name}
MESSAGE