xtask/
release.rs

1mod changelog;
2
3use xshell::{Shell, cmd};
4
5use crate::{date_iso, flags, is_release_tag, project_root};
6
7impl 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        let website_root = project_root().join("../rust-analyzer.github.io");
26        {
27            let _dir = sh.push_dir(&website_root);
28            cmd!(sh, "git switch src").run()?;
29            cmd!(sh, "git pull").run()?;
30        }
31        let changelog_dir = website_root.join("./thisweek/_posts");
32
33        let today = date_iso(sh)?;
34        let commit = cmd!(sh, "git rev-parse HEAD").read()?;
35        let changelog_n = sh
36            .read_dir(changelog_dir.as_path())?
37            .into_iter()
38            .filter_map(|p| p.file_stem().map(|s| s.to_string_lossy().to_string()))
39            .filter_map(|s| s.splitn(5, '-').last().map(|n| n.replace('-', ".")))
40            .filter_map(|s| s.parse::<f32>().ok())
41            .map(|n| 1 + n.floor() as usize)
42            .max()
43            .unwrap_or_default();
44
45        let tags = cmd!(sh, "git tag --list").read()?;
46        let prev_tag = tags.lines().rfind(|line| is_release_tag(line)).unwrap();
47
48        let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
49        let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));
50        sh.write_file(path, contents)?;
51
52        Ok(())
53    }
54}