Skip to content

Commit e3c5fbf

Browse files
Automate Cargo tagging
This doesn't handle the crates.io releases, which we may want to do in GHA CI in response to the tagging event - that would allow us to reuse that infrastructure across rust-lang/rust rather than having something fully custom for promote release.
1 parent a226029 commit e3c5fbf

File tree

2 files changed

+61
-13
lines changed

2 files changed

+61
-13
lines changed

src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ pub(crate) struct Config {
151151
/// Should be a org/repo code, e.g., rust-lang/rust.
152152
pub(crate) rustc_tag_repository: Option<String>,
153153

154+
/// Where to tag stable cargo releases.
155+
///
156+
/// This repository should have content write permissions with the github
157+
/// app configuration.
158+
///
159+
/// Should be a org/repo code, e.g., rust-lang/cargo.
160+
pub(crate) cargo_tag_repository: Option<String>,
161+
154162
/// Where to publish new blog PRs.
155163
///
156164
/// We create a new PR announcing releases in this repository; currently we
@@ -219,6 +227,7 @@ impl Config {
219227
recompress_xz: bool_env("RECOMPRESS_XZ")?,
220228
recompress_gz: bool_env("RECOMPRESS_GZ")?,
221229
rustc_tag_repository: maybe_env("RUSTC_TAG_REPOSITORY")?,
230+
cargo_tag_repository: maybe_env("CARGO_TAG_REPOSITORY")?,
222231
blog_repository: maybe_env("BLOG_REPOSITORY")?,
223232
blog_pr: maybe_env("BLOG_MERGE_PR")?,
224233
scheduled_release_date: maybe_env("BLOG_SCHEDULED_RELEASE_DATE")?,

src/main.rs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct Context {
3838
config: Config,
3939
date: String,
4040
current_version: Option<String>,
41+
current_cargo_version: Option<String>,
4142
}
4243

4344
// Called as:
@@ -66,6 +67,7 @@ impl Context {
6667
date,
6768
handle: Easy::new(),
6869
current_version: None,
70+
current_cargo_version: None,
6971
})
7072
}
7173

@@ -262,18 +264,12 @@ impl Context {
262264
Ok(())
263265
}
264266

265-
fn current_version_same(&mut self, prev: &str) -> Result<bool, Error> {
266-
// nightly's always changing
267-
if self.config.channel == Channel::Nightly {
268-
return Ok(false);
269-
}
270-
let prev_version = prev.split(' ').next().unwrap();
271-
267+
fn load_version(&mut self, mut filter: impl FnMut(&str) -> bool) -> Result<String, Error> {
272268
let mut current = None;
273269
for e in self.dl_dir().read_dir()? {
274270
let e = e?;
275271
let filename = e.file_name().into_string().unwrap();
276-
if !filename.starts_with("rustc-") || !filename.ends_with(".tar.xz") {
272+
if !filter(&filename) && filename.ends_with(".tar.xz") {
277273
continue;
278274
}
279275
println!("looking inside {} for a version", filename);
@@ -301,13 +297,26 @@ impl Context {
301297
break;
302298
}
303299
}
304-
let current = current.ok_or_else(|| anyhow::anyhow!("no archives with a version"))?;
300+
current.ok_or_else(|| anyhow::anyhow!("no archives with a version"))
301+
}
305302

306-
println!("current version: {}", current);
303+
fn current_version_same(&mut self, prev: &str) -> Result<bool, Error> {
304+
// nightly's always changing
305+
if self.config.channel == Channel::Nightly {
306+
return Ok(false);
307+
}
308+
let prev_version = prev.split(' ').next().unwrap();
307309

310+
let current = self.load_version(|filename| filename.starts_with("rustc-"))?;
311+
println!("current version: {}", current);
308312
let current_version = current.split(' ').next().unwrap();
309313
self.current_version = Some(current_version.to_string());
310314

315+
let current_cargo = self.load_version(|filename| filename.starts_with("cargo-"))?;
316+
println!("current cargo version: {}", current_cargo);
317+
let current_version = current_cargo.split(' ').next().unwrap();
318+
self.current_cargo_version = Some(current_cargo.to_string());
319+
311320
// The release process for beta looks like so:
312321
//
313322
// * Force push master branch to beta branch
@@ -613,13 +622,43 @@ impl Context {
613622
return Ok(());
614623
};
615624

616-
if let Some(repo) = self.config.rustc_tag_repository.clone() {
617-
self.tag_repository(signer, &mut github, &repo, rustc_commit)?;
625+
if let Some(rustc_repo) = self.config.rustc_tag_repository.clone() {
626+
let rustc_version = self.current_version.clone().expect("has current version");
627+
self.tag_repository(
628+
signer,
629+
&mut github,
630+
&rustc_repo,
631+
rustc_commit,
632+
&rustc_version,
633+
)?;
618634

619635
// Once we've tagged rustc, kick off a thanks workflow run.
620636
github
621637
.token("rust-lang/thanks")?
622638
.workflow_dispatch("ci.yml", "master")?;
639+
640+
if let Some(cargo_repo) = self.config.cargo_tag_repository.clone() {
641+
let cargo_version = self
642+
.current_cargo_version
643+
.clone()
644+
.expect("has current cargo version");
645+
let cargo_commit = match github
646+
.token(&rustc_repo)?
647+
.read_file(Some(rustc_commit), "src/tools/cargo")?
648+
{
649+
github::GitFile::Submodule { sha } => sha,
650+
github::GitFile::File { .. } => {
651+
anyhow::bail!("src/tools/cargo is expected to be a submodule")
652+
}
653+
};
654+
self.tag_repository(
655+
signer,
656+
&mut github,
657+
&cargo_repo,
658+
&cargo_commit,
659+
&cargo_version,
660+
)?;
661+
}
623662
}
624663

625664
Ok(())
@@ -631,8 +670,8 @@ impl Context {
631670
github: &mut Github,
632671
repository: &str,
633672
commit: &str,
673+
version: &str,
634674
) -> Result<(), Error> {
635-
let version = self.current_version.as_ref().expect("has current version");
636675
let tag_name = version.to_owned();
637676
let username = "rust-lang/promote-release";
638677
let email = "release-team@rust-lang.org";

0 commit comments

Comments
 (0)