Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/ofborg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 33258c16c671
Choose a base ref
...
head repository: NixOS/ofborg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 90fda07cf259
Choose a head ref
  • 18 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 30, 2020

  1. nixenv: send stats to a file

    grahamc committed Mar 30, 2020
    Copy the full SHA
    da4a882 View commit details
  2. Copy the full SHA
    b50bc35 View commit details
  3. nixenv: ignore empty lines

    grahamc committed Mar 30, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    NeQuissimus Tim Steinbach
    Copy the full SHA
    13ea5fd View commit details
  4. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    NeQuissimus Tim Steinbach
    Copy the full SHA
    a2bbc8d View commit details
  5. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    NeQuissimus Tim Steinbach
    Copy the full SHA
    9f70ab9 View commit details

Commits on Mar 31, 2020

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    NeQuissimus Tim Steinbach
    Copy the full SHA
    5730914 View commit details
  2. Fixup whitespace

    grahamc committed Mar 31, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    NeQuissimus Tim Steinbach
    Copy the full SHA
    3e51325 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    vcunat Vladimír Čunát
    Copy the full SHA
    0ae112f View commit details
  4. Copy the full SHA
    cf28b41 View commit details
  5. Copy the full SHA
    ea2f7cf View commit details
  6. evaluate task: move evaluation leg work in to another function, and j…

    …ust call it from the consumer implementation
    grahamc committed Mar 31, 2020
    Copy the full SHA
    39af0ae View commit details
  7. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9f383f4 View commit details
  8. Revert "evaluate: start to use error returns"

    This reverts commit 9f383f4.
    grahamc committed Mar 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    be7bc06 View commit details
  9. Copy the full SHA
    0b936ea View commit details
  10. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a8eb174 View commit details
  11. Revert "Revert "commitstatus: return an error if we fail to set a sta…

    …tus""
    
    This reverts commit cf28b41.
    grahamc committed Mar 31, 2020

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    veprbl Dmitry Kalinkin
    Copy the full SHA
    85649b0 View commit details
  12. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    750bc88 View commit details
  13. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    90fda07 View commit details
Showing with 295 additions and 128 deletions.
  1. +25 −5 ofborg/src/commitstatus.rs
  2. +7 −0 ofborg/src/nix.rs
  3. +34 −7 ofborg/src/nixenv.rs
  4. +8 −1 ofborg/src/tasks/eval/mod.rs
  5. +20 −13 ofborg/src/tasks/eval/nixpkgs.rs
  6. +201 −102 ofborg/src/tasks/evaluate.rs
30 changes: 25 additions & 5 deletions ofborg/src/commitstatus.rs
Original file line number Diff line number Diff line change
@@ -36,25 +36,45 @@ impl<'a> CommitStatus<'a> {
self.url = url.unwrap_or_else(|| String::from(""))
}

pub fn set_with_description(&mut self, description: &str, state: hubcaps::statuses::State) {
pub fn set_with_description(
&mut self,
description: &str,
state: hubcaps::statuses::State,
) -> Result<(), CommitStatusError> {
self.set_description(description.to_owned());
self.set(state);
self.set(state)
}

pub fn set_description(&mut self, description: String) {
self.description = description;
}

pub fn set(&self, state: hubcaps::statuses::State) {
pub fn set(&self, state: hubcaps::statuses::State) -> Result<(), CommitStatusError> {
let desc = if self.description.len() >= 140 {
eprintln!(
"Warning: description is over 140 char; truncating: {:?}",
&self.description
);
self.description.chars().take(140).collect()
} else {
self.description.clone()
};

self.api
.create(
self.sha.as_ref(),
&hubcaps::statuses::StatusOptions::builder(state)
.context(self.context.clone())
.description(self.description.clone())
.description(desc)
.target_url(self.url.clone())
.build(),
)
.expect("Failed to mark final status on commit");
.map(|_| ())
.map_err(|e| CommitStatusError::HubcapsError(e))
}
}

#[derive(Debug)]
pub enum CommitStatusError {
HubcapsError(hubcaps::Error),
}
7 changes: 7 additions & 0 deletions ofborg/src/nix.rs
Original file line number Diff line number Diff line change
@@ -349,9 +349,16 @@ fn lines_from_file(file: fs::File) -> Vec<String> {
.lines()
.filter(|line| line.is_ok())
.map(|line| line.unwrap())
.filter(|msg| !is_user_setting_warning(msg))
.collect()
}

pub fn is_user_setting_warning(line: &str) -> bool {
let line = line.trim();
line.starts_with("warning: ignoring the user-specified setting '")
&& line.ends_with("because it is a restricted setting and you are not a trusted user")
}

#[cfg(test)]
mod tests {
fn nix() -> Nix {
41 changes: 34 additions & 7 deletions ofborg/src/nixenv.rs
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@ use ofborg::nix;
use serde_json;
use std::fs;
use std::fs::File;
use std::io::BufReader;
use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;

pub struct HydraNixEnv {
@@ -32,15 +32,28 @@ impl HydraNixEnv {
&self,
) -> Result<(outpathdiff::PackageOutPaths, EvaluationStats), Error> {
self.place_nix()?;
let (status, stdout, mut stderr) = self.run_nix_env();
let (status, stdout, stderr, mut stats) = self.run_nix_env();
self.remove_nix()?;

if status {
let outpaths = outpathdiff::parse_lines(&mut BufReader::new(stdout));
let stats = serde_json::from_reader(&mut stderr).map_err(|err| {
let seek = stderr.seek(SeekFrom::Start(0));

Error::StatsParse(stderr, seek, err)
let evaluation_errors = BufReader::new(stderr)
.lines()
.collect::<Result<Vec<String>, _>>()?
.into_iter()
.filter(|msg| msg.trim().len() > 0)
.filter(|line| !nix::is_user_setting_warning(line))
.collect::<Vec<String>>();

if evaluation_errors.len() > 0 {
return Err(Error::UncleanEvaluation(evaluation_errors));
}

let stats = serde_json::from_reader(&mut stats).map_err(|err| {
let seek = stats.seek(SeekFrom::Start(0));

Error::StatsParse(stats, seek, err)
})?;
Ok((outpaths, stats))
} else {
@@ -59,14 +72,19 @@ impl HydraNixEnv {

fn remove_nix(&self) -> Result<(), std::io::Error> {
fs::remove_file(self.outpath_nix_path())?;
fs::remove_file(self.outpath_stats_path())?;
Ok(())
}

fn outpath_nix_path(&self) -> PathBuf {
self.path.join(".gc-of-borg-outpaths.nix")
}

fn run_nix_env(&self) -> (bool, File, File) {
fn outpath_stats_path(&self) -> PathBuf {
self.path.join(".gc-of-borg-stats.json")
}

fn run_nix_env(&self) -> (bool, File, File, File) {
let check_meta = if self.check_meta { "true" } else { "false" };

let mut cmd = self.nix.safe_command(
@@ -82,14 +100,20 @@ impl HydraNixEnv {
&[],
);
cmd.env("NIX_SHOW_STATS", "1");
self.nix.run_stderr_stdout(cmd)
cmd.env("NIX_SHOW_STATS_PATH", self.outpath_stats_path());

let (status, stdout, stderr) = self.nix.run_stderr_stdout(cmd);
let stats =
File::open(self.outpath_stats_path()).expect("Failed to open stats path, not created?");
return (status, stdout, stderr, stats);
}
}

pub enum Error {
Io(std::io::Error),
CommandFailed(File),
StatsParse(File, Result<u64, std::io::Error>, serde_json::Error),
UncleanEvaluation(Vec<String>),
}

impl From<std::io::Error> for Error {
@@ -115,6 +139,9 @@ impl Error {
),
}
}
Error::UncleanEvaluation(warnings) => {
format!("nix-env did not evaluate cleanly:\n {:#?}", warnings)
}
Error::StatsParse(mut fd, seek, parse_err) => {
let mut buffer = Vec::new();
let read_result = fd.read_to_end(&mut buffer);
9 changes: 8 additions & 1 deletion ofborg/src/tasks/eval/mod.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ mod generic;
pub use self::generic::GenericStrategy;
use hubcaps::checks::CheckRunOptions;
use ofborg::checkout::CachedProjectCo;
use ofborg::commitstatus::CommitStatus;
use ofborg::commitstatus::{CommitStatus, CommitStatusError};
use ofborg::evalchecker::EvalChecker;
use ofborg::message::buildjob::BuildJob;
use std::path::Path;
@@ -36,6 +36,13 @@ pub struct EvaluationComplete {

#[derive(Debug)]
pub enum Error {
CommitStatusWrite(CommitStatusError),
Fail(String),
FailWithGist(String, String, String),
}

impl From<CommitStatusError> for Error {
fn from(e: CommitStatusError) -> Error {
Error::CommitStatusWrite(e)
}
}
33 changes: 20 additions & 13 deletions ofborg/src/tasks/eval/nixpkgs.rs
Original file line number Diff line number Diff line change
@@ -206,14 +206,18 @@ impl<'a> NixpkgsStrategy<'a> {
}
}

fn update_rebuild_labels(&self, dir: &Path, overall_status: &mut CommitStatus) {
fn update_rebuild_labels(
&self,
dir: &Path,
overall_status: &mut CommitStatus,
) -> Result<(), Error> {
if let Some(ref rebuildsniff) = self.outpath_diff {
let mut rebuild_tags = RebuildTagger::new();

if let Some(attrs) = rebuildsniff.calculate_rebuild() {
if !attrs.is_empty() {
overall_status.set_url(self.gist_changed_paths(&attrs));
self.record_impacted_maintainers(&dir, &attrs);
self.record_impacted_maintainers(&dir, &attrs)?;
}

rebuild_tags.parse_attrs(attrs);
@@ -225,6 +229,7 @@ impl<'a> NixpkgsStrategy<'a> {
&rebuild_tags.tags_to_remove(),
);
}
Ok(())
}

fn gist_changed_paths(&self, attrs: &[PackageArch]) -> Option<String> {
@@ -240,7 +245,7 @@ impl<'a> NixpkgsStrategy<'a> {
)
}

fn record_impacted_maintainers(&self, dir: &Path, attrs: &[PackageArch]) {
fn record_impacted_maintainers(&self, dir: &Path, attrs: &[PackageArch]) -> Result<(), Error> {
let changed_attributes = attrs
.iter()
.map(|attr| attr.package.split('.').collect::<Vec<&str>>())
@@ -271,7 +276,7 @@ impl<'a> NixpkgsStrategy<'a> {
String::from("matching changed paths to changed attrs..."),
gist_url,
);
status.set(hubcaps::statuses::State::Success);
status.set(hubcaps::statuses::State::Success)?;

if let Ok(ref maint) = m {
request_reviews(&maint, &self.pull);
@@ -285,6 +290,8 @@ impl<'a> NixpkgsStrategy<'a> {
);
}
}

Ok(())
}

fn check_meta_queue_builds(&self, dir: &Path) -> StepResult<Vec<BuildJob>> {
@@ -296,7 +303,7 @@ impl<'a> NixpkgsStrategy<'a> {
String::from("config.nix: checkMeta = true"),
None,
);
status.set(hubcaps::statuses::State::Pending);
status.set(hubcaps::statuses::State::Pending)?;

let nixenv = HydraNixEnv::new(self.nix.clone(), dir.to_path_buf(), true);
match nixenv.execute_with_stats() {
@@ -310,7 +317,7 @@ impl<'a> NixpkgsStrategy<'a> {
try_build.dedup();

status.set_url(None);
status.set(hubcaps::statuses::State::Success);
status.set(hubcaps::statuses::State::Success)?;

if !try_build.is_empty() && try_build.len() <= 10 {
// In the case of trying to merge master in to
@@ -332,7 +339,7 @@ impl<'a> NixpkgsStrategy<'a> {
}
Err(out) => {
status.set_url(make_gist(&self.gists, "Meta Check", None, out.display()));
status.set(hubcaps::statuses::State::Failure);
status.set(hubcaps::statuses::State::Failure)?;
Err(Error::Fail(String::from(
"Failed to validate package metadata.",
)))
@@ -354,13 +361,13 @@ impl<'a> EvaluationStrategy for NixpkgsStrategy<'a> {
status.set_with_description(
"Checking original stdenvs",
hubcaps::statuses::State::Pending,
);
)?;
self.check_stdenvs_before(dir);

status.set_with_description(
"Checking original out paths",
hubcaps::statuses::State::Pending,
);
)?;
self.check_outpaths_before(dir)?;

Ok(())
@@ -396,10 +403,10 @@ impl<'a> EvaluationStrategy for NixpkgsStrategy<'a> {
&["2.status: merge conflict".to_owned()],
);

status.set_with_description("Checking new stdenvs", hubcaps::statuses::State::Pending);
status.set_with_description("Checking new stdenvs", hubcaps::statuses::State::Pending)?;
self.check_stdenvs_after();

status.set_with_description("Checking new out paths", hubcaps::statuses::State::Pending);
status.set_with_description("Checking new out paths", hubcaps::statuses::State::Pending)?;
self.check_outpaths_after()?;

Ok(())
@@ -535,10 +542,10 @@ impl<'a> EvaluationStrategy for NixpkgsStrategy<'a> {
status.set_with_description(
"Calculating Changed Outputs",
hubcaps::statuses::State::Pending,
);
)?;

self.update_new_package_labels();
self.update_rebuild_labels(&dir, status);
self.update_rebuild_labels(&dir, status)?;
let checks = self.performance_stats();

let builds = self.check_meta_queue_builds(&dir)?;
Loading