forked from tigerbeetle/tigerbeetle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.zig
195 lines (164 loc) · 7.11 KB
/
ci.zig
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! Various CI checks that go beyond `zig build test`. Notably, at the moment this script includes:
//!
//! - Testing all language clients.
//! - Building and link-checking docs.
const std = @import("std");
const builtin = @import("builtin");
const log = std.log;
const assert = std.debug.assert;
const stdx = @import("../stdx.zig");
const flags = @import("../flags.zig");
const fatal = flags.fatal;
const Shell = @import("../shell.zig");
const TmpTigerBeetle = @import("../testing/tmp_tigerbeetle.zig");
const client_readmes = @import("./client_readmes.zig");
pub const Language = std.meta.FieldEnum(@TypeOf(LanguageCI));
const LanguageCI = .{
.dotnet = @import("../clients/dotnet/ci.zig"),
.go = @import("../clients/go/ci.zig"),
.java = @import("../clients/java/ci.zig"),
.node = @import("../clients/node/ci.zig"),
};
pub const CliArgs = struct {
language: ?Language = null,
validate_release: bool = false,
};
pub fn main(shell: *Shell, gpa: std.mem.Allocator, cli_args: CliArgs) !void {
if (cli_args.validate_release) {
try validate_release(shell, gpa, cli_args.language);
} else {
try generate_readmes(shell, gpa, cli_args.language);
try run_tests(shell, gpa, cli_args.language);
}
}
fn generate_readmes(shell: *Shell, gpa: std.mem.Allocator, language_requested: ?Language) !void {
inline for (comptime std.enums.values(Language)) |language| {
if (language_requested == language or language_requested == null) {
try shell.pushd("./src/clients/" ++ @tagName(language));
defer shell.popd();
try client_readmes.test_freshness(shell, gpa, language);
}
}
}
fn run_tests(shell: *Shell, gpa: std.mem.Allocator, language_requested: ?Language) !void {
inline for (comptime std.enums.values(Language)) |language| {
if (language_requested == language or language_requested == null) {
const ci = @field(LanguageCI, @tagName(language));
var section = try shell.open_section(@tagName(language) ++ " ci");
defer section.close();
{
try shell.pushd("./src/clients/" ++ @tagName(language));
defer shell.popd();
try ci.tests(shell, gpa);
}
// Piggy back on node client testing to verify our docs, as we use node to generate
// them anyway.
if (language == .node and builtin.os.tag == .linux) {
const node_version = try shell.exec_stdout("node --version", .{});
if (std.mem.startsWith(u8, node_version, "v14")) {
log.warn("skip building documentation on old Node.js", .{});
} else {
try build_docs(shell);
}
}
}
}
}
fn build_docs(shell: *Shell) !void {
try shell.pushd("./src/docs_website");
defer shell.popd();
try shell.exec("npm install", .{});
try shell.exec("npm run build", .{});
}
fn validate_release(shell: *Shell, gpa: std.mem.Allocator, language_requested: ?Language) !void {
var tmp_dir = std.testing.tmpDir(.{});
defer tmp_dir.cleanup();
try shell.pushd_dir(tmp_dir.dir);
defer shell.popd();
const release_info = try shell.exec_stdout(
"gh release --repo tigerbeetle/tigerbeetle list --limit 1",
.{},
);
const tag = stdx.cut(release_info, "\t").?.prefix;
log.info("validating release {s}", .{tag});
try shell.exec(
"gh release --repo tigerbeetle/tigerbeetle download {tag}",
.{ .tag = tag },
);
if (builtin.os.tag != .linux) {
log.warn("skip release verification for platforms other than Linux", .{});
}
// Note: when updating the list of artifacts, don't forget to check for any external links.
//
// At minimum, `installation.md` requires an update.
const artifacts = [_][]const u8{
"tigerbeetle-aarch64-linux-debug.zip",
"tigerbeetle-aarch64-linux.zip",
"tigerbeetle-universal-macos-debug.zip",
"tigerbeetle-universal-macos.zip",
"tigerbeetle-x86_64-linux-debug.zip",
"tigerbeetle-x86_64-linux.zip",
"tigerbeetle-x86_64-windows-debug.zip",
"tigerbeetle-x86_64-windows.zip",
};
for (artifacts) |artifact| {
assert(shell.file_exists(artifact));
}
// Enable this once deterministic zip generation has been merged in and released.
// const raw_run_number = stdx.cut(stdx.cut(tag, ".").?.suffix, ".").?.suffix;
// // The +185 comes from how release.zig calculates the version number.
// const run_number = try std.fmt.allocPrint(
// shell.arena.allocator(),
// "{}",
// .{try std.fmt.parseInt(u32, raw_run_number, 10) + 185},
// );
// const sha = try shell.exec_stdout("git rev-parse HEAD", .{});
// try shell.zig("build scripts -- release --build --run-number={run_number} " ++
// "--sha={sha} --language=zig", .{
// .run_number = run_number,
// .sha = sha,
// });
// for (artifacts) |artifact| {
// // Zig only guarantees release builds to be deterministic.
// if (std.mem.indexOf(u8, artifact, "-debug.zip") != null) continue;
// // TODO(Zig): Determinism is broken on Windows:
// // https://github.com/ziglang/zig/issues/9432
// if (std.mem.indexOf(u8, artifact, "-windows.zip") != null) continue;
// const checksum_downloaded = try shell.exec_stdout("sha256sum {artifact}", .{
// .artifact = artifact,
// });
// shell.popd();
// const checksum_built = try shell.exec_stdout("sha256sum dist/tigerbeetle/{artifact}", .{
// .artifact = artifact,
// });
// try shell.pushd_dir(tmp_dir.dir);
// // Slice the output to supress the names.
// if (!std.mem.eql(u8, checksum_downloaded[0..64], checksum_built[0..64])) {
// std.debug.panic("checksum mismatch - {s}: downloaded {s}, built {s}", .{
// artifact,
// checksum_downloaded[0..64],
// checksum_built[0..64],
// });
// }
// }
try shell.exec("unzip tigerbeetle-x86_64-linux.zip", .{});
const version = try shell.exec_stdout("./tigerbeetle version --verbose", .{});
assert(std.mem.indexOf(u8, version, tag) != null);
assert(std.mem.indexOf(u8, version, "ReleaseSafe") != null);
const tigerbeetle_absolute_path = try shell.cwd.realpathAlloc(gpa, "tigerbeetle");
defer gpa.free(tigerbeetle_absolute_path);
inline for (comptime std.enums.values(Language)) |language| {
if (language_requested == language or language_requested == null) {
const ci = @field(LanguageCI, @tagName(language));
try ci.validate_release(shell, gpa, .{
.tigerbeetle = tigerbeetle_absolute_path,
.version = tag,
});
}
}
const docker_version = try shell.exec_stdout(
\\docker run ghcr.io/tigerbeetle/tigerbeetle:{version} version --verbose
, .{ .version = tag });
assert(std.mem.indexOf(u8, docker_version, tag) != null);
assert(std.mem.indexOf(u8, docker_version, "ReleaseSafe") != null);
}