Skip to content

Commit 8f4b455

Browse files
authored
Merge pull request #69 from Mark-Simulacrum/tag-cargo
Automate Cargo tagging
2 parents 2ea4c86 + e3c5fbf commit 8f4b455

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
@@ -152,6 +152,14 @@ pub(crate) struct Config {
152152
/// Should be a org/repo code, e.g., rust-lang/rust.
153153
pub(crate) rustc_tag_repository: Option<String>,
154154

155+
/// Where to tag stable cargo releases.
156+
///
157+
/// This repository should have content write permissions with the github
158+
/// app configuration.
159+
///
160+
/// Should be a org/repo code, e.g., rust-lang/cargo.
161+
pub(crate) cargo_tag_repository: Option<String>,
162+
155163
/// Where to publish new blog PRs.
156164
///
157165
/// We create a new PR announcing releases in this repository; currently we
@@ -228,6 +236,7 @@ impl Config {
228236
recompress_xz: bool_env("RECOMPRESS_XZ")?,
229237
recompress_gz: bool_env("RECOMPRESS_GZ")?,
230238
rustc_tag_repository: maybe_env("RUSTC_TAG_REPOSITORY")?,
239+
cargo_tag_repository: maybe_env("CARGO_TAG_REPOSITORY")?,
231240
blog_repository: maybe_env("BLOG_REPOSITORY")?,
232241
blog_pr: maybe_env("BLOG_MERGE_PR")?,
233242
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
@@ -644,13 +653,43 @@ impl Context {
644653
return Ok(());
645654
};
646655

647-
if let Some(repo) = self.config.rustc_tag_repository.clone() {
648-
self.tag_repository(signer, &mut github, &repo, rustc_commit)?;
656+
if let Some(rustc_repo) = self.config.rustc_tag_repository.clone() {
657+
let rustc_version = self.current_version.clone().expect("has current version");
658+
self.tag_repository(
659+
signer,
660+
&mut github,
661+
&rustc_repo,
662+
rustc_commit,
663+
&rustc_version,
664+
)?;
649665

650666
// Once we've tagged rustc, kick off a thanks workflow run.
651667
github
652668
.token("rust-lang/thanks")?
653669
.workflow_dispatch("ci.yml", "master")?;
670+
671+
if let Some(cargo_repo) = self.config.cargo_tag_repository.clone() {
672+
let cargo_version = self
673+
.current_cargo_version
674+
.clone()
675+
.expect("has current cargo version");
676+
let cargo_commit = match github
677+
.token(&rustc_repo)?
678+
.read_file(Some(rustc_commit), "src/tools/cargo")?
679+
{
680+
github::GitFile::Submodule { sha } => sha,
681+
github::GitFile::File { .. } => {
682+
anyhow::bail!("src/tools/cargo is expected to be a submodule")
683+
}
684+
};
685+
self.tag_repository(
686+
signer,
687+
&mut github,
688+
&cargo_repo,
689+
&cargo_commit,
690+
&cargo_version,
691+
)?;
692+
}
654693
}
655694

656695
Ok(())
@@ -662,8 +701,8 @@ impl Context {
662701
github: &mut Github,
663702
repository: &str,
664703
commit: &str,
704+
version: &str,
665705
) -> Result<(), Error> {
666-
let version = self.current_version.as_ref().expect("has current version");
667706
let tag_name = version.to_owned();
668707
let username = "rust-lang/promote-release";
669708
let email = "release-team@rust-lang.org";

0 commit comments

Comments
 (0)