diff --git a/Cargo.lock b/Cargo.lock index 916ee34..ff7d0f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.80" +version = "0.1.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "644dd749086bf3771a2fbc5f256fdb982d53f011c7d5d560304eafeecebce79d" dependencies = [ "proc-macro2", "quote", @@ -1214,9 +1214,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.68" +version = "0.10.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6" dependencies = [ "bitflags 2.5.0", "cfg-if", @@ -1246,9 +1246,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.104" +version = "0.9.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc" dependencies = [ "cc", "libc", diff --git a/gitlab-runner/Cargo.toml b/gitlab-runner/Cargo.toml index a210cf9..5f47582 100644 --- a/gitlab-runner/Cargo.toml +++ b/gitlab-runner/Cargo.toml @@ -24,7 +24,7 @@ bytes = "1.9.0" zip = "2.2.2" pin-project = "1.0.7" futures = "0.3.15" -async-trait = "0.1.50" +async-trait = "0.1.86" tempfile = "3.15.0" parking_lot = "0.12.0" tracing-subscriber = "0.3.10" diff --git a/gitlab-runner/examples/demo-runner.rs b/gitlab-runner/examples/demo-runner.rs index 6e6c945..1f3be25 100644 --- a/gitlab-runner/examples/demo-runner.rs +++ b/gitlab-runner/examples/demo-runner.rs @@ -141,6 +141,7 @@ enum DemoFile { Fact { index: usize, value: String }, } +#[async_trait::async_trait] impl UploadableFile for DemoFile { type Data<'a> = Box; @@ -151,11 +152,11 @@ impl UploadableFile for DemoFile { } } - fn get_data(&self) -> Box { - match self { + async fn get_data(&self) -> Result, ()> { + Ok(match self { DemoFile::ReadMe => Box::new(b"Demo runner artifact\n".as_slice()), DemoFile::Fact { value, .. } => Box::new(Cursor::new(value.clone().into_bytes())), - } + }) } } diff --git a/gitlab-runner/src/lib.rs b/gitlab-runner/src/lib.rs index 3377c00..6ecd209 100644 --- a/gitlab-runner/src/lib.rs +++ b/gitlab-runner/src/lib.rs @@ -59,6 +59,7 @@ pub use client::Phase; /// generated or downloaded from some other source on demand. The /// `get_path` method is required so that the globbing Gitlab expects /// can be performed without the handler needing to be involved. +#[async_trait::async_trait] pub trait UploadableFile: Eq { /// The type of the data stream returned by /// [`get_data`](Self::get_data) @@ -76,7 +77,7 @@ pub trait UploadableFile: Eq { /// Get something that can provide the data for this file. /// /// This can be any implementor of [`AsyncRead`]. - fn get_data(&self) -> Self::Data<'_>; + async fn get_data(&self) -> Result, ()>; } /// An [`UploadableFile`] type for JobHandlers that expose no files. @@ -87,13 +88,14 @@ pub trait UploadableFile: Eq { #[derive(Clone, Debug, Eq, PartialEq)] pub struct NoFiles {} +#[async_trait::async_trait] impl UploadableFile for NoFiles { type Data<'a> = &'a [u8]; fn get_path(&self) -> Cow<'_, str> { unreachable!("tried to get path of NoFiles") } - fn get_data(&self) -> Self::Data<'_> { + async fn get_data(&self) -> Result, ()> { unreachable!("tried to read data from NoFiles"); } } diff --git a/gitlab-runner/src/run.rs b/gitlab-runner/src/run.rs index bb73569..f63a6de 100644 --- a/gitlab-runner/src/run.rs +++ b/gitlab-runner/src/run.rs @@ -135,7 +135,7 @@ where let path = file.get_path(); match uploader.file(path.to_string()).await { Ok(mut upload) => { - let mut data = file.get_data(); + let mut data = file.get_data().await?; match futures::io::copy(&mut data, &mut upload).await { Ok(_) => { uploaded += 1; diff --git a/gitlab-runner/tests/artifacts.rs b/gitlab-runner/tests/artifacts.rs index 5674d5a..c6e4096 100644 --- a/gitlab-runner/tests/artifacts.rs +++ b/gitlab-runner/tests/artifacts.rs @@ -29,11 +29,11 @@ impl UploadableFile for TestFile { TestFile::Test2 => "test2".into(), } } - fn get_data(&self) -> &'_ [u8] { - match self { + async fn get_data(&self) -> Result<&'_ [u8], ()> { + Ok(match self { TestFile::Test => b"testdata".as_slice(), TestFile::Test2 => b"testdata2".as_slice(), - } + }) } }