Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 57 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 16 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@
[package]
name = "obs-gitlab-runner"
version = "0.1.8"
edition = "2024"
license = "MIT OR Apache-2.0"
[workspace]
resolver = "3"
members = [
"obo-core",
"obo-tests",
"obo-test-support",
"obs-gitlab-runner"
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[workspace.dependencies]
async-trait = "0.1"
base16ct = { version = "0.2", features = ["std"] }
bytes = "1.10"
camino = "1.1"
claims = "0.8"
clap = { version = "4.5", features = ["default", "derive", "env"] }
color-eyre = "0.6"
derivative = "2.2"
futures-util = "0.3"
md-5 = "0.10"
reqwest = "0.12"
rfc822-like = "0.2"
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" }
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-api" }
rstest = "0.26"
serde = "1.0"
serde_yaml = "0.9"
shellexpand = "3.1"
shell-words = "1.1"
strum = { version = "0.27", features = ["derive"] }
tempfile = "3.20"
thiserror = "2.0"
tokio = { version = "1.45", features = ["full"] }
tokio-retry2 = { version = "0.6.0", features = ["jitter"] }
tokio-util = { version = "0.7", features = ["full"] }
tracing = "0.1"
tracing-error = "0.2"
tracing-subscriber = { version = "0.3", features = ["default", "json"] }
url = "2.5"

gitlab-runner = "0.3.0-rc1"
# gitlab-runner = { path = "../gitlab-runner-rs/gitlab-runner" }
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
thiserror = "2.0.12"
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }

[dev-dependencies]
claims = "0.8"
rstest = "0.26"
wiremock = "0.6"
zip = "5.1"

gitlab-runner-mock = "0.2.1"
# 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" }
37 changes: 37 additions & 0 deletions obo-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "obo-core"
description = "OBS Build Orchestrator — core"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
async-trait.workspace = true
base16ct = { version = "0.2", features = ["std"] }
bytes = "1.10"
camino.workspace = true
clap.workspace = true
color-eyre.workspace = true
derivative.workspace = true
futures-util.workspace = true
md-5 = "0.10"
obo-test-support = { path = "../obo-test-support" }
open-build-service-api.workspace = true
reqwest = "0.12"
rfc822-like = "0.2"
serde.workspace = true
serde_yaml.workspace = true
shell-words.workspace = true
tempfile.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-retry2 = { version = "0.6.0", features = ["jitter"] }
tokio-util.workspace = true
tracing.workspace = true

[dev-dependencies]
claims.workspace = true
rstest.workspace = true
open-build-service-mock.workspace = true
wiremock.workspace = true

52 changes: 52 additions & 0 deletions src/actions.rs → obo-core/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ impl FlagSupportingExplicitValue for clap::Arg {
}
}

#[derive(Debug)]
struct CommandBuilder {
args: Vec<String>,
}

impl CommandBuilder {
fn new(name: String) -> Self {
Self { args: vec![name] }
}

fn add(&mut self, arg: &str, value: &str) -> &mut Self {
self.args
.push(format!("--{arg}={}", shell_words::quote(value)));
self
}

fn build(self) -> String {
self.args.join(" ")
}
}

