aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/release.rs
blob: 7fa0966aa36da494a2004fc85acb14a301c726db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::{
    codegen, is_release_tag,
    not_bash::{date_iso, fs2, pushd, run},
    project_root, Mode, Result,
};

pub struct ReleaseCmd {
    pub dry_run: bool,
}

impl ReleaseCmd {
    pub fn run(self) -> Result<()> {
        if !self.dry_run {
            run!("git switch release")?;
            run!("git fetch upstream --tags --force")?;
            run!("git reset --hard tags/nightly")?;
            run!("git push")?;
        }
        codegen::generate_assists_docs(Mode::Overwrite)?;
        codegen::generate_feature_docs(Mode::Overwrite)?;

        let website_root = project_root().join("../rust-analyzer.github.io");
        let changelog_dir = website_root.join("./thisweek/_posts");

        let today = date_iso()?;
        let commit = run!("git rev-parse HEAD")?;
        let changelog_n = fs2::read_dir(changelog_dir.as_path())?.count();

        let contents = format!(
            "\
= Changelog #{}
:sectanchors:
:page-layout: post

Commit: commit:{}[] +
Release: release:{}[]

== Sponsors

**Become a sponsor:** https://opencollective.com/rust-analyzer/[opencollective.com/rust-analyzer]

== New Features

* pr:[] .

== Fixes

== Internal Improvements
",
            changelog_n, commit, today
        );

        let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n));
        fs2::write(&path, &contents)?;

        for &adoc in ["manual.adoc", "generated_features.adoc", "generated_assists.adoc"].iter() {
            let src = project_root().join("./docs/user/").join(adoc);
            let dst = website_root.join(adoc);
            fs2::copy(src, dst)?;
        }

        let tags = run!("git tag --list"; echo = false)?;
        let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap();

        let git_log = run!("git log {}..HEAD --merges --reverse", prev_tag; echo = false)?;
        let git_log_dst = website_root.join("git.log");
        fs2::write(git_log_dst, &git_log)?;

        Ok(())
    }
}

pub struct PromoteCmd {
    pub dry_run: bool,
}

impl PromoteCmd {
    pub fn run(self) -> Result<()> {
        let _dir = pushd("../rust-rust-analyzer");
        run!("git switch master")?;
        run!("git fetch upstream")?;
        run!("git reset --hard upstream/master")?;
        run!("git submodule update --recursive")?;

        let branch = format!("rust-analyzer-{}", date_iso()?);
        run!("git switch -c {}", branch)?;
        {
            let _dir = pushd("src/tools/rust-analyzer");
            run!("git fetch origin")?;
            run!("git reset --hard origin/release")?;
        }
        run!("git add src/tools/rust-analyzer")?;
        run!("git commit -m':arrow_up: rust-analyzer'")?;
        if !self.dry_run {
            run!("git push")?;
            run!(
                "xdg-open https://github.com/matklad/rust/pull/new/{}?body=r%3F%20%40ghost",
                branch
            )?;
        }
        Ok(())
    }
}