Skip to content

Commit a339b1e

Browse files
committed
test stdenv rebuild skipping
1 parent 5f2e393 commit a339b1e

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

ofborg/src/tasks/build.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,21 @@ mod tests {
452452
hash.trim().to_owned()
453453
}
454454

455+
fn make_stdenv_pr_repo(bare: &Path, co: &Path) -> String {
456+
let output = Command::new("bash")
457+
.current_dir(tpath("./test-srcs"))
458+
.arg("make-stdenv-pr.sh")
459+
.arg(bare)
460+
.arg(co)
461+
.stderr(Stdio::null())
462+
.stdout(Stdio::piped())
463+
.output()
464+
.expect("building the test PR failed");
465+
let hash = String::from_utf8(output.stdout).expect("Should just be a hash");
466+
467+
hash.trim().to_owned()
468+
}
469+
455470
fn strip_escaped_ansi(string: &str) -> String {
456471
string
457472
.replace("‘", "'")
@@ -532,6 +547,45 @@ mod tests {
532547
assert_eq!(actions.next(), Some(worker::Action::Ack));
533548
}
534549

550+
#[test]
551+
pub fn test_stdenv_rebuild() {
552+
let p = TestScratch::new_dir("build-stdenv-build-working");
553+
let bare_repo = TestScratch::new_dir("build-stdenv-build-bare");
554+
let co_repo = TestScratch::new_dir("build-stdenv-build-co");
555+
556+
let head_sha = make_stdenv_pr_repo(&bare_repo.path(), &co_repo.path());
557+
let worker = make_worker(&p.path());
558+
559+
let job = buildjob::BuildJob {
560+
attrs: vec!["success".to_owned()],
561+
pr: Pr {
562+
head_sha,
563+
number: 1,
564+
target_branch: Some("staging".to_owned()),
565+
},
566+
repo: Repo {
567+
clone_url: bare_repo.path().to_str().unwrap().to_owned(),
568+
full_name: "test-git".to_owned(),
569+
name: "nixos".to_owned(),
570+
owner: "ofborg-test".to_owned(),
571+
},
572+
subset: None,
573+
logs: Some((Some(String::from("logs")), Some(String::from("build.log")))),
574+
statusreport: Some((Some(String::from("build-results")), None)),
575+
request_id: "bogus-request-id".to_owned(),
576+
};
577+
578+
let mut dummyreceiver = notifyworker::DummyNotificationReceiver::new();
579+
580+
worker.consumer(&job, &mut dummyreceiver);
581+
582+
println!("Total actions: {:?}", dummyreceiver.actions.len());
583+
let mut actions = dummyreceiver.actions.into_iter();
584+
assert_contains_job(&mut actions, "skipped_attrs\":[\"success"); // First one to the github poster
585+
assert_contains_job(&mut actions, "skipped_attrs\":[\"success"); // This one to the logs
586+
assert_eq!(actions.next(), Some(worker::Action::Ack));
587+
}
588+
535589
#[test]
536590
pub fn test_all_jobs_skipped() {
537591
let p = TestScratch::new_dir("no-attempt");

ofborg/test-srcs/build-pr/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ let
22
builder = builtins.storePath <ofborg-test-bash>;
33
in
44
{
5+
stdenv = import <nix/fetchurl.nix> {
6+
url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz";
7+
sha256 = "a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39";
8+
};
9+
510
success = derivation {
611
name = "success";
712
system = builtins.currentSystem;

ofborg/test-srcs/build/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ let
22
builder = builtins.storePath <ofborg-test-bash>;
33
in
44
{
5+
stdenv = import <nix/fetchurl.nix> {
6+
url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz";
7+
sha256 = "a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39";
8+
};
9+
510
success = derivation {
611
name = "success";
712
system = builtins.currentSystem;

ofborg/test-srcs/make-stdenv-pr.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
bare=$1
5+
co=$2
6+
7+
makepr() {
8+
git init --bare "$bare"
9+
git clone "$bare" "$co"
10+
git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg <[email protected]>" --allow-empty -m "empty master commit"
11+
git -C "$co" push origin master
12+
13+
cp build/* "$co/"
14+
git -C "$co" add .
15+
git -C "$co" checkout -B staging
16+
git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg <[email protected]>" -m "initial repo commit"
17+
git -C "$co" push origin staging
18+
19+
cp stdenv-pr/* "$co/"
20+
git -C "$co" checkout -b my-cool-pr
21+
git -C "$co" add .
22+
git -C "$co" commit --no-gpg-sign --author "GrahamCOfBorg <[email protected]>" -m "check out this cool PR"
23+
git -C "$co" push origin my-cool-pr:refs/pull/1/head
24+
}
25+
26+
makepr >&2
27+
git -C "$co" rev-parse HEAD
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let
2+
builder = builtins.storePath <ofborg-test-bash>;
3+
in
4+
{
5+
stdenv = import <nix/fetchurl.nix> {
6+
url = "http://tarballs.nixos.org/stdenv-linux/x86_64/c5aabb0d603e2c1ea05f5a93b3be82437f5ebf31/bootstrap-tools.tar.xz";
7+
sha256 = "0000000000000000000000000000000000000000000000000000000000000000";
8+
};
9+
10+
success = derivation {
11+
name = "success";
12+
system = builtins.currentSystem;
13+
inherit builder;
14+
args = [ "-c" "echo hi; printf '1\n2\n3\n4\n'; echo ${toString builtins.currentTime} > $out" ];
15+
};
16+
}

0 commit comments

Comments
 (0)