From 57147d7471584e23135dff1e629a44dfd7657276 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 10 Feb 2020 15:32:03 +0100 Subject: xtask release --- xtask/src/cmd.rs | 1 + xtask/src/lib.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- xtask/src/main.rs | 6 +++++- 3 files changed, 48 insertions(+), 2 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/cmd.rs b/xtask/src/cmd.rs index 8e08a929b..37497fb74 100644 --- a/xtask/src/cmd.rs +++ b/xtask/src/cmd.rs @@ -37,6 +37,7 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> { pub fn run_with_output(cmdline: &str, dir: &str) -> Result { let output = do_run(cmdline, dir, &mut |_| {})?; let stdout = String::from_utf8(output.stdout)?; + let stdout = stdout.trim().to_string(); Ok(stdout) } diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 8fdf43e4a..1bb1882b0 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -15,7 +15,10 @@ use std::{ process::{Command, Stdio}, }; -use crate::{cmd::run, codegen::Mode}; +use crate::{ + cmd::{run, run_with_output}, + codegen::Mode, +}; pub use anyhow::Result; @@ -156,3 +159,41 @@ fn rm_rf(path: &Path) -> Result<()> { if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } .with_context(|| format!("failed to remove {:?}", path)) } + +pub fn run_release() -> Result<()> { + run("git switch release", ".")?; + run("git fetch upstream", ".")?; + run("git reset --hard upstream/master", ".")?; + run("git push", ".")?; + + let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts"); + + let today = run_with_output("date --iso", ".")?; + let commit = run_with_output("git rev-parse HEAD", ".")?; + let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); + + let contents = format!( + "\ += Changelog #{} +:sectanchors: +:page-layout: post + +Commit: commit:{}[] + +Release: release:{}[] + +== New Features + +* pr:[] . + +== Fixes + +== Internal Improvements +", + changelog_n, commit, today + ); + + let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); + fs::write(&path, &contents)?; + + Ok(()) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c347de9ab..7ca727bde 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -14,7 +14,7 @@ use pico_args::Arguments; use xtask::{ codegen::{self, Mode}, install::{ClientOpt, InstallCmd, ServerOpt}, - pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result, + pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result, }; fn main() -> Result<()> { @@ -92,6 +92,10 @@ FLAGS: args.finish()?; run_pre_cache() } + "release" => { + args.finish()?; + run_release() + } _ => { eprintln!( "\ -- cgit v1.2.3