Skip to content

Commit 692b91a

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 fb9b128 commit 692b91a

File tree

8 files changed

+58
-70
lines changed

8 files changed

+58
-70
lines changed

Cargo.lock

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

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

obs-commander-tests/src/lib.rs

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

315315
let arch_1 = build_info
316316
.enabled_repos
317-
.get(&RepoArch {
318-
repo: TEST_REPO.to_owned(),
319-
arch: TEST_ARCH_1.to_owned(),
320-
})
317+
.iter()
318+
.find(|e| e.repo_arch.repo == TEST_REPO && e.repo_arch.arch == TEST_ARCH_1)
321319
.unwrap();
322320

323321
if test == DputTest::Rebuild {
@@ -327,10 +325,8 @@ pub async fn test_dput<C: TestContext>(
327325

328326
let arch_2 = build_info
329327
.enabled_repos
330-
.get(&RepoArch {
331-
repo: TEST_REPO.to_owned(),
332-
arch: TEST_ARCH_2.to_owned(),
333-
})
328+
.iter()
329+
.find(|e| e.repo_arch.repo == TEST_REPO && e.repo_arch.arch == TEST_ARCH_2)
334330
.unwrap();
335331
assert_none!(arch_2.prev_endtime_for_commit);
336332
}

obs-commander/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open-build-service-api.workspace = true
1919
reqwest = "0.12"
2020
rfc822-like = "0.2"
2121
serde.workspace = true
22-
serde_yaml.workspace = true
22+
serde_json = "1.0.140"
2323
tempfile.workspace = true
2424
thiserror.workspace = true
2525
tokio.workspace = true

obs-commander/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,17 +11,14 @@ use tracing::{debug, info, instrument};
1111
use crate::{
1212
artifacts::{ArtifactDirectory, 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
prune::prune_branch,
2017
retry_request,
2118
upload::ObsDscUploader,
2219
};
2320

24-
pub const DEFAULT_BUILD_INFO: &str = "build-info.yml";
21+
pub const DEFAULT_BUILD_INFO: &str = "build-info.json";
2522
pub const DEFAULT_BUILD_LOG: &str = "build.log";
2623

2724
// Our flags can all take explicit values, because it makes it easier to
@@ -102,7 +99,7 @@ pub struct ObsBuildInfo {
10299
pub rev: Option<String>,
103100
pub srcmd5: Option<String>,
104101
pub is_branched: bool,
105-
pub enabled_repos: HashMap<RepoArch, CommitBuildInfo>,
102+
pub enabled_repos: Vec<EnabledRepo>,
106103
}
107104

108105
impl ObsBuildInfo {
@@ -112,7 +109,7 @@ impl ObsBuildInfo {
112109
.save_with(path, async |file| {
113110
let mut file = file.into_std().await;
114111
tokio::task::spawn_blocking(move || {
115-
serde_yaml::to_writer(&mut file, &self)
112+
serde_json::to_writer(&mut file, &self)
116113
.wrap_err("Failed to write build info file")
117114
})
118115
.await??;
@@ -165,7 +162,7 @@ impl Actions {
165162
rev: None,
166163
srcmd5: None,
167164
is_branched,
168-
enabled_repos: HashMap::new(),
165+
enabled_repos: vec![],
169166
};
170167
debug!("Saving initial build info: {:?}", build_info);
171168
build_info
@@ -362,7 +359,7 @@ impl Actions {
362359
artifacts.read_string(&args.build_info).await?
363360
};
364361

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

368365
if build_info.is_branched {

obs-commander/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(

obs-gitlab-runner/src/handler.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ mod tests {
447447
use claims::*;
448448
use gitlab_runner::{GitlabLayer, Runner, RunnerBuilder};
449449
use gitlab_runner_mock::*;
450-
use obs_commander::build_meta::{CommitBuildInfo, RepoArch};
450+
use obs_commander::build_meta::{EnabledRepo, RepoArch};
451451
use obs_commander_test_support::*;
452452
use obs_commander_tests::*;
453453
use rstest::rstest;
@@ -867,10 +867,10 @@ mod tests {
867867

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

870-
for repo in build_info.enabled_repos.keys() {
870+
for enabled in &build_info.enabled_repos {
871871
let monitor_job_name = format!(
872872
"{}-{}-{}",
873-
DEFAULT_PIPELINE_JOB_PREFIX, TEST_REPO, &repo.arch
873+
DEFAULT_PIPELINE_JOB_PREFIX, TEST_REPO, &enabled.repo_arch.arch
874874
);
875875

876876
let monitor_map = pipeline_yaml
@@ -944,7 +944,7 @@ mod tests {
944944
context,
945945
dput.clone(),
946946
build_info,
947-
repo,
947+
&enabled.repo_arch,
948948
&script,
949949
success,
950950
dput_test,
@@ -1129,16 +1129,14 @@ mod tests {
11291129
rev: Some("1".to_owned()),
11301130
srcmd5: Some("abc".to_owned()),
11311131
is_branched: false,
1132-
enabled_repos: [(
1133-
RepoArch {
1132+
enabled_repos: vec![EnabledRepo {
1133+
repo_arch: RepoArch {
11341134
repo: TEST_REPO.to_owned(),
11351135
arch: TEST_ARCH_1.to_owned(),
11361136
},
1137-
CommitBuildInfo {
1138-
prev_endtime_for_commit: None,
1139-
},
1140-
)]
1141-
.into(),
1137+
1138+
prev_endtime_for_commit: None,
1139+
}],
11421140
};
11431141

11441142
let build_info = context

obs-gitlab-runner/src/pipeline.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use color_eyre::eyre::{Context, Result};
4-
use obs_commander::build_meta::{CommitBuildInfo, RepoArch};
4+
use obs_commander::build_meta::{EnabledRepo, RepoArch};
55
use serde::Serialize;
66
use tracing::instrument;
77

@@ -58,7 +58,7 @@ pub fn generate_monitor_pipeline(
5858
package: &str,
5959
rev: &str,
6060
srcmd5: &str,
61-
enabled_repos: &HashMap<RepoArch, CommitBuildInfo>,
61+
enabled_repos: &[EnabledRepo],
6262
options: GeneratePipelineOptions,
6363
) -> Result<String> {
6464
let rules: Option<serde_yaml::Sequence> = options
@@ -69,7 +69,9 @@ pub fn generate_monitor_pipeline(
6969
.wrap_err("Failed to parse provided rules")?;
7070

7171
let mut jobs = HashMap::new();
72-
for (RepoArch { repo, arch }, info) in enabled_repos {
72+
for enabled in enabled_repos {
73+
let RepoArch { repo, arch } = &enabled.repo_arch;
74+
7375
let mut script = vec![];
7476
let mut artifact_paths = vec![];
7577

@@ -85,7 +87,7 @@ pub fn generate_monitor_pipeline(
8587
("srcmd5", srcmd5.to_owned()),
8688
("build-log-out", options.build_log_out.clone()),
8789
];
88-
if let Some(endtime) = &info.prev_endtime_for_commit {
90+
if let Some(endtime) = &enabled.prev_endtime_for_commit {
8991
monitor_args.push(("prev-endtime-for-commit", endtime.to_string()));
9092
}
9193
monitor_args.extend_from_slice(&common_args);

0 commit comments

Comments
 (0)