#[derive(Parser, Debug)]
pub struct DputAction {
pub project: String,
Expand Down Expand Up @@ -74,6 +95,24 @@ pub struct MonitorAction {
pub build_log_out: String,
}

impl MonitorAction {
pub fn generate_command(&self) -> String {
let mut builder = CommandBuilder::new("monitor".to_owned());
builder
.add("project", &self.project)
.add("package", &self.package)
.add("rev", &self.rev)
.add("srcmd5", &self.srcmd5)
.add("repository", &self.repository)
.add("arch", &self.arch)
.add("build-log-out", &self.build_log_out);
if let Some(endtime) = &self.prev_endtime_for_commit {
builder.add("prev-endtime-for-commit", &endtime.to_string());
}
builder.build()
}
}

#[derive(Parser, Debug)]
pub struct DownloadBinariesAction {
#[clap(long)]
Expand All @@ -88,6 +127,19 @@ pub struct DownloadBinariesAction {
pub build_results_dir: Utf8PathBuf,
}

impl DownloadBinariesAction {
pub fn generate_command(&self) -> String {
let mut builder = CommandBuilder::new("download-binaries".to_owned());
builder
.add("project", &self.project)
.add("package", &self.package)
.add("repository", &self.repository)
.add("arch", &self.arch)
.add("build-results-dir", self.build_results_dir.as_str());
builder.build()
}
}

#[derive(Parser, Debug)]
pub struct PruneAction {
#[clap(long, default_value_t = DEFAULT_BUILD_INFO.to_owned())]
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/binaries.rs → obo-core/src/binaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ mod tests {
use std::time::SystemTime;

use claims::*;
use obo_test_support::*;
use open_build_service_mock::*;

use crate::{artifacts::test_support::MockArtifactDirectory, test_support::*};
use crate::artifacts::test_support::MockArtifactDirectory;

use super::*;

Expand Down
3 changes: 1 addition & 2 deletions src/build_meta.rs → obo-core/src/build_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@
Ok(result) => Ok(Some(result)),
Err(e) => {
for cause in e.chain() {
if let Some(obs::Error::ApiError(obs::ApiError { code, .. })) =
cause.downcast_ref::<obs::Error>()
{
if code == "unknown_package" {
return Ok(None);
}
}

Check warning on line 130 in obo-core/src/build_meta.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/build_meta.rs:124:21 | 124 | / if let Some(obs::Error::ApiError(obs::ApiError { code, .. })) = 125 | | cause.downcast_ref::<obs::Error>() 126 | | { 127 | | if code == "unknown_package" { ... | 130 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `#[warn(clippy::collapsible_if)]` on by default help: collapse nested if block | 125 ~ cause.downcast_ref::<obs::Error>() 126 ~ && code == "unknown_package" { 127 | return Ok(None); 128 ~ } |

Check warning on line 130 in obo-core/src/build_meta.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/build_meta.rs:124:21 | 124 | / if let Some(obs::Error::ApiError(obs::ApiError { code, .. })) = 125 | | cause.downcast_ref::<obs::Error>() 126 | | { 127 | | if code == "unknown_package" { ... | 130 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `#[warn(clippy::collapsible_if)]` on by default help: collapse nested if block | 125 ~ cause.downcast_ref::<obs::Error>() 126 ~ && code == "unknown_package" { 127 | return Ok(None); 128 ~ } |

Check warning on line 130 in obo-core/src/build_meta.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/build_meta.rs:124:21 | 124 | / if let Some(obs::Error::ApiError(obs::ApiError { code, .. })) = 125 | | cause.downcast_ref::<obs::Error>() 126 | | { 127 | | if code == "unknown_package" { ... | 130 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `#[warn(clippy::collapsible_if)]` on by default help: collapse nested if block | 125 ~ cause.downcast_ref::<obs::Error>() 126 ~ && code == "unknown_package" { 127 | return Ok(None); 128 ~ } |

Check warning on line 130 in obo-core/src/build_meta.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/build_meta.rs:124:21 | 124 | / if let Some(obs::Error::ApiError(obs::ApiError { code, .. })) = 125 | | cause.downcast_ref::<obs::Error>() 126 | | { 127 | | if code == "unknown_package" { ... | 130 | | } | |_____________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `#[warn(clippy::collapsible_if)]` on by default help: collapse nested if block | 125 ~ cause.downcast_ref::<obs::Error>() 126 ~ && code == "unknown_package" { 127 | return Ok(None); 128 ~ } |
}

Err(e)
Expand Down Expand Up @@ -265,11 +265,10 @@
use std::time::{Duration, SystemTime};

use claims::*;
use obo_test_support::*;
use open_build_service_mock::*;
use rstest::rstest;

use crate::test_support::*;

use super::*;

#[tokio::test]
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions obo-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub mod actions;
pub mod artifacts;
pub mod binaries;
pub mod build_meta;
pub mod dsc;
pub mod logging;
pub mod monitor;
pub mod prune;
pub mod retry;
pub mod upload;
57 changes: 57 additions & 0 deletions obo-core/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use tracing::{
Event, Metadata,
field::{self, Field},
};

pub const TRACING_FIELD: &str = "obo_core.output";

#[macro_export]
macro_rules! outputln {
($($args:tt)*) => {
::tracing::trace!(obo_core.output = true, $($args)*)
};
}

struct OutputTester(bool);

impl field::Visit for OutputTester {
fn record_bool(&mut self, field: &Field, value: bool) {
if field.name() == TRACING_FIELD {
self.0 = value;
}
}

fn record_debug(&mut self, _field: &Field, _value: &dyn std::fmt::Debug) {}
}

pub fn is_output_field_set_in_event(event: &Event<'_>) -> bool {
let mut visitor = OutputTester(false);
event.record(&mut visitor);
visitor.0
}

pub fn is_output_field_in_metadata(metadata: &Metadata<'_>) -> bool {
metadata.fields().iter().any(|f| f.name() == TRACING_FIELD)
}

struct MessageExtractor(Option<String>);

impl field::Visit for MessageExtractor {
fn record_str(&mut self, field: &Field, value: &str) {
if field.name() == "message" {
self.0 = Some(value.to_owned());
}
}

fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) {
if field.name() == "message" {
self.0 = Some(format!("{value:?}"));
}
}
}

pub fn get_event_message(event: &Event) -> Option<String> {
let mut visitor = MessageExtractor(None);
event.record(&mut visitor);
visitor.0
}
3 changes: 2 additions & 1 deletion src/monitor.rs → obo-core/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,11 @@ mod tests {
use std::{collections::HashMap, time::SystemTime};

use claims::*;
use obo_test_support::*;
use obs::PackageCode;
use open_build_service_mock::*;

use crate::{artifacts::test_support::MockArtifactDirectory, test_support::*};
use crate::artifacts::test_support::MockArtifactDirectory;

use super::*;

Expand Down
3 changes: 1 addition & 2 deletions src/prune.rs → obo-core/src/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
.wrap_err("Failed to list package")
)?;

if let Some(expected_rev) = expected_rev {
if dir.rev.as_deref() != Some(expected_rev) {
outputln!(
"Latest revision is {}, skipping prune",
dir.rev.as_deref().unwrap_or("[unknown]")
);
return Ok(());
}
}

Check warning on line 56 in obo-core/src/prune.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/prune.rs:48:5 | 48 | / if let Some(expected_rev) = expected_rev { 49 | | if dir.rev.as_deref() != Some(expected_rev) { 50 | | outputln!( 51 | | "Latest revision is {}, skipping prune", ... | 56 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 48 ~ if let Some(expected_rev) = expected_rev 49 ~ && dir.rev.as_deref() != Some(expected_rev) { 50 | outputln!( ... 54 | return Ok(()); 55 ~ } |

Check warning on line 56 in obo-core/src/prune.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/prune.rs:48:5 | 48 | / if let Some(expected_rev) = expected_rev { 49 | | if dir.rev.as_deref() != Some(expected_rev) { 50 | | outputln!( 51 | | "Latest revision is {}, skipping prune", ... | 56 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 48 ~ if let Some(expected_rev) = expected_rev 49 ~ && dir.rev.as_deref() != Some(expected_rev) { 50 | outputln!( ... 54 | return Ok(()); 55 ~ } |

Check warning on line 56 in obo-core/src/prune.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/prune.rs:48:5 | 48 | / if let Some(expected_rev) = expected_rev { 49 | | if dir.rev.as_deref() != Some(expected_rev) { 50 | | outputln!( 51 | | "Latest revision is {}, skipping prune", ... | 56 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 48 ~ if let Some(expected_rev) = expected_rev 49 ~ && dir.rev.as_deref() != Some(expected_rev) { 50 | outputln!( ... 54 | return Ok(()); 55 ~ } |

Check warning on line 56 in obo-core/src/prune.rs

View workflow job for this annotation

GitHub Actions / cargo clippy latest

this `if` statement can be collapsed

warning: this `if` statement can be collapsed --> obo-core/src/prune.rs:48:5 | 48 | / if let Some(expected_rev) = expected_rev { 49 | | if dir.rev.as_deref() != Some(expected_rev) { 50 | | outputln!( 51 | | "Latest revision is {}, skipping prune", ... | 56 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 48 ~ if let Some(expected_rev) = expected_rev 49 ~ && dir.rev.as_deref() != Some(expected_rev) { 50 | outputln!( ... 54 | return Ok(()); 55 ~ } |

retry_request!(
client
Expand Down Expand Up @@ -95,10 +95,9 @@
use std::time::SystemTime;

use claims::*;
use obo_test_support::*;
use open_build_service_mock::*;

use crate::test_support::*;

use super::*;

#[tokio::test]
Expand Down
Loading
Loading