Skip to content

Commit c0aac91

Browse files
committed
Refactor out the OBS interaction code into a new 'obo-core' crate
This is largely just a rename, as well as the slightly-silly `obo-test-support` crate that exists to be depended on by `obo-core` *and* `obs-gitlab-runner`.
1 parent a0ad286 commit c0aac91

28 files changed

+322
-154
lines changed

Cargo.lock

Lines changed: 41 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,30 @@
1-
[package]
2-
name = "obs-gitlab-runner"
3-
version = "0.1.8"
4-
edition = "2024"
5-
license = "MIT OR Apache-2.0"
1+
[workspace]
2+
resolver = "3"
3+
members = [
4+
"obo-core",
5+
"obo-test-support",
6+
"obs-gitlab-runner"
7+
]
68

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
9-
[dependencies]
9+
[workspace.dependencies]
1010
async-trait = "0.1"
11-
base16ct = { version = "0.2", features = ["std"] }
12-
bytes = "1.10"
1311
camino = "1.1"
12+
claims = "0.8"
1413
clap = { version = "4.5", features = ["default", "derive", "env"] }
1514
color-eyre = "0.6"
1615
derivative = "2.2"
1716
futures-util = "0.3"
18-
md-5 = "0.10"
19-
reqwest = "0.12"
20-
rfc822-like = "0.2"
17+
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
18+
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }
19+
open-build-service-mock = { git = "https://github.com/collabora/open-build-service-rs" }
20+
# open-build-service-mock = { path = "../open-build-service-rs/open-build-service-api" }
21+
rstest = "0.26"
2122
serde = "1.0"
2223
serde_yaml = "0.9"
23-
shellexpand = "3.1"
2424
shell-words = "1.1"
25-
strum = { version = "0.27", features = ["derive"] }
2625
tempfile = "3.20"
26+
thiserror = "2.0"
2727
tokio = { version = "1.45", features = ["full"] }
28-
tokio-retry2 = { version = "0.6.0", features = ["jitter"] }
2928
tokio-util = { version = "0.7", features = ["full"] }
3029
tracing = "0.1"
31-
tracing-error = "0.2"
32-
tracing-subscriber = { version = "0.3", features = ["default", "json"] }
33-
url = "2.5"
34-
35-
gitlab-runner = "0.3.0-rc1"
36-
# gitlab-runner = { path = "../gitlab-runner-rs/gitlab-runner" }
37-
open-build-service-api = { git = "https://github.com/collabora/open-build-service-rs" }
38-
thiserror = "2.0.12"
39-
# open-build-service-api = { path = "../open-build-service-rs/open-build-service-api" }
40-
41-
[dev-dependencies]
42-
claims = "0.8"
43-
rstest = "0.26"
4430
wiremock = "0.6"
45-
zip = "5.1"
46-
47-
gitlab-runner-mock = "0.2.1"
48-
# gitlab-runner-mock = { path = "../gitlab-runner-rs/gitlab-runner-mock" }
49-
open-build-service-mock = { git = "https://github.com/collabora/open-build-service-rs" }
50-
# open-build-service-mock = { path = "../open-build-service-rs/open-build-service-mock" }

obo-core/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "obo-core"
3+
description = "OBS Build Orchestrator — core"
4+
version = "0.1.0"
5+
edition = "2024"
6+
license = "MIT OR Apache-2.0"
7+
8+
[dependencies]
9+
async-trait.workspace = true
10+
base16ct = { version = "0.2", features = ["std"] }
11+
bytes = "1.10"
12+
camino.workspace = true
13+
clap.workspace = true
14+
color-eyre.workspace = true
15+
derivative.workspace = true
16+
futures-util.workspace = true
17+
md-5 = "0.10"
18+
obo-test-support = { path = "../obo-test-support" }
19+
open-build-service-api.workspace = true
20+
reqwest = "0.12"
21+
rfc822-like = "0.2"
22+
serde.workspace = true
23+
serde_yaml.workspace = true
24+
shell-words.workspace = true
25+
tempfile.workspace = true
26+
thiserror.workspace = true
27+
tokio.workspace = true
28+
tokio-retry2 = { version = "0.6.0", features = ["jitter"] }
29+
tokio-util.workspace = true
30+
tracing.workspace = true
31+
32+
[dev-dependencies]
33+
claims.workspace = true
34+
rstest.workspace = true
35+
open-build-service-mock.workspace = true
36+
wiremock.workspace = true
37+

src/actions.rs renamed to obo-core/src/actions.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ impl FlagSupportingExplicitValue for clap::Arg {
4242
}
4343
}
4444

45+
#[derive(Debug)]
46+
struct CommandBuilder {
47+
args: Vec<String>,
48+
}
49+
50+
impl CommandBuilder {
51+
fn new(name: String) -> Self {
52+
Self { args: vec![name] }
53+
}
54+
55+
fn add(&mut self, arg: &str, value: &str) -> &mut Self {
56+
self.args
57+
.push(format!("--{arg}={}", shell_words::quote(value)));
58+
self
59+
}
60+
61+
fn build(self) -> String {
62+
self.args.join(" ")
63+
}
64+
}
65+
4566
#[derive(Parser, Debug)]
4667
pub struct DputAction {
4768
pub project: String,
@@ -74,6 +95,24 @@ pub struct MonitorAction {
7495
pub build_log_out: String,
7596
}
7697

98+
impl MonitorAction {
99+
pub fn generate_command(&self) -> String {
100+
let mut builder = CommandBuilder::new("monitor".to_owned());
101+
builder
102+
.add("project", &self.project)
103+
.add("package", &self.package)
104+
.add("rev", &self.rev)
105+
.add("srcmd5", &self.srcmd5)
106+
.add("repository", &self.repository)
107+
.add("arch", &self.arch)
108+
.add("build-log-out", &self.build_log_out);
109+
if let Some(endtime) = &self.prev_endtime_for_commit {
110+
builder.add("prev-endtime-for-commit", &endtime.to_string());
111+
}
112+
builder.build()
113+
}
114+
}
115+
77116
#[derive(Parser, Debug)]
78117
pub struct DownloadBinariesAction {
79118
#[clap(long)]
@@ -88,6 +127,19 @@ pub struct DownloadBinariesAction {
88127
pub build_results_dir: Utf8PathBuf,
89128
}
90129

130+
impl DownloadBinariesAction {
131+
pub fn generate_command(&self) -> String {
132+
let mut builder = CommandBuilder::new("download-binaries".to_owned());
133+
builder
134+
.add("project", &self.project)
135+
.add("package", &self.package)
136+
.add("repository", &self.repository)
137+
.add("arch", &self.arch)
138+
.add("build-results-dir", self.build_results_dir.as_str());
139+
builder.build()
140+
}
141+
}
142+
91143
#[derive(Parser, Debug)]
92144
pub struct PruneAction {
93145
#[clap(long, default_value_t = DEFAULT_BUILD_INFO.to_owned())]
File renamed without changes.

src/binaries.rs renamed to obo-core/src/binaries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ mod tests {
8080
use std::time::SystemTime;
8181

8282
use claims::*;
83+
use obo_test_support::*;
8384
use open_build_service_mock::*;
8485

85-
use crate::{artifacts::test_support::MockArtifactDirectory, test_support::*};
86+
use crate::artifacts::test_support::MockArtifactDirectory;
8687

8788
use super::*;
8889

src/build_meta.rs renamed to obo-core/src/build_meta.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,10 @@ mod tests {
265265
use std::time::{Duration, SystemTime};
266266

267267
use claims::*;
268+
use obo_test_support::*;
268269
use open_build_service_mock::*;
269270
use rstest::rstest;
270271

271-
use crate::test_support::*;
272-
273272
use super::*;
274273

275274
#[tokio::test]
File renamed without changes.

obo-core/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub mod actions;
2+
pub mod artifacts;
3+
pub mod binaries;
4+
pub mod build_meta;
5+
pub mod dsc;
6+
pub mod logging;
7+
pub mod monitor;
8+
pub mod prune;
9+
pub mod retry;
10+
pub mod upload;

obo-core/src/logging.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use tracing::{
2+
Event, Metadata,
3+
field::{self, Field},
4+
};
5+
6+
pub const TRACING_FIELD: &str = "obo_core.output";
7+
8+
#[macro_export]
9+
macro_rules! outputln {
10+
($($args:tt)*) => {
11+
::tracing::trace!(obo_core.output = true, $($args)*)
12+
};
13+
}
14+
15+
struct OutputTester(bool);
16+
17+
impl field::Visit for OutputTester {
18+
fn record_bool(&mut self, field: &Field, value: bool) {
19+
if field.name() == TRACING_FIELD {
20+
self.0 = value;
21+
}
22+
}
23+
24+
fn record_debug(&mut self, _field: &Field, _value: &dyn std::fmt::Debug) {}
25+
}
26+
27+
pub fn is_output_field_set_in_event(event: &Event<'_>) -> bool {
28+
let mut visitor = OutputTester(false);
29+
event.record(&mut visitor);
30+
visitor.0
31+
}
32+
33+
pub fn is_output_field_in_metadata(metadata: &Metadata<'_>) -> bool {
34+
metadata.fields().iter().any(|f| f.name() == TRACING_FIELD)
35+
}
36+
37+
struct MessageExtractor(Option<String>);
38+
39+
impl field::Visit for MessageExtractor {
40+
fn record_str(&mut self, field: &Field, value: &str) {
41+
if field.name() == "message" {
42+
self.0 = Some(value.to_owned());
43+
}
44+
}
45+
46+
fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) {
47+
if field.name() == "message" {
48+
self.0 = Some(format!("{value:?}"));
49+
}
50+
}
51+
}
52+
53+
pub fn get_event_message(event: &Event) -> Option<String> {
54+
let mut visitor = MessageExtractor(None);
55+
event.record(&mut visitor);
56+
visitor.0
57+
}

0 commit comments

Comments
 (0)