Skip to content

Commit 727dcf5

Browse files
authored
Merge pull request #3081 from matklad/with-output
xtask release
2 parents 46a4748 + 57147d7 commit 727dcf5

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

xtask/src/cmd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
3737
pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> {
3838
let output = do_run(cmdline, dir, &mut |_| {})?;
3939
let stdout = String::from_utf8(output.stdout)?;
40+
let stdout = stdout.trim().to_string();
4041
Ok(stdout)
4142
}
4243

xtask/src/lib.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use std::{
1515
process::{Command, Stdio},
1616
};
1717

18-
use crate::{cmd::run, codegen::Mode};
18+
use crate::{
19+
cmd::{run, run_with_output},
20+
codegen::Mode,
21+
};
1922

2023
pub use anyhow::Result;
2124

@@ -156,3 +159,41 @@ fn rm_rf(path: &Path) -> Result<()> {
156159
if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
157160
.with_context(|| format!("failed to remove {:?}", path))
158161
}
162+
163+
pub fn run_release() -> Result<()> {
164+
run("git switch release", ".")?;
165+
run("git fetch upstream", ".")?;
166+
run("git reset --hard upstream/master", ".")?;
167+
run("git push", ".")?;
168+
169+
let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts");
170+
171+
let today = run_with_output("date --iso", ".")?;
172+
let commit = run_with_output("git rev-parse HEAD", ".")?;
173+
let changelog_n = fs::read_dir(changelog_dir.as_path())?.count();
174+
175+
let contents = format!(
176+
"\
177+
= Changelog #{}
178+
:sectanchors:
179+
:page-layout: post
180+
181+
Commit: commit:{}[] +
182+
Release: release:{}[]
183+
184+
== New Features
185+
186+
* pr:[] .
187+
188+
== Fixes
189+
190+
== Internal Improvements
191+
",
192+
changelog_n, commit, today
193+
);
194+
195+
let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n));
196+
fs::write(&path, &contents)?;
197+
198+
Ok(())
199+
}

xtask/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use pico_args::Arguments;
1414
use xtask::{
1515
codegen::{self, Mode},
1616
install::{ClientOpt, InstallCmd, ServerOpt},
17-
pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result,
17+
pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result,
1818
};
1919

2020
fn main() -> Result<()> {
@@ -92,6 +92,10 @@ FLAGS:
9292
args.finish()?;
9393
run_pre_cache()
9494
}
95+
"release" => {
96+
args.finish()?;
97+
run_release()
98+
}
9599
_ => {
96100
eprintln!(
97101
"\

0 commit comments

Comments
 (0)