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
63 changes: 58 additions & 5 deletions Cargo.lock

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

52 changes: 17 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
[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_json = "1.0.140"
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" }
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ In order to connect to OBS, three variables must be set (generally within the
```bash
dput PROJECT DSC_FILE
[--branch-to BRANCHED_PROJECT]
[--build-info-out BUILD_INFO_FILE=build-info.yml]
[--build-info-out BUILD_INFO_FILE=build-info.json]
[--rebuild-if-unchanged]
```

Expand All @@ -92,7 +92,7 @@ within, will be removed.

Metadata information on the uploaded revision, such as the revision number,
project name, and package name, will be saved into the file specified by
`--build-info-out` (default is `build-info.yml`). This file is **required** by
`--build-info-out` (default is `build-info.json`). This file is **required** by
the `generate-monitor` and `prune` steps. Do note that, if `--branch-to` is
given, the file will be written *immediately* after the branch takes place (i.e.
before the upload); that way, if the upload fails, the branched project can still
Expand All @@ -109,7 +109,7 @@ testing builds on MRs; you can create an OBS branch named after the MR's Git
branch, and then builds can take place there without interfering with your main
projects.

##### `--build-info-out BUILD_INFO_FILE=build-info.yml`
##### `--build-info-out BUILD_INFO_FILE=build-info.json`

Changes the filename that the build info will be written to.

Expand All @@ -130,7 +130,7 @@ operation, there will *always* be a change to upload.
generate-monitor RUNNER_TAG
[--rules RULES]
[--download-build-results-to BUILD_RESULTS_DIR]
[--build-info BUILD_INFO_FILE=build-info.yml]
[--build-info BUILD_INFO_FILE=build-info.json]
[--pipeline-out PIPELINE_FILE=obs.yml]
[--job-prefix MONITOR_JOB_PREFIX=obs]
[--job-timeout MONITOR_JOB_TIMEOUT]
Expand Down Expand Up @@ -199,7 +199,7 @@ dput-and-generate:
After a monitoring job completes, download the build results from OBS to the
given `BUILD_RESULTS_DIR`, and upload it as a GitLab build artifact..

##### `--build-info BUILD_INFO_FILE=build-info.yml`
##### `--build-info BUILD_INFO_FILE=build-info.json`

Specifies the name of the build info file to read. In particular, if a different
build info filename was used with `dput` via
Expand Down Expand Up @@ -233,7 +233,7 @@ Changes the filename each monitoring job will save the build log into.

```bash
prune
[--build-info BUILD_INFO_FILE=build-info.yml]
[--build-info BUILD_INFO_FILE=build-info.json]
[--ignore-missing-build-info]
[--only-if-job-unsuccessful]
```
Expand All @@ -242,7 +242,7 @@ If a branch occurred, deletes the branched package and, if now empty, project,
using the information from the build info file. (If no branching occurred, this
does nothing.)

##### `--build-info BUILD_INFO_FILE=build-info.yml`
##### `--build-info BUILD_INFO_FILE=build-info.json`

Specifies the name of the build info file to read. In particular, if a different
build info filename was used with `dput` via
Expand Down
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_json.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

69 changes: 59 additions & 10 deletions src/actions.rs → obo-core/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, io::SeekFrom};
use std::io::SeekFrom;

use camino::{Utf8Path, Utf8PathBuf};
use clap::{ArgAction, Parser};
Expand All @@ -11,18 +11,15 @@ use tracing::{debug, instrument};
use crate::{
artifacts::{ArtifactDirectory, ArtifactReader, ArtifactWriter, MissingArtifactToNone},
binaries::download_binaries,
build_meta::{
BuildHistoryRetrieval, BuildMeta, BuildMetaOptions, CommitBuildInfo, DisabledRepos,
RepoArch,
},
build_meta::{BuildHistoryRetrieval, BuildMeta, BuildMetaOptions, DisabledRepos, EnabledRepo},
monitor::{MonitoredPackage, ObsMonitor, PackageCompletion, PackageMonitoringOptions},
outputln,
prune::prune_branch,
retry_request,
upload::ObsDscUploader,
};

pub const DEFAULT_BUILD_INFO: &str = "build-info.yml";
pub const DEFAULT_BUILD_INFO: &str = "build-info.json";
pub const DEFAULT_BUILD_LOG: &str = "build.log";

// Our flags can all take explicit values, because it makes it easier to
Expand All @@ -42,6 +39,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 +92,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 +124,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 All @@ -103,7 +152,7 @@ pub struct ObsBuildInfo {
pub rev: Option<String>,
pub srcmd5: Option<String>,
pub is_branched: bool,
pub enabled_repos: HashMap<RepoArch, CommitBuildInfo>,
pub enabled_repos: Vec<EnabledRepo>,
}

impl ObsBuildInfo {
Expand All @@ -112,7 +161,7 @@ impl ObsBuildInfo {
artifacts
.save_with(path, async |file: &mut ArtifactWriter| {
let data =
serde_yaml::to_string(&self).wrap_err("Failed to serialize build info")?;
serde_json::to_string(&self).wrap_err("Failed to serialize build info")?;
file.write_all(data.as_bytes())
.await
.wrap_err("Failed to write build info file")?;
Expand Down Expand Up @@ -165,7 +214,7 @@ impl Actions {
rev: None,
srcmd5: None,
is_branched,
enabled_repos: HashMap::new(),
enabled_repos: vec![],
};
debug!("Saving initial build info: {:?}", build_info);
build_info
Expand Down Expand Up @@ -362,7 +411,7 @@ impl Actions {
artifacts.read_string(&args.build_info).await?
};

let build_info: ObsBuildInfo = serde_yaml::from_str(&build_info_data)
let build_info: ObsBuildInfo = serde_json::from_str(&build_info_data)
.wrap_err("Failed to parse provided build info file")?;

if build_info.is_branched {
Expand Down
File renamed without changes.
Loading
Loading