blob: 775d10c085edb1e4eefbfa4eb8e89af06912bfc7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
{ lib, pkgs, ... }:
let
seed-nid = "z6MkhwX7wBkHQvcLazu2KDFK6UifGkLcoxNm2iA38fPH9LwU";
seed-ssh-keys = import ./ssh-keys.nix pkgs;
radicleConfig =
alias:
pkgs.writeText "config.json" (
builtins.toJSON {
preferredSeeds = [ "${seed-nid}@seed:8776" ];
node = { inherit alias; };
}
);
in
{
name = "radicle-ci-broker";
meta.maintainers = lib.teams.radicle.members;
nodes.seed = {
virtualisation.credentials = {
"dev.radicle.node.secret".source = "${seed-ssh-keys.snakeOilEd25519PrivateKey}";
};
services.radicle = {
enable = true;
publicKey = seed-ssh-keys.snakeOilEd25519PublicKey;
node.openFirewall = true;
settings = {
preferredSeeds = [ ];
node.alias = "seed";
};
ci = {
adapters.native.instances.native = { };
broker = {
enable = true;
settings.triggers = [
{
adapter = "native";
filters = [
{
And = [
{ HasFile = ".radicle/native.yaml"; }
"DefaultBranch"
];
}
];
}
];
};
};
};
};
nodes.alice =
{ pkgs, ... }:
{
environment.etc."gitconfig".text = ''
[init]
defaultBranch = main
[user]
email = root@alice
name = alice
'';
environment.systemPackages = with pkgs; [
gitMinimal
radicle-node
radicle-job
];
};
interactive.sshBackdoor.enable = true;
interactive.defaults.virtualisation.graphics = false;
testScript = ''
import json
import time
start_all()
seed.wait_for_unit("radicle-ci-broker.service")
alice.succeed("rad auth --alias alice --stdin </dev/null")
alice.copy_from_host("${radicleConfig "alice"}", "/root/.radicle/config.json")
alice.succeed("rad node start")
alice_nid = alice.succeed("rad self --nid").strip()
alice.succeed("mkdir /tmp/repo")
alice.succeed("git -C /tmp/repo init")
alice.succeed("mkdir /tmp/repo/.radicle")
alice.succeed("echo 'shell: echo -n it works > /run/radicle-ci-broker/result' > /tmp/repo/.radicle/native.yaml")
alice.succeed("git -C /tmp/repo add .")
alice.succeed("git -C /tmp/repo commit -m init")
alice.succeed("cd /tmp/repo && rad init --name repo --description \"\" --default-branch main --public")
rid = alice.succeed("rad inspect --rid /tmp/repo").strip()
def git_head():
return alice.succeed("git -C /tmp/repo rev-parse HEAD").strip()
def list_runs(oid):
alice.succeed(f"rad sync {rid} -f")
jobs = json.loads(alice.succeed(f"rad job --repository {rid} list"))["jobs"]
return [
{"node_id": run["node_id"], **node_run}
for job in jobs if job["oid"] == oid
for run in job["runs"] for node_run in run["runs"]
]
def run_succeeded(run):
return run["node_id"] == "${seed-nid}" and run["status"] == {"Finished": "Succeeded"}
def _retry(f):
for _ in range(10):
if out := f(): return out
time.sleep(1)
assert False
assert list_runs(head := git_head()) == []
seed.succeed(f"rad-system seed {rid}")
assert seed.wait_until_succeeds("cat /run/radicle-ci-broker/result") == "it works"
_retry(lambda: len(runs := list_runs(head)) == 1 and run_succeeded(runs[0]))
alice.succeed("echo 'shell: echo -n second commit > /run/radicle-ci-broker/result2' > /tmp/repo/.radicle/native.yaml")
alice.succeed("git -C /tmp/repo add .")
alice.succeed("git -C /tmp/repo commit -m 2")
assert list_runs(head := git_head()) == []
alice.succeed("git -C /tmp/repo push")
assert seed.wait_until_succeeds("cat /run/radicle-ci-broker/result2") == "second commit"
run = _retry(lambda: len(runs := list_runs(head)) == 1 and run_succeeded(run := runs[0]) and run)
seed.succeed("rm /run/radicle-ci-broker/result2")
seed.fail("cat /run/radicle-ci-broker/result2")
seed.succeed(f"cibtool-system trigger --repo repo --node {alice_nid} --commit main")
assert seed.wait_until_succeeds("cat /run/radicle-ci-broker/result2") == "second commit"
_retry(lambda: len(runs := sorted(list_runs(head), key=run.__ne__)) == 2
and runs[0] == run and runs[1]["run_id"] != run["run_id"] and run_succeeded(runs[1]))
'';
}
|