Publish evaluation erports

This commit is contained in:
Graham Christensen 2019-04-13 22:17:11 -04:00
parent d297515ee5
commit 289dba8891
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
4 changed files with 91 additions and 32 deletions

View file

@ -1,9 +1,8 @@
use ofborg::checkout::CachedProjectCo;
use ofborg::commitstatus::CommitStatus;
use ofborg::evalchecker::EvalChecker;
use ofborg::message::buildjob::BuildJob;
use std::path::Path;
use tasks::eval::{EvaluationStrategy, StepResult};
use tasks::eval::{EvaluationComplete, EvaluationStrategy, StepResult};
#[derive(Default)]
pub struct GenericStrategy {}
@ -40,7 +39,7 @@ impl EvaluationStrategy for GenericStrategy {
&mut self,
_co: &Path,
_status: &mut CommitStatus,
) -> StepResult<Vec<BuildJob>> {
Ok(vec![])
) -> StepResult<EvaluationComplete> {
Ok(Default::default())
}
}

View file

@ -4,6 +4,7 @@ mod nixpkgs;
pub use self::nixpkgs::NixpkgsStrategy;
mod generic;
pub use self::generic::GenericStrategy;
use hubcaps::checks::CheckRunOptions;
use ofborg::checkout::CachedProjectCo;
use ofborg::commitstatus::CommitStatus;
use ofborg::evalchecker::EvalChecker;
@ -12,6 +13,7 @@ use std::path::Path;
pub trait EvaluationStrategy {
fn pre_clone(&mut self) -> StepResult<()>;
fn on_target_branch(&mut self, co: &Path, status: &mut CommitStatus) -> StepResult<()>;
fn after_fetch(&mut self, co: &CachedProjectCo) -> StepResult<()>;
fn merge_conflict(&mut self);
@ -21,11 +23,17 @@ pub trait EvaluationStrategy {
&mut self,
co: &Path,
status: &mut CommitStatus,
) -> StepResult<Vec<BuildJob>>;
) -> StepResult<EvaluationComplete>;
}
pub type StepResult<T> = Result<T, Error>;
#[derive(Default)]
pub struct EvaluationComplete {
pub builds: Vec<BuildJob>,
pub checks: Vec<CheckRunOptions>,
}
#[derive(Debug)]
pub enum Error {
Fail(String),

View file

@ -1,6 +1,7 @@
use crate::maintainers;
use crate::maintainers::ImpactedMaintainers;
use crate::nixenv::HydraNixEnv;
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use hubcaps::gists::Gists;
use hubcaps::issues::{Issue, IssueRef};
use hubcaps::repositories::Repository;
@ -15,7 +16,9 @@ use ofborg::nix::Nix;
use ofborg::outpathdiff::{OutPathDiff, PackageArch};
use ofborg::tagger::{MaintainerPRTagger, PathsTagger, RebuildTagger};
use ofborg::tagger::{PkgsAddedRemovedTagger, StdenvTagger};
use ofborg::tasks::eval::{stdenvs::Stdenvs, Error, EvaluationStrategy, StepResult};
use ofborg::tasks::eval::{
stdenvs::Stdenvs, Error, EvaluationComplete, EvaluationStrategy, StepResult,
};
use ofborg::tasks::evaluate::update_labels;
use std::collections::HashMap;
use std::path::Path;
@ -160,6 +163,32 @@ impl<'a> NixpkgsStrategy<'a> {
}
}
fn performance_stats(&self) -> Vec<CheckRunOptions> {
if let Some(ref rebuildsniff) = self.outpath_diff {
if let Some(report) = rebuildsniff.performance_diff() {
return vec![CheckRunOptions {
name: "Evaluation Performance Report".to_owned(),
actions: None,
completed_at: None,
started_at: None,
conclusion: Some(Conclusion::Success),
status: Some(CheckRunState::Completed),
details_url: None,
external_id: None,
head_sha: self.job.pr.head_sha.clone(),
output: Some(Output {
title: "Evaluator Performance Report".to_string(),
summary: "".to_string(),
text: Some(report.markdown()),
annotations: None,
images: None,
}),
}];
}
}
vec![]
}
fn update_new_package_labels(&self) {
if let Some(ref rebuildsniff) = self.outpath_diff {
if let Some((removed, added)) = rebuildsniff.package_diff() {
@ -479,7 +508,7 @@ impl<'a> EvaluationStrategy for NixpkgsStrategy<'a> {
&mut self,
dir: &Path,
status: &mut CommitStatus,
) -> StepResult<Vec<BuildJob>> {
) -> StepResult<EvaluationComplete> {
self.update_stdenv_labels();
status.set_with_description(
@ -489,8 +518,10 @@ impl<'a> EvaluationStrategy for NixpkgsStrategy<'a> {
self.update_new_package_labels();
self.update_rebuild_labels(&dir, status);
let checks = self.performance_stats();
self.check_meta_queue_builds(&dir)
let builds = self.check_meta_queue_builds(&dir)?;
Ok(EvaluationComplete { builds, checks })
}
}

View file

@ -4,6 +4,7 @@ extern crate env_logger;
extern crate uuid;
use amqp::protocol::basic::{BasicProperties, Deliver};
use hubcaps;
use hubcaps::checks::CheckRunOptions;
use hubcaps::gists::Gists;
use hubcaps::issues::Issue;
use ofborg::acl::ACL;
@ -331,30 +332,9 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
let ret = evaluation_strategy
.all_evaluations_passed(&Path::new(&refpath), &mut overall_status);
match ret {
Ok(builds) => {
info!(
"Scheduling build jobs {:#?} on arches {:#?}",
builds, auto_schedule_build_archs
);
for buildjob in builds {
for arch in auto_schedule_build_archs.iter() {
let (exchange, routingkey) = arch.as_build_destination();
response.push(worker::publish_serde_action(
exchange, routingkey, &buildjob,
));
}
response.push(worker::publish_serde_action(
Some("build-results".to_string()),
None,
&buildjob::QueuedBuildJobs {
job: buildjob,
architectures: auto_schedule_build_archs
.iter()
.map(|arch| arch.to_string())
.collect(),
},
));
}
Ok(complete) => {
send_check_statuses(complete.checks, &repo);
response.extend(schedule_builds(complete.builds, auto_schedule_build_archs));
}
Err(e) => {
info!("Failed after all the evaluations passed");
@ -382,6 +362,47 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
}
}
fn send_check_statuses(checks: Vec<CheckRunOptions>, repo: &hubcaps::repositories::Repository) {
for check in checks {
match repo.checkruns().create(&check) {
Ok(_) => info!("Sent check update"),
Err(e) => info!("Failed to send check update: {:?}", e),
}
}
}
fn schedule_builds(
builds: Vec<buildjob::BuildJob>,
auto_schedule_build_archs: Vec<systems::System>,
) -> Vec<worker::Action> {
let mut response = vec![];
info!(
"Scheduling build jobs {:#?} on arches {:#?}",
builds, auto_schedule_build_archs
);
for buildjob in builds {
for arch in auto_schedule_build_archs.iter() {
let (exchange, routingkey) = arch.as_build_destination();
response.push(worker::publish_serde_action(
exchange, routingkey, &buildjob,
));
}
response.push(worker::publish_serde_action(
Some("build-results".to_string()),
None,
&buildjob::QueuedBuildJobs {
job: buildjob,
architectures: auto_schedule_build_archs
.iter()
.map(|arch| arch.to_string())
.collect(),
},
));
}
response
}
pub fn make_gist<'a>(
gists: &hubcaps::gists::Gists<'a>,
name: &str,