diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6825260 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: nix +matrix: + include: + - script: + - nix-shell --run 'cd ofborg && cargo test --lib -- --nocapture' + - nix-shell --run 'cd ofborg && cargo test --lib -- --nocapture' --arg useNix1 true diff --git a/ofborg/src/checkout.rs b/ofborg/src/checkout.rs index 4f1bde9..14cb651 100644 --- a/ofborg/src/checkout.rs +++ b/ofborg/src/checkout.rs @@ -269,10 +269,14 @@ mod tests { .current_dir(tpath("./test-srcs")) .arg(bare) .arg(co) - .stderr(Stdio::null()) .stdout(Stdio::piped()) .output() .expect("building the test PR failed"); + + let stderr = String::from_utf8(output.stderr) + .unwrap_or_else(|err| format!("warning: {}", err)); + println!("{}", stderr); + let hash = String::from_utf8(output.stdout).expect("Should just be a hash"); return hash.trim().to_owned(); } diff --git a/ofborg/src/clone.rs b/ofborg/src/clone.rs index 1ab3277..a2ba7ea 100644 --- a/ofborg/src/clone.rs +++ b/ofborg/src/clone.rs @@ -76,7 +76,7 @@ pub trait GitClonable { if result.success() { return Ok(()); } else { - return Err(Error::new(ErrorKind::Other, "Failed to clone")); + return Err(Error::new(ErrorKind::Other, format!("Failed to clone from {:?} to {:?}", self.clone_from(), self.clone_to()))); } } diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs index 0f2e890..3418950 100644 --- a/ofborg/src/nix.rs +++ b/ofborg/src/nix.rs @@ -275,7 +275,8 @@ fn lines_from_file(file: File) -> Vec { #[cfg(test)] mod tests { fn nix() -> Nix { - Nix::new("x86_64-linux".to_owned(), "daemon".to_owned(), 1800, None) + let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); + Nix::new("x86_64-linux".to_owned(), remote, 1800, None) } fn noop(operation: Operation) -> Operation { @@ -502,7 +503,8 @@ mod tests { #[test] fn safe_command_custom_gc() { - let nix = Nix::new("x86_64-linux".to_owned(), "daemon".to_owned(), 1800, Some("4g".to_owned())); + let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); + let nix = Nix::new("x86_64-linux".to_owned(), remote, 1800, Some("4g".to_owned())); let ret: Result = nix.run( diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index 62c8100..6f47d95 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -400,6 +400,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { #[cfg(test)] mod tests { use super::*; + use std::env; use std::path::{Path, PathBuf}; use ofborg::message::{Pr, Repo}; use notifyworker::SimpleNotifyWorker; @@ -408,7 +409,8 @@ mod tests { use ofborg::test_scratch::TestScratch; fn nix() -> nix::Nix { - nix::Nix::new("x86_64-linux".to_owned(), "daemon".to_owned(), 1800, None) + let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); + nix::Nix::new("x86_64-linux".to_owned(), remote, 1800, None) } fn tpath(component: &str) -> PathBuf { diff --git a/ofborg/src/tasks/massrebuilder.rs b/ofborg/src/tasks/massrebuilder.rs index 13796ef..12b3307 100644 --- a/ofborg/src/tasks/massrebuilder.rs +++ b/ofborg/src/tasks/massrebuilder.rs @@ -786,6 +786,7 @@ fn parse_commit_messages(messages: Vec) -> Vec { mod tests { use super::*; + use std::env; use std::process::Command; #[test] @@ -798,7 +799,8 @@ mod tests { let nixpkgs = String::from_utf8(output.stdout) .expect("nixpkgs required"); - let nix = nix::Nix::new(String::from("x86_64-linux"), String::from("daemon"), 1200, None); + let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); + let nix = nix::Nix::new(String::from("x86_64-linux"), remote, 1200, None); let mut stdenv = Stdenvs::new( nix.clone(), diff --git a/ofborg/test-srcs/build-pr/succeed.sh b/ofborg/test-srcs/build-pr/succeed.sh index 7ec52d0..c244fe9 100644 --- a/ofborg/test-srcs/build-pr/succeed.sh +++ b/ofborg/test-srcs/build-pr/succeed.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash echo "$@" echo hi diff --git a/ofborg/test-srcs/build/environment.sh b/ofborg/test-srcs/build/environment.sh index 81c93fb..dc4cd85 100755 --- a/ofborg/test-srcs/build/environment.sh +++ b/ofborg/test-srcs/build/environment.sh @@ -1,3 +1,3 @@ -#!/bin/sh +#!/usr/bin/env bash env diff --git a/ofborg/test-srcs/build/succeed.sh b/ofborg/test-srcs/build/succeed.sh index 7ec52d0..c244fe9 100644 --- a/ofborg/test-srcs/build/succeed.sh +++ b/ofborg/test-srcs/build/succeed.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash echo "$@" echo hi diff --git a/ofborg/test-srcs/make-pr.sh b/ofborg/test-srcs/make-pr.sh index 84c055c..018c333 100755 --- a/ofborg/test-srcs/make-pr.sh +++ b/ofborg/test-srcs/make-pr.sh @@ -1,36 +1,24 @@ -#!/bin/sh - -set -eux -set -o pipefail +#!/usr/bin/env bash +set -eu bare=$1 co=$2 -( +makepr() { git init --bare "$bare" git clone "$bare" "$co" + cp build/* "$co/" + git -C "$co" add . + git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg " -m "initial repo commit" + git -C "$co" push origin master - ( - cp build/* "$co/" - cd "$co/" - git add . - git commit --no-gpg-sign -m "initial repo commit" - git push origin master - ) + cp build-pr/* "$co/" + git -C "$co" checkout -b my-cool-pr + git -C "$co" add . + git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg " -m "check out this cool PR" + git -C "$co" push origin my-cool-pr:refs/pull/1/head +} - ( - cp build-pr/* "$co/" - cd "$co/" - git checkout -b my-cool-pr - git add . - git commit --no-gpg-sign -m "check out this cool PR" - git push origin my-cool-pr:refs/pull/1/head - - ) -) >&2 - -( - cd "$co/" - git rev-parse HEAD -) +makepr >&2 +git -C "$co" rev-parse HEAD diff --git a/shell.nix b/shell.nix index 7ec2848..9843aec 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,6 @@ +{ pkgs ? import ./nix {}, useNix1 ? true }: + let - pkgs = import ./nix {}; - - inherit (pkgs) stdenv; phpEnv = stdenv.mkDerivation rec { @@ -11,12 +10,12 @@ let nix-prefetch-git php phpPackages.composer - nix git php curl bash - ]; + ] + ++ stdenv.lib.optional useNix1 nix; # HISTFILE = "${src}/.bash_hist"; }; @@ -32,7 +31,9 @@ let openssl.dev pkgconfig git - ] ++ (lib.optional stdenv.isDarwin pkgs.darwin.Security); + ] + ++ stdenv.lib.optional useNix1 nix + ++ stdenv.lib.optional stdenv.isDarwin pkgs.darwin.Security; HISTFILE = "${toString ./.}/.bash_hist"; passthru.phpEnv = phpEnv;