Skip to content

Commit

Permalink
test stdenv rebuild skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
LnL7 committed Dec 17, 2020
1 parent 5f2e393 commit b11f349
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
54 changes: 54 additions & 0 deletions ofborg/src/tasks/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,21 @@ mod tests {
hash.trim().to_owned()
}

fn make_stdenv_pr_repo(bare: &Path, co: &Path) -> String {
let output = Command::new("bash")
.current_dir(tpath("./test-srcs"))
.arg("make-stdenv-pr.sh")
.arg(bare)
.arg(co)
.stderr(Stdio::null())
.stdout(Stdio::piped())
.output()
.expect("building the test PR failed");
let hash = String::from_utf8(output.stdout).expect("Should just be a hash");

hash.trim().to_owned()
}

fn strip_escaped_ansi(string: &str) -> String {
string
.replace("‘", "'")
Expand Down Expand Up @@ -532,6 +547,45 @@ mod tests {
assert_eq!(actions.next(), Some(worker::Action::Ack));
}

#[test]
pub fn test_stdenv_rebuild() {
let p = TestScratch::new_dir("build-stdenv-build-working");
let bare_repo = TestScratch::new_dir("build-stdenv-build-bare");
let co_repo = TestScratch::new_dir("build-stdenv-build-co");

let head_sha = make_stdenv_pr_repo(&bare_repo.path(), &co_repo.path());
let worker = make_worker(&p.path());

let job = buildjob::BuildJob {
attrs: vec!["success".to_owned()],
pr: Pr {
head_sha,
number: 1,
target_branch: Some("staging".to_owned()),
},
repo: Repo {
clone_url: bare_repo.path().to_str().unwrap().to_owned(),
full_name: "test-git".to_owned(),
name: "nixos".to_owned(),
owner: "ofborg-test".to_owned(),
},
subset: None,
logs: Some((Some(String::from("logs")), Some(String::from("build.log")))),
statusreport: Some((Some(String::from("build-results")), None)),
request_id: "bogus-request-id".to_owned(),
};

let mut dummyreceiver = notifyworker::DummyNotificationReceiver::new();

worker.consumer(&job, &mut dummyreceiver);

println!("Total actions: {:?}", dummyreceiver.actions.len());
let mut actions = dummyreceiver.actions.into_iter();
assert_contains_job(&mut actions, "skipped_attrs\":[\"success"); // First one to the github poster
assert_contains_job(&mut actions, "skipped_attrs\":[\"success"); // This one to the logs
assert_eq!(actions.next(), Some(worker::Action::Ack));
}

#[test]
pub fn test_all_jobs_skipped() {
let p = TestScratch::new_dir("no-attempt");
Expand Down
5 changes: 5 additions & 0 deletions ofborg/test-srcs/build-pr/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ let
builder = builtins.storePath <ofborg-test-bash>;
in
{
stdenv = import <nix/fetchurl.nix> {
url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz";
sha256 = "a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39";
};

success = derivation {
name = "success";
system = builtins.currentSystem;
Expand Down
5 changes: 5 additions & 0 deletions ofborg/test-srcs/build/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ let
builder = builtins.storePath <ofborg-test-bash>;
in
{
stdenv = import <nix/fetchurl.nix> {
url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz";
sha256 = "a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39";
};

success = derivation {
name = "success";
system = builtins.currentSystem;
Expand Down
27 changes: 27 additions & 0 deletions ofborg/test-srcs/make-stdenv-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -eu

bare=$1
co=$2

makepr() {
git init --bare "$bare"
git clone "$bare" "$co"
git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg <graham+cofborg@example.com>" --allow-empty -m "empty master commit"
git -C "$co" push origin master

cp build/* "$co/"
git -C "$co" add .
git -C "$co" checkout -B staging
git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg <graham+cofborg@example.com>" -m "initial repo commit"
git -C "$co" push origin staging

cp stdenv-pr/* "$co/"
git -C "$co" checkout -b my-cool-pr
git -C "$co" add .
git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg <graham+cofborg@example.com>" -m "check out this cool PR"
git -C "$co" push origin my-cool-pr:refs/pull/1/head
}

makepr >&2
git -C "$co" rev-parse HEAD
16 changes: 16 additions & 0 deletions ofborg/test-srcs/stdenv-pr/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let
builder = builtins.storePath <ofborg-test-bash>;
in
{
stdenv = import <nix/fetchurl.nix> {
url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz";
sha256 = "0000000000000000000000000000000000000000000000000000000000000000";
};

success = derivation {
name = "success";
system = builtins.currentSystem;
inherit builder;
args = [ "-c" "echo hi; printf '1\n2\n3\n4\n'; echo ${toString builtins.currentTime} > $out" ];
};
}

0 comments on commit b11f349

Please sign in to comment.