Skip to content

Commit fde06c3

Browse files
committed
rust: change release artifact naming convention
We change the filename so the tag is placed after the Python versions. e.g. `cpython-X.Y-<triple>-<build>-<tag>.tar.zst` -> `cpython-X.Y+<tag>-<triple>-<build>.tar.zst`. This naming scheme is better because the tag is effectively a version component and it should be earlier in the filename to aid sorting.
1 parent ebc4bee commit fde06c3

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

src/github.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use {
99
futures::StreamExt,
1010
octocrab::{models::workflows::WorkflowListArtifact, Octocrab, OctocrabBuilder},
1111
rayon::prelude::*,
12-
std::{collections::BTreeSet, io::Read, path::PathBuf},
12+
std::{
13+
collections::{BTreeMap, BTreeSet},
14+
io::Read,
15+
path::PathBuf,
16+
},
1317
zip::ZipArchive,
1418
};
1519

@@ -220,7 +224,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
220224
python_versions.insert(parts[1]);
221225
}
222226

223-
let mut wanted_filenames = BTreeSet::new();
227+
let mut wanted_filenames = BTreeMap::new();
224228
for version in python_versions {
225229
for (triple, release) in RELEASE_TRIPLES.iter() {
226230
if let Some(req) = &release.python_version_requirement {
@@ -231,20 +235,30 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
231235
}
232236

233237
for suffix in &release.suffixes {
234-
wanted_filenames.insert(format!(
235-
"cpython-{}-{}-{}-{}.tar.zst",
236-
version, triple, suffix, datetime
237-
));
238+
wanted_filenames.insert(
239+
format!(
240+
"cpython-{}-{}-{}-{}.tar.zst",
241+
version, triple, suffix, datetime
242+
),
243+
format!("cpython-{}+{}-{}-{}.tar.zst", version, tag, triple, suffix),
244+
);
238245
}
239246

240-
wanted_filenames.insert(format!(
241-
"cpython-{}-{}-install_only-{}.tar.gz",
242-
version, triple, datetime
243-
));
247+
wanted_filenames.insert(
248+
format!(
249+
"cpython-{}-{}-install_only-{}.tar.gz",
250+
version, triple, datetime
251+
),
252+
format!("cpython-{}+{}-{}-install_only.tar.gz", version, tag, triple),
253+
);
244254
}
245255
}
246256

247-
let missing = wanted_filenames.difference(&filenames).collect::<Vec<_>>();
257+
let missing = wanted_filenames
258+
.keys()
259+
.filter(|x| !filenames.contains(*x))
260+
.collect::<Vec<_>>();
261+
248262
for f in &missing {
249263
println!("missing release artifact: {}", f);
250264
}
@@ -265,13 +279,17 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
265279
));
266280
};
267281

268-
for filename in wanted_filenames.intersection(&filenames) {
269-
if release.assets.iter().any(|asset| &asset.name == filename) {
270-
println!("release asset {} already present; skipping", filename);
282+
for (source, dest) in wanted_filenames {
283+
if !filenames.contains(&source) {
284+
continue;
285+
}
286+
287+
if release.assets.iter().any(|asset| asset.name == dest) {
288+
println!("release asset {} already present; skipping", dest);
271289
continue;
272290
}
273291

274-
let path = dist_dir.join(filename);
292+
let path = dist_dir.join(&source);
275293
let file_data = std::fs::read(&path)?;
276294

277295
let mut url = release.upload_url.clone();
@@ -283,9 +301,9 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
283301

284302
url.query_pairs_mut()
285303
.clear()
286-
.append_pair("name", filename.as_str());
304+
.append_pair("name", dest.as_str());
287305

288-
println!("uploading {} to {}", filename, url);
306+
println!("uploading {} to {}", source, url);
289307

290308
let request = client
291309
.request_builder(url, reqwest::Method::POST)

0 commit comments

Comments
 (0)