diff options
Diffstat (limited to 'src/pipeline/mod.rs')
| -rw-r--r-- | src/pipeline/mod.rs | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 3e63a69..5bc7cdb 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -1,5 +1,5 @@ -pub mod publish; pub mod dispatch; +pub mod publish; mod steps; use std::path::PathBuf; @@ -7,9 +7,9 @@ use std::sync::Arc; use std::time::Duration; use crate::config::Config; -use crate::db::{self, builds, Db, Pkgbase}; -use crate::db::model::*; +use crate::db::model::{BuildState, CandidateRow, ReleaseRow, StepState}; use crate::db::SnapshotRow; +use crate::db::{self, builds, Db, Pkgbase}; use crate::error::{Error, Missing, Result}; use crate::sandbox::{Sandbox, SandboxBackend}; @@ -103,26 +103,17 @@ pub struct Ctx { impl Ctx { pub fn new(cfg: &Config, db: &Db, build_id: &str) -> Result<Self> { - let build = builds::get(db, build_id)? - .ok_or_else(|| Error::not_found(Missing::Build(build_id.to_string())))?; - let pb = db::get_pkgbase_by_id(db, build.pkgbase_id)? - .ok_or_else(|| Error::not_found("pkgbase for build"))?; - let src = match build.candidate_id { - Some(cid) => { - let c = crate::review::reads::candidate(db, cid)? - .ok_or_else(|| Error::not_found("candidate for build"))?; - let snap = db::snapshot_by_id(db, c.snapshot_id)? - .ok_or_else(|| Error::not_found("snapshot for candidate"))?; - SourceIdentity::from_candidate(&c, &snap) - } - None => { - let rid = build - .release_id - .ok_or_else(|| Error::invalid("build has neither candidate nor release"))?; - let r = db::release_by_id(db, rid)? - .ok_or_else(|| Error::not_found("release for rebuild"))?; - SourceIdentity::from_release(&r) - } + let build = builds::get(db, build_id)?.ok_or_else(|| Error::not_found(Missing::Build(build_id.to_string())))?; + let pb = db::get_pkgbase_by_id(db, build.pkgbase_id)?.ok_or_else(|| Error::not_found("pkgbase for build"))?; + let src = if let Some(cid) = build.candidate_id { + let c = crate::review::reads::candidate(db, cid)?.ok_or_else(|| Error::not_found("candidate for build"))?; + let snap = + db::snapshot_by_id(db, c.snapshot_id)?.ok_or_else(|| Error::not_found("snapshot for candidate"))?; + SourceIdentity::from_candidate(&c, &snap) + } else { + let rid = build.release_id.ok_or_else(|| Error::invalid("build has neither candidate nor release"))?; + let r = db::release_by_id(db, rid)?.ok_or_else(|| Error::not_found("release for rebuild"))?; + SourceIdentity::from_release(&r) }; let attempt = build.attempt; let profile = build.build_profile.clone(); @@ -231,20 +222,13 @@ fn run_with_impl(ctx: &Ctx) -> Result<Outcome> { Err(e) => { let transient = e.is_transient(); builds::finish_step(&ctx.db, &ctx.build.id, step, StepState::Failed, None, Some(&e.to_string()))?; - builds::set_state( - &ctx.db, - &ctx.build.id, - BuildState::Failed, - Some(&format!("{step}: {e}")), - )?; + builds::set_state(&ctx.db, &ctx.build.id, BuildState::Failed, Some(&format!("{step}: {e}")))?; ctx.log_line(&format!("!! {step} failed: {e}")); return Ok(Outcome::Failed { step: step.to_string(), error: e.to_string(), transient }); } } } - let release_id = ctx - .release_id() - .ok_or_else(|| Error::other("publish produced no release"))?; + let release_id = ctx.release_id().ok_or_else(|| Error::other("publish produced no release"))?; builds::set_state(&ctx.db, &ctx.build.id, BuildState::Succeeded, None)?; db::audit_system( &ctx.db.writer, @@ -263,8 +247,7 @@ impl Ctx { } pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result<String> { - let pb = db::get_pkgbase_by_id(db, c.pkgbase_id)? - .ok_or_else(|| Error::not_found("pkgbase"))?; + let pb = db::get_pkgbase_by_id(db, c.pkgbase_id)?.ok_or_else(|| Error::not_found("pkgbase"))?; let world = publish::index_world(db)?; let world_hash = crate::hash::canonical_json(&world)?; let id = builds::build_id(&pb.name, &c.identity_hash, &world_hash, &cfg.build_profile); @@ -274,19 +257,21 @@ pub fn enqueue_for_candidate(cfg: &Config, db: &Db, c: &CandidateRow) -> Result< } pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result<String> { - let pb = db::get_pkgbase(db, pkgbase)? - .ok_or_else(|| Error::not_found(Missing::Pkgbase(pkgbase.to_string())))?; + let pb = db::get_pkgbase(db, pkgbase)?.ok_or_else(|| Error::not_found(Missing::Pkgbase(pkgbase.to_string())))?; let rel = db::accepted_release(db, pkgbase)? .ok_or_else(|| Error::invalid(format!("{pkgbase} has no accepted release")))?; let identity = format!( "sha256:{}", - crate::hash::hex(crate::hash::canonical_json(&serde_json::json!({ - "aur_commit": rel.aur_commit, - "recipe_hash": rel.recipe_hash, - "upstream_pins": rel.pins(), - "source_digests": rel.digests(), - "requested": "manual_rebuild", - }))?.as_bytes()) + crate::hash::hex( + crate::hash::canonical_json(&serde_json::json!({ + "aur_commit": rel.aur_commit, + "recipe_hash": rel.recipe_hash, + "upstream_pins": rel.pins(), + "source_digests": rel.digests(), + "requested": "manual_rebuild", + }))? + .as_bytes() + ) ); let world = publish::index_world(db)?; let world_hash = crate::hash::canonical_json(&world)?; |
