Skip to content

Commit 1b177cb

Browse files
committed
Rework the build-info format to be JSON
External services like GH Actions can read JSON but *not* YAML, and the previous format couldn't simply be written "as JSON" because it relied on having structs as keys. This tweaks the format to be JSON-friendly and uses actual JSON files.
1 parent 9d78d16 commit 1b177cb

File tree

10 files changed

+63
-72
lines changed

10 files changed

+63
-72
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ open-build-service-mock = { git = "https://github.com/collabora/open-build-servi
2121
# open-build-service-mock = { path = "../open-build-service-rs/open-build-service-api" }
2222
rstest = "0.26"
2323
serde = "1.0"
24+
serde_json = "1.0.140"
2425
serde_yaml = "0.9"
2526
shell-words = "1.1"
2627
tempfile = "3.20"

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ In order to connect to OBS, three variables must be set (generally within the
8282
```bash
8383
dput PROJECT DSC_FILE
8484
[--branch-to BRANCHED_PROJECT]
85-
[--build-info-out BUILD_INFO_FILE=build-info.yml]
85+
[--build-info-out BUILD_INFO_FILE=build-info.json]
8686
[--rebuild-if-unchanged]
8787
```
8888

@@ -92,7 +92,7 @@ within, will be removed.
9292

9393
Metadata information on the uploaded revision, such as the revision number,
9494
project name, and package name, will be saved into the file specified by
95-
`--build-info-out` (default is `build-info.yml`). This file is **required** by
95+
`--build-info-out` (default is `build-info.json`). This file is **required** by
9696
the `generate-monitor` and `prune` steps. Do note that, if `--branch-to` is
9797
given, the file will be written *immediately* after the branch takes place (i.e.
9898
before the upload); that way, if the upload fails, the branched project can still
@@ -109,7 +109,7 @@ testing builds on MRs; you can create an OBS branch named after the MR's Git
109109
branch, and then builds can take place there without interfering with your main
110110
projects.
111111
112-
##### `--build-info-out BUILD_INFO_FILE=build-info.yml`
112+
##### `--build-info-out BUILD_INFO_FILE=build-info.json`
113113
114114
Changes the filename that the build info will be written to.
115115
@@ -130,7 +130,7 @@ operation, there will *always* be a change to upload.
130130
generate-monitor RUNNER_TAG
131131
[--rules RULES]
132132
[--download-build-results-to BUILD_RESULTS_DIR]
133-
[--build-info BUILD_INFO_FILE=build-info.yml]
133+
[--build-info BUILD_INFO_FILE=build-info.json]
134134
[--pipeline-out PIPELINE_FILE=obs.yml]
135135
[--job-prefix MONITOR_JOB_PREFIX=obs]
136136
[--job-timeout MONITOR_JOB_TIMEOUT]
@@ -199,7 +199,7 @@ dput-and-generate:
199199
After a monitoring job completes, download the build results from OBS to the
200200
given `BUILD_RESULTS_DIR`, and upload it as a GitLab build artifact..
201201

202-
##### `--build-info BUILD_INFO_FILE=build-info.yml`
202+
##### `--build-info BUILD_INFO_FILE=build-info.json`
203203

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

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

245-
##### `--build-info BUILD_INFO_FILE=build-info.yml`
245+
##### `--build-info BUILD_INFO_FILE=build-info.json`
246246

247247
Specifies the name of the build info file to read. In particular, if a different
248248
build info filename was used with `dput` via

obo-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ open-build-service-api.workspace = true
2020
reqwest = "0.12"
2121
rfc822-like = "0.2"
2222
serde.workspace = true
23-
serde_yaml.workspace = true
23+
serde_json.workspace = true
2424
shell-words.workspace = true
2525
tempfile.workspace = true
2626
thiserror.workspace = true

obo-core/src/actions.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, io::SeekFrom};
1+
use std::io::SeekFrom;
22

33
use camino::{Utf8Path, Utf8PathBuf};
44
use clap::{ArgAction, Parser};
@@ -11,18 +11,15 @@ use tracing::{debug, instrument};
1111
use crate::{
1212
artifacts::{ArtifactDirectory, ArtifactReader, ArtifactWriter, MissingArtifactToNone},
1313
binaries::download_binaries,
14-
build_meta::{
15-
BuildHistoryRetrieval, BuildMeta, BuildMetaOptions, CommitBuildInfo, DisabledRepos,
16-
RepoArch,
17-
},
14+
build_meta::{BuildHistoryRetrieval, BuildMeta, BuildMetaOptions, DisabledRepos, EnabledRepo},
1815
monitor::{MonitoredPackage, ObsMonitor, PackageCompletion, PackageMonitoringOptions},
1916
outputln,
2017
prune::prune_branch,
2118
retry_request,
2219
upload::ObsDscUploader,
2320
};
2421

25-
pub const DEFAULT_BUILD_INFO: &str = "build-info.yml";
22+
pub const DEFAULT_BUILD_INFO: &str = "build-info.json";
2623
pub const DEFAULT_BUILD_LOG: &str = "build.log";
2724

2825
// Our flags can all take explicit values, because it makes it easier to
@@ -155,7 +152,7 @@ pub struct ObsBuildInfo {
155152
pub rev: Option<String>,
156153
pub srcmd5: Option<String>,
157154
pub is_branched: bool,
158-
pub enabled_repos: HashMap<RepoArch, CommitBuildInfo>,
155+
pub enabled_repos: Vec<EnabledRepo>,
159156
}
160157

161158
impl ObsBuildInfo {
@@ -164,7 +161,7 @@ impl ObsBuildInfo {
164161
artifacts
165162
.save_with(path, async |file: &mut ArtifactWriter| {
166163
let data =
167-
serde_yaml::to_string(&self).wrap_err("Failed to serialize build info")?;
164+
serde_json::to_string(&self).wrap_err("Failed to serialize build info")?;
168165
file.write_all(data.as_bytes())
169166
.await
170167
.wrap_err("Failed to write build info file")?;
@@ -217,7 +214,7 @@ impl Actions {
217214
rev: None,
218215
srcmd5: None,
219216
is_branched,
220-
enabled_repos: HashMap::new(),
217+
enabled_repos: vec![],
221218
};
222219
debug!("Saving initial build info: {:?}", build_info);
223220
build_info
@@ -414,7 +411,7 @@ impl Actions {
414411
artifacts.read_string(&args.build_info).await?
415412
};
416413

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

420417
if build_info.is_branched {

obo-core/src/build_meta.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ pub struct RepoArch {
1414
}
1515

1616
#[derive(Deserialize, Serialize, Debug, Clone)]
17-
pub struct CommitBuildInfo {
17+
pub struct EnabledRepo {
18+
#[serde(flatten)]
19+
pub repo_arch: RepoArch,
1820
pub prev_endtime_for_commit: Option<u64>,
1921
}
2022

@@ -237,26 +239,19 @@ impl BuildMeta {
237239
Ok(())
238240
}
239241

240-
pub fn get_commit_build_info(&self, srcmd5: &str) -> HashMap<RepoArch, CommitBuildInfo> {
241-
let mut repos = HashMap::new();
242-
243-
for (repo, jobhist) in &self.repos {
244-
let prev_endtime_for_commit = jobhist
245-
.jobhist
246-
.iter()
247-
.filter(|e| e.srcmd5 == srcmd5)
248-
.next_back()
249-
.map(|e| e.endtime);
250-
251-
repos.insert(
252-
repo.clone(),
253-
CommitBuildInfo {
254-
prev_endtime_for_commit,
255-
},
256-
);
257-
}
258-
259-
repos
242+
pub fn get_commit_build_info(&self, srcmd5: &str) -> Vec<EnabledRepo> {
243+
self.repos
244+
.iter()
245+
.map(|(repo, jobhist)| EnabledRepo {
246+
repo_arch: repo.clone(),
247+
prev_endtime_for_commit: jobhist
248+
.jobhist
249+
.iter()
250+
.filter(|e| e.srcmd5 == srcmd5)
251+
.next_back()
252+
.map(|e| e.endtime),
253+
})
254+
.collect()
260255
}
261256
}
262257

@@ -360,10 +355,10 @@ mod tests {
360355

361356
let build_info = meta.get_commit_build_info(&srcmd5_1);
362357

363-
let arch_1 = assert_some!(build_info.get(&repo_arch_1));
358+
let arch_1 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_1));
364359
assert_some_eq!(arch_1.prev_endtime_for_commit, endtime_1);
365360

366-
let arch_2 = assert_some!(build_info.get(&repo_arch_2));
361+
let arch_2 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_2));
367362
assert_none!(arch_2.prev_endtime_for_commit);
368363

369364
let meta = assert_ok!(
@@ -385,9 +380,9 @@ mod tests {
385380

386381
let build_info = meta.get_commit_build_info(&srcmd5_1);
387382

388-
let arch_1 = assert_some!(build_info.get(&repo_arch_1));
383+
let arch_1 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_1));
389384
assert_none!(arch_1.prev_endtime_for_commit);
390-
let arch_2 = assert_some!(build_info.get(&repo_arch_2));
385+
let arch_2 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_2));
391386
assert_none!(arch_2.prev_endtime_for_commit);
392387

393388
assert!(meta.repos.contains_key(&repo_arch_2));
@@ -431,7 +426,7 @@ mod tests {
431426

432427
let build_info = meta.get_commit_build_info(&srcmd5_2);
433428

434-
let arch_1 = assert_some!(build_info.get(&repo_arch_2));
429+
let arch_1 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_2));
435430
assert_some_eq!(arch_1.prev_endtime_for_commit, endtime_2);
436431

437432
mock.add_job_history(
@@ -465,13 +460,13 @@ mod tests {
465460

466461
let build_info = meta.get_commit_build_info(&srcmd5_1);
467462

468-
let arch_2 = assert_some!(build_info.get(&repo_arch_2));
463+
let arch_2 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_2));
469464
assert_some_eq!(arch_2.prev_endtime_for_commit, endtime_1);
470465

471466
meta.clear_stored_history();
472467

473468
let build_info = meta.get_commit_build_info(&srcmd5_1);
474-
let arch_2 = assert_some!(build_info.get(&repo_arch_2));
469+
let arch_2 = assert_some!(build_info.iter().find(|e| e.repo_arch == repo_arch_2));
475470
assert_none!(arch_2.prev_endtime_for_commit);
476471

477472
mock.set_package_build_status(

obo-tests/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,8 @@ pub async fn test_dput<C: TestContext>(
323323

324324
let arch_1 = build_info
325325
.enabled_repos
326-
.get(&RepoArch {
327-
repo: TEST_REPO.to_owned(),
328-
arch: TEST_ARCH_1.to_owned(),
329-
})
326+
.iter()
327+
.find(|e| e.repo_arch.repo == TEST_REPO && e.repo_arch.arch == TEST_ARCH_1)
330328
.unwrap();
331329

332330
if test == DputTest::Rebuild {
@@ -336,10 +334,8 @@ pub async fn test_dput<C: TestContext>(
336334

337335
let arch_2 = build_info
338336
.enabled_repos
339-
.get(&RepoArch {
340-
repo: TEST_REPO.to_owned(),
341-
arch: TEST_ARCH_2.to_owned(),
342-
})
337+
.iter()
338+
.find(|e| e.repo_arch.repo == TEST_REPO && e.repo_arch.arch == TEST_ARCH_2)
343339
.unwrap();
344340
assert_none!(arch_2.prev_endtime_for_commit);
345341
}

obs-gitlab-runner/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obo-core = { path = "../obo-core" }
1919
obo-test-support = { path = "../obo-test-support" }
2020
open-build-service-api.workspace = true
2121
serde.workspace = true
22+
serde_json.workspace = true
2223
serde_yaml.workspace = true
2324
shellexpand = "3.1"
2425
shell-words.workspace = true

obs-gitlab-runner/src/handler.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl ObsJobHandler {
228228
};
229229

230230
let build_info_data = artifacts.read_string(&args.build_info).await?;
231-
let build_info: ObsBuildInfo = serde_yaml::from_str(&build_info_data)
231+
let build_info: ObsBuildInfo = serde_json::from_str(&build_info_data)
232232
.wrap_err("Failed to parse provided build info file")?;
233233

234234
let pipeline = generate_monitor_pipeline(
@@ -448,7 +448,7 @@ mod tests {
448448
use claims::*;
449449
use gitlab_runner::{GitlabLayer, Runner, RunnerBuilder};
450450
use gitlab_runner_mock::*;
451-
use obo_core::build_meta::{CommitBuildInfo, RepoArch};
451+
use obo_core::build_meta::{EnabledRepo, RepoArch};
452452
use obo_test_support::*;
453453
use obo_tests::*;
454454
use rstest::rstest;
@@ -868,10 +868,10 @@ mod tests {
868868

869869
assert_eq!(pipeline_map.len(), build_info.enabled_repos.len());
870870

871-
for repo in build_info.enabled_repos.keys() {
871+
for enabled in &build_info.enabled_repos {
872872
let monitor_job_name = format!(
873873
"{}-{}-{}",
874-
DEFAULT_PIPELINE_JOB_PREFIX, TEST_REPO, &repo.arch
874+
DEFAULT_PIPELINE_JOB_PREFIX, TEST_REPO, &enabled.repo_arch.arch
875875
);
876876

877877
let monitor_map = pipeline_yaml
@@ -945,7 +945,7 @@ mod tests {
945945
context,
946946
dput.clone(),
947947
build_info,
948-
repo,
948+
&enabled.repo_arch,
949949
&script,
950950
success,
951951
dput_test,
@@ -1130,23 +1130,21 @@ mod tests {
11301130
rev: Some("1".to_owned()),
11311131
srcmd5: Some("abc".to_owned()),
11321132
is_branched: false,
1133-
enabled_repos: [(
1134-
RepoArch {
1133+
enabled_repos: vec![EnabledRepo {
1134+
repo_arch: RepoArch {
11351135
repo: TEST_REPO.to_owned(),
11361136
arch: TEST_ARCH_1.to_owned(),
11371137
},
1138-
CommitBuildInfo {
1139-
prev_endtime_for_commit: None,
1140-
},
1141-
)]
1142-
.into(),
1138+
1139+
prev_endtime_for_commit: None,
1140+
}],
11431141
};
11441142

11451143
let build_info = context
11461144
.inject_artifacts(
11471145
[(
11481146
DEFAULT_BUILD_INFO.to_owned(),
1149-
serde_yaml::to_string(&build_info).unwrap().into_bytes(),
1147+
serde_json::to_string(&build_info).unwrap().into_bytes(),
11501148
)]
11511149
.into(),
11521150
)

0 commit comments

Comments
 (0)