]> git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/xtask/src/release.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / src / tools / rust-analyzer / xtask / src / release.rs
1 mod changelog;
2
3 use xshell::{cmd, Shell};
4
5 use crate::{date_iso, flags, is_release_tag, project_root};
6
7 impl flags::Release {
8 pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
9 if !self.dry_run {
10 cmd!(sh, "git switch release").run()?;
11 cmd!(sh, "git fetch upstream --tags --force").run()?;
12 cmd!(sh, "git reset --hard tags/nightly").run()?;
13 // The `release` branch sometimes has a couple of cherry-picked
14 // commits for patch releases. If that's the case, just overwrite
15 // it. As we are setting `release` branch to an up-to-date `nightly`
16 // tag, this shouldn't be problematic in general.
17 //
18 // Note that, as we tag releases, we don't worry about "losing"
19 // commits -- they'll be kept alive by the tag. More generally, we
20 // don't care about historic releases all that much, it's fine even
21 // to delete old tags.
22 cmd!(sh, "git push --force").run()?;
23 }
24
25 // Generates bits of manual.adoc.
26 cmd!(sh, "cargo test -p ide-assists -p ide-diagnostics -p rust-analyzer -- sourcegen_")
27 .run()?;
28
29 let website_root = project_root().join("../rust-analyzer.github.io");
30 {
31 let _dir = sh.push_dir(&website_root);
32 cmd!(sh, "git switch src").run()?;
33 cmd!(sh, "git pull").run()?;
34 }
35 let changelog_dir = website_root.join("./thisweek/_posts");
36
37 let today = date_iso(sh)?;
38 let commit = cmd!(sh, "git rev-parse HEAD").read()?;
39 let changelog_n = sh
40 .read_dir(changelog_dir.as_path())?
41 .into_iter()
42 .filter_map(|p| p.file_stem().map(|s| s.to_string_lossy().to_string()))
43 .filter_map(|s| s.splitn(5, '-').last().map(|n| n.replace('-', ".")))
44 .filter_map(|s| s.parse::<f32>().ok())
45 .map(|n| 1 + n.floor() as usize)
46 .max()
47 .unwrap_or_default();
48
49 for adoc in [
50 "manual.adoc",
51 "generated_assists.adoc",
52 "generated_config.adoc",
53 "generated_diagnostic.adoc",
54 "generated_features.adoc",
55 ] {
56 let src = project_root().join("./docs/user/").join(adoc);
57 let dst = website_root.join(adoc);
58
59 let contents = sh.read_file(src)?;
60 sh.write_file(dst, contents)?;
61 }
62
63 let tags = cmd!(sh, "git tag --list").read()?;
64 let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap();
65
66 let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
67 let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));
68 sh.write_file(path, contents)?;
69
70 Ok(())
71 }
72 }
73
74 impl flags::Promote {
75 pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
76 let _dir = sh.push_dir("../rust-rust-analyzer");
77 cmd!(sh, "git switch master").run()?;
78 cmd!(sh, "git fetch upstream").run()?;
79 cmd!(sh, "git reset --hard upstream/master").run()?;
80
81 let date = date_iso(sh)?;
82 let branch = format!("rust-analyzer-{date}");
83 cmd!(sh, "git switch -c {branch}").run()?;
84 cmd!(sh, "git subtree pull -m ':arrow_up: rust-analyzer' -P src/tools/rust-analyzer rust-analyzer release").run()?;
85
86 if !self.dry_run {
87 cmd!(sh, "git push -u origin {branch}").run()?;
88 cmd!(
89 sh,
90 "xdg-open https://github.com/matklad/rust/pull/new/{branch}?body=r%3F%20%40ghost"
91 )
92 .run()?;
93 }
94 Ok(())
95 }
96 }