Skip to content
Draft
2,721 changes: 1,339 additions & 1,382 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ backoff = { version = "0.4", features = ["tokio"] }
base16ct = { version = "0.1", features = ["std"] }
bytes = "1.1"
camino = "1.0"
clap = { version = "3.1", features = ["default", "derive", "env"] }
clap = { version = "4.5", features = ["default", "derive", "env"] }
color-eyre = "0.6"
derivative = "2.2"
futures-util = "0.3"
Expand All @@ -32,18 +32,18 @@ tracing-error = "0.2"
tracing-subscriber = { version = "0.3", features = ["default", "json"] }
url = "2.2"

gitlab-runner = "0.0.7"
# gitlab-runner = { path = "../gitlab-runner-rs/gitlab-runner" }
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }
# gitlab-runner = "0.1.0"
gitlab-runner = { path = "../gitlab-runner-rs/gitlab-runner" }
# open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }

[dev-dependencies]
claim = "0.5"
rstest = "0.12"
wiremock = "0.5"
zip = "0.5"
zip = "2.2.3"

gitlab-runner-mock = "0.0.5"
# gitlab-runner-mock = { path = "../gitlab-runner-rs/gitlab-runner-mock" }
open-build-service-mock = { git = "https://github.com/collabora/open-build-service-rs" }
# open-build-service-mock = { path = "../open-build-service-rs/open-build-service-mock" }
# gitlab-runner-mock = "0.1.0"
gitlab-runner-mock = { path = "../gitlab-runner-rs/gitlab-runner-mock" }
# open-build-service-mock = { git = "https://github.com/collabora/open-build-service-rs" }
open-build-service-mock = { path = "../open-build-service-rs/open-build-service-mock" }
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ dput PROJECT DSC_FILE
[--branch-to BRANCHED_PROJECT]
[--build-info-out BUILD_INFO_FILE=build-info.yml]
[--rebuild-if-unchanged]
[--repositories REPO[,REPO...]]
```

This will upload the given .dsc file, as well as any files referenced by it, to
Expand Down Expand Up @@ -124,6 +125,16 @@ Note that, if `--branch-to` was specified, this will, in practice, never be
triggered: due to the way metadata files are handled, right after a branching
operation, there will *always* be a change to upload.

##### `--repositories REPO[,REPO,...]`

A comma separated list of one or more repositories. If set the .dsc file will be
uploaded for only specified repositories that are part of the target project,
otherwise it will be uploaded for all the target projects repositories.
```
// TODO: Should this work as a filter or specify repositories to build against
```


#### `generate-monitor`

```bash
Expand Down
23 changes: 13 additions & 10 deletions src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,31 @@ pub async fn async_save_to_tempfile<R: Read + Send + 'static>(mut reader: R) ->

#[async_trait]
pub trait ArtifactDirectory: Send + Sync {
type Reader: Read + Send + 'static;
type Reader<'a>: Read + Send
where
Self: 'a;

async fn get_or_none(&self, filename: &str) -> Result<Option<Self::Reader>>;
async fn get_or_none(&self, filename: &str) -> Result<Option<Self::Reader<'_>>>;

async fn get(&self, filename: &str) -> Result<Self::Reader> {
async fn get(&self, filename: &str) -> Result<Self::Reader<'_>> {
self.get_or_none(filename)
.await?
.ok_or_else(|| eyre!("Could not find artifact '{}'", filename))
}

async fn get_file_or_none(&self, filename: &str) -> Result<Option<AsyncFile>> {
let reader = self.get_or_none(filename).await?;
Ok(if let Some(reader) = reader {
Some(async_save_to_tempfile(reader).await?)
let mut reader = self.get_or_none(filename).await?;
Ok(if let Some(reader) = &mut reader {
Some(AsyncFile::from_std(save_to_tempfile(reader)?))
} else {
None
})
}

async fn get_file(&self, filename: &str) -> Result<AsyncFile> {
let reader = self.get(filename).await?;
async_save_to_tempfile(reader).await
self.get_file_or_none(filename)
.await?
.ok_or_else(|| eyre!("Could not find artifact '{}'", filename))
}

async fn get_data_or_none(&self, filename: &str) -> Result<Option<Vec<u8>>> {
Expand Down Expand Up @@ -98,9 +101,9 @@ pub mod test_support {

#[async_trait]
impl ArtifactDirectory for MockArtifactDirectory {
type Reader = MockArtifactReader;
type Reader<'a> = MockArtifactReader;

async fn get_or_none(&self, filename: &str) -> Result<Option<Self::Reader>> {
async fn get_or_none(&self, filename: &str) -> Result<Option<Self::Reader<'_>>> {
Ok(self
.artifacts
.get(filename)
Expand Down
52 changes: 37 additions & 15 deletions src/binaries.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::{collections::HashMap, io};
use std::{
collections::HashMap,
io,
path::{Path, PathBuf},
};

use color_eyre::eyre::{Report, Result, WrapErr};
use futures_util::TryStreamExt;
use open_build_service_api as obs;
use tokio::{fs::File as AsyncFile, io::AsyncSeekExt};
use tokio::fs::File as AsyncFile;
use tokio_util::compat::FuturesAsyncReadCompatExt;
use tracing::{info_span, instrument, Instrument};

Expand All @@ -12,11 +16,12 @@ use crate::retry::retry_request;
#[instrument(skip(client))]
pub async fn download_binaries(
client: obs::Client,
build_dir: &Path,
project: &str,
package: &str,
repository: &str,
arch: &str,
) -> Result<HashMap<String, AsyncFile>> {
) -> Result<HashMap<String, PathBuf>> {
let binary_list = retry_request(|| async {
client
.project(project.to_owned())
Expand All @@ -28,13 +33,15 @@ pub async fn download_binaries(
let mut binaries = HashMap::new();

for binary in binary_list.binaries {
let mut dest = retry_request(|| {
let path = retry_request(|| {
let binary = binary.clone();
let client = client.clone();
async move {
let mut dest = AsyncFile::from_std(
tempfile::tempfile().wrap_err("Failed to create temporary file")?,
);
let (file, path) = tempfile::Builder::new()
.prefix("obs-glr-")
.suffix(".bin")
.tempfile_in(build_dir)?
.keep()?;

let stream = client
.project(project.to_owned())
Expand All @@ -48,20 +55,17 @@ pub async fn download_binaries(
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
.into_async_read()
.compat(),
&mut dest,
&mut AsyncFile::from_std(file),
)
.await
.wrap_err("Failed to download file")?;
Ok::<AsyncFile, Report>(dest)
Ok::<PathBuf, Report>(path)
}
})
.instrument(info_span!("download_binaries:download", ?binary))
.await?;

dest.rewind()
.instrument(info_span!("download_binaries:rewind", ?binary))
.await?;
binaries.insert(binary.filename, dest);
binaries.insert(binary.filename, path);
}

Ok(binaries)
Expand All @@ -81,6 +85,10 @@ mod tests {

#[tokio::test]
async fn test_build_results() {
let build_dir = tempfile::Builder::new()
.prefix("obs-glr-test-bin-")
.tempdir()
.unwrap();
let test_file = "test.bin";
let test_contents = "123980238";

Expand Down Expand Up @@ -117,13 +125,27 @@ mod tests {
let client = create_default_client(&mock);

let mut binaries = assert_ok!(
download_binaries(client, TEST_PROJECT, TEST_PACKAGE_1, TEST_REPO, TEST_ARCH_1).await
download_binaries(
client,
build_dir.path(),
TEST_PROJECT,
TEST_PACKAGE_1,
TEST_REPO,
TEST_ARCH_1
)
.await
);
assert_eq!(binaries.len(), 1);

let binary = assert_some!(binaries.get_mut(test_file));
let mut contents = String::new();
assert_ok!(binary.read_to_string(&mut contents).await);
assert_ok!(
AsyncFile::open(binary)
.await
.unwrap()
.read_to_string(&mut contents)
.await
);
assert_eq!(contents, test_contents);
}
}
Loading