rust/xtask/src/release.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
3.6 KiB
Rust
Raw Normal View History

mod changelog;
2022-03-13 16:20:51 -05:00
use xshell::{cmd, Shell};
2020-10-16 12:46:03 -05:00
2022-03-13 16:20:51 -05:00
use crate::{date_iso, flags, is_release_tag, project_root};
2020-06-08 06:58:54 -05:00
impl flags::Release {
2022-03-13 16:20:51 -05:00
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
2020-06-08 07:00:30 -05:00
if !self.dry_run {
2022-03-13 16:20:51 -05:00
cmd!(sh, "git switch release").run()?;
cmd!(sh, "git fetch upstream --tags --force").run()?;
cmd!(sh, "git reset --hard tags/nightly").run()?;
// The `release` branch sometimes has a couple of cherry-picked
// commits for patch releases. If that's the case, just overwrite
// it. As we are setting `release` branch to an up-to-date `nightly`
// tag, this shouldn't be problematic in general.
//
// Note that, as we tag releases, we don't worry about "losing"
// commits -- they'll be kept alive by the tag. More generally, we
// don't care about historic releases all that much, it's fine even
// to delete old tags.
2022-03-13 16:20:51 -05:00
cmd!(sh, "git push --force").run()?;
2020-06-08 07:00:30 -05:00
}
// Generates bits of manual.adoc.
2022-05-02 03:41:06 -05:00
cmd!(sh, "cargo test -p ide-assists -p ide-diagnostics -p rust-analyzer -- sourcegen_")
.run()?;
2020-06-08 06:58:54 -05:00
2020-06-08 07:00:30 -05:00
let website_root = project_root().join("../rust-analyzer.github.io");
{
2022-03-13 16:20:51 -05:00
let _dir = sh.push_dir(&website_root);
cmd!(sh, "git switch src").run()?;
cmd!(sh, "git pull").run()?;
}
2020-06-08 07:00:30 -05:00
let changelog_dir = website_root.join("./thisweek/_posts");
2020-06-08 06:58:54 -05:00
2022-03-13 16:20:51 -05:00
let today = date_iso(sh)?;
let commit = cmd!(sh, "git rev-parse HEAD").read()?;
let changelog_n = sh
.read_dir(changelog_dir.as_path())?
.into_iter()
.filter_map(|p| p.file_stem().map(|s| s.to_string_lossy().to_string()))
.filter_map(|s| s.splitn(5, '-').last().map(|n| n.replace('-', ".")))
.filter_map(|s| s.parse::<f32>().ok())
.map(|n| 1 + n.floor() as usize)
.max()
.unwrap_or_default();
2020-06-08 06:58:54 -05:00
2021-10-03 07:45:08 -05:00
for adoc in [
"manual.adoc",
"generated_assists.adoc",
"generated_config.adoc",
"generated_diagnostic.adoc",
"generated_features.adoc",
2021-10-03 07:45:08 -05:00
] {
let src = project_root().join("./docs/user/").join(adoc);
let dst = website_root.join(adoc);
2022-03-13 16:20:51 -05:00
let contents = sh.read_file(src)?;
sh.write_file(dst, contents)?;
}
2022-03-13 16:20:51 -05:00
let tags = cmd!(sh, "git tag --list").read()?;
let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap();
2022-03-13 16:20:51 -05:00
let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));
sh.write_file(path, contents)?;
2020-06-08 07:00:30 -05:00
Ok(())
}
2020-06-08 06:58:54 -05:00
}
2020-07-07 11:12:22 -05:00
impl flags::Promote {
2022-03-13 16:20:51 -05:00
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
let _dir = sh.push_dir("../rust-rust-analyzer");
cmd!(sh, "git switch master").run()?;
cmd!(sh, "git fetch upstream").run()?;
cmd!(sh, "git reset --hard upstream/master").run()?;
2020-07-07 11:38:34 -05:00
2022-03-13 16:20:51 -05:00
let date = date_iso(sh)?;
let branch = format!("rust-analyzer-{date}");
cmd!(sh, "git switch -c {branch}").run()?;
cmd!(sh, "git subtree pull -m ':arrow_up: rust-analyzer' -P src/tools/rust-analyzer rust-analyzer release").run()?;
2020-07-07 11:38:34 -05:00
if !self.dry_run {
2022-03-13 16:20:51 -05:00
cmd!(sh, "git push -u origin {branch}").run()?;
cmd!(
sh,
"xdg-open https://github.com/matklad/rust/pull/new/{branch}?body=r%3F%20%40ghost"
)
.run()?;
2020-07-07 11:38:34 -05:00
}
2020-07-07 11:12:22 -05:00
Ok(())
}
}