Skip to content

Commit 61b71b7

Browse files
committed
rust: upload release artifacts in parallel
It takes several minutes to upload releases. And GitHub sorts the artifacts by their filename, so upload order isn't important. Let's upload in parallel so things finish faster.
1 parent 8ab167c commit 61b71b7

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/github.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async fn fetch_artifact(client: &Octocrab, artifact: WorkflowListArtifact) -> Re
3434
async fn upload_release_artifact(
3535
client: &Octocrab,
3636
release: &Release,
37-
filename: &str,
37+
filename: String,
3838
data: Vec<u8>,
3939
dry_run: bool,
4040
) -> Result<()> {
@@ -50,7 +50,7 @@ async fn upload_release_artifact(
5050
url.set_path(path);
5151
}
5252

53-
url.query_pairs_mut().clear().append_pair("name", filename);
53+
url.query_pairs_mut().clear().append_pair("name", &filename);
5454

5555
println!("uploading to {}", url);
5656

@@ -364,6 +364,8 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
364364

365365
let mut digests = BTreeMap::new();
366366

367+
let mut fs = vec![];
368+
367369
for (source, dest) in wanted_filenames {
368370
if !filenames.contains(&source) {
369371
continue;
@@ -378,15 +380,26 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
378380

379381
digests.insert(dest.clone(), digest.clone());
380382

381-
upload_release_artifact(&client, &release, &dest, file_data, dry_run).await?;
382-
upload_release_artifact(
383+
fs.push(upload_release_artifact(
383384
&client,
384385
&release,
385-
&format!("{}.sha256", dest),
386+
dest.clone(),
387+
file_data,
388+
dry_run,
389+
));
390+
fs.push(upload_release_artifact(
391+
&client,
392+
&release,
393+
format!("{}.sha256", dest),
386394
format!("{}\n", digest).into_bytes(),
387395
dry_run,
388-
)
389-
.await?;
396+
));
397+
}
398+
399+
let mut buffered = futures::stream::iter(fs).buffer_unordered(6);
400+
401+
while let Some(res) = buffered.next().await {
402+
res?;
390403
}
391404

392405
let shasums = digests
@@ -400,7 +413,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
400413
upload_release_artifact(
401414
&client,
402415
&release,
403-
"SHA256SUMS",
416+
"SHA256SUMS".to_string(),
404417
shasums.into_bytes(),
405418
dry_run,
406419
)

0 commit comments

Comments
 (0)