Skip to content

Commit

Permalink
[beta] Automaticaly calculate beta prerelease numbers
Browse files Browse the repository at this point in the history
This commit automatically calculates the beta prerelease number meaning we'll no
longer need to manually change the beta version. Instead beta will automatically
deploy any time a backport is merged, ensuring that backports are released for
testing ASAP. More details about this can be found on the internal [forums]

The only bit of trickiness here was that on CI we do shallow clones by default
but the git history probing here requires some more information. Do cope with
that this commit chooses the strategy of converting the repository to a full
clone via the `--unshallow` flag to `git`. That way this should work for local
developers as well as CI changes.

Note that this commit is coming first to the beta branch to test it, and if
successful we can go back and land it on master.

[forums]: https://internals.rust-lang.org/t/tweaking-how-betas-are-produced/6526
  • Loading branch information
alexcrichton committed Jan 14, 2018
1 parent bb9be9e commit 9426dda
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
5 changes: 0 additions & 5 deletions src/bootstrap/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ use config::Config;
// The version number
pub const CFG_RELEASE_NUM: &str = "1.24.0";

// An optional number to put after the label, e.g. '.2' -> '-beta.2'
// Be sure to make this starts with a dot to conform to semver pre-release
// versions (section 9)
pub const CFG_PRERELEASE_VERSION: &str = ".3";

pub struct GitInfo {
inner: Option<Info>,
}
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,6 @@ fn add_env(build: &Build, cmd: &mut Command, target: Interned<String>) {
cmd.env("CFG_RELEASE_INFO", build.rust_version())
.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM)
.env("CFG_RELEASE", build.rust_release())
.env("CFG_PRERELEASE_VERSION", channel::CFG_PRERELEASE_VERSION)
.env("CFG_VER_MAJOR", parts.next().unwrap())
.env("CFG_VER_MINOR", parts.next().unwrap())
.env("CFG_VER_PATCH", parts.next().unwrap())
Expand Down
49 changes: 47 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern crate toml;
#[cfg(unix)]
extern crate libc;

use std::cell::RefCell;
use std::cell::{RefCell, Cell};
use std::collections::{HashSet, HashMap};
use std::env;
use std::fs::{self, File};
Expand Down Expand Up @@ -250,6 +250,7 @@ pub struct Build {
is_sudo: bool,
ci_env: CiEnv,
delayed_failures: RefCell<Vec<String>>,
prerelease_version: Cell<Option<u32>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -335,6 +336,7 @@ impl Build {
is_sudo,
ci_env: CiEnv::current(),
delayed_failures: RefCell::new(Vec::new()),
prerelease_version: Cell::new(None),
}
}

Expand Down Expand Up @@ -769,12 +771,55 @@ impl Build {
fn release(&self, num: &str) -> String {
match &self.config.channel[..] {
"stable" => num.to_string(),
"beta" => format!("{}-beta{}", num, channel::CFG_PRERELEASE_VERSION),
"beta" => format!("{}-beta.{}", num, self.beta_prerelease_version()),
"nightly" => format!("{}-nightly", num),
_ => format!("{}-dev", num),
}
}

fn beta_prerelease_version(&self) -> u32 {
if let Some(s) = self.prerelease_version.get() {
return s
}

let beta = output(
Command::new("git")
.arg("ls-remote")
.arg("origin")
.arg("beta")
);
let beta = beta.trim().split_whitespace().next().unwrap();
let master = output(
Command::new("git")
.arg("ls-remote")
.arg("origin")
.arg("master")
);
let master = master.trim().split_whitespace().next().unwrap();

// Figure out where the current beta branch started.
let base = output(
Command::new("git")
.arg("merge-base")
.arg(beta)
.arg(master),
);
let base = base.trim();

// Next figure out how many merge commits happened since we branched off
// beta. That's our beta number!
let count = output(
Command::new("git")
.arg("rev-list")
.arg("--count")
.arg("--merges")
.arg(format!("{}...HEAD", base)),
);
let n = count.trim().parse().unwrap();
self.prerelease_version.set(Some(n));
return n
}

/// Returns the value of `release` above for Rust itself.
fn rust_release(&self) -> String {
self.release(channel::CFG_RELEASE_NUM)
Expand Down
6 changes: 6 additions & 0 deletions src/ci/init_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ fi
rm -rf "$CACHE_DIR"
mkdir "$CACHE_DIR"

# On the beta channel we'll be automatically calculating the prerelease version
# via the git history, so unshallow our shallow clone from CI.
if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then
git fetch origin --unshallow beta master
fi

travis_fold start update_cache
travis_time_start

Expand Down

0 comments on commit 9426dda

Please sign in to comment.