Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit e96fe4f

Browse files
committed
clients: bring back testing of READMEs on CI
Move logic from docs_generate utility into `scripts -- ci` workflow, so that it gets executed by CI naturally. Along the way, cleanup code a bit: * use rely on `shell.zig` rather than `shutil.zig`, remove the latter. * merge `Generator` and `Markdown` writer into a single `Context` struct. There might be some finer grained factoring here, but we don't use markdown-writing capabilities elsewhere, so a single grab bag of stuff feels simpler. * pull the overall control flow for reading&updating files into a top-level function. * remove helper functions for generating common parts between main & sample readmes --- the "common" parts differ more than they are the same, it's more readable to copy the relevant paragraphs twice * use code blocks to delimit markdown sections. This surfaces one wrong header even!
1 parent 71ee9fd commit e96fe4f

15 files changed

+611
-848
lines changed

Diff for: build.zig

-81
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,6 @@ pub fn build(b: *std.Build) !void {
394394
git_clone_tracy,
395395
tracer_backend,
396396
);
397-
client_docs(
398-
b.allocator,
399-
b,
400-
mode,
401-
target,
402-
);
403397
}
404398

405399
{
@@ -1036,81 +1030,6 @@ fn c_client_sample(
10361030
c_sample_build.dependOn(&install_step.step);
10371031
}
10381032

1039-
// Allows a build step to run the command it builds after it builds it if the user passes --.
1040-
// e.g.: ./zig/zig build docs_generate --
1041-
// Whereas `./zig/zig build docs_generate` would not run the command.
1042-
fn maybe_execute(
1043-
b: *std.Build,
1044-
allocator: std.mem.Allocator,
1045-
top_level_step: *std.Build.Step,
1046-
install_step: *std.Build.Step.InstallArtifact,
1047-
binary_name: []const u8,
1048-
) void {
1049-
var to_run = std.ArrayList([]const u8).init(allocator);
1050-
defer to_run.deinit();
1051-
1052-
const sep = if (builtin.os.tag == .windows) "\\" else "/";
1053-
const ext = if (builtin.os.tag == .windows) ".exe" else "";
1054-
to_run.append(
1055-
std.fmt.allocPrint(
1056-
allocator,
1057-
".{s}zig-out{s}bin{s}{s}{s}",
1058-
.{
1059-
sep,
1060-
sep,
1061-
sep,
1062-
binary_name,
1063-
ext,
1064-
},
1065-
) catch unreachable,
1066-
) catch unreachable;
1067-
1068-
var args = std.process.argsWithAllocator(allocator) catch unreachable;
1069-
defer args.deinit();
1070-
1071-
var build_and_run = false;
1072-
while (args.next()) |arg| {
1073-
if (std.mem.eql(u8, arg, "--")) {
1074-
build_and_run = true;
1075-
continue;
1076-
}
1077-
1078-
if (build_and_run) {
1079-
to_run.append(arg) catch unreachable;
1080-
}
1081-
}
1082-
1083-
if (build_and_run) {
1084-
const run = b.addSystemCommand(to_run.items);
1085-
run.step.dependOn(&install_step.step);
1086-
top_level_step.dependOn(&run.step);
1087-
}
1088-
}
1089-
1090-
// See src/clients/README.md for documentation.
1091-
fn client_docs(
1092-
allocator: std.mem.Allocator,
1093-
b: *std.Build,
1094-
mode: Mode,
1095-
target: CrossTarget,
1096-
) void {
1097-
const binary = b.addExecutable(.{
1098-
.name = "client_docs",
1099-
.root_source_file = .{ .path = "src/clients/docs_generate.zig" },
1100-
.target = target,
1101-
.optimize = mode,
1102-
.main_pkg_path = .{ .path = "src" },
1103-
});
1104-
1105-
const client_docs_build = b.step("client_docs", "Generate documentation for a client library");
1106-
client_docs_build.dependOn(&binary.step);
1107-
1108-
const install_step = b.addInstallArtifact(binary, .{});
1109-
client_docs_build.dependOn(&install_step.step);
1110-
1111-
maybe_execute(b, allocator, client_docs_build, install_step, "client_docs");
1112-
}
1113-
11141033
/// Steps which unconditionally fails with a message.
11151034
///
11161035
/// This is useful for cases where at configuration time you can determine that a certain step

Diff for: src/clients/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
*.o
2-
docs_generate

Diff for: src/clients/README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
## Documentation
44

55
Documentation for clients (i.e. client `README.md`s) are generated
6-
from [docs_generate.zig](./docs_generate.zig).
6+
from [../scripts/client_readmes.zig](../scripts/client_readmes.zig).
77

88
Each client implements the `Docs` struct from
99
[docs_types.zig](./docs_types.zig).
1010

1111
The template for the README is in code in
12-
[docs_generate.zig](./docs_generate.zig).
12+
[../scripts/client_readmes.zig](../scripts/client_readmes.zig).
1313

1414
Existing `Docs` struct implementations are in:
1515

@@ -34,21 +34,15 @@ script on Windows.
3434
To build and run the client docs generator:
3535

3636
```console
37-
./zig/zig build client_docs --
37+
./zig/zig build scripts -- ci
3838
```
3939

40-
Note: Omitting the `--` will only build, not run the client_docs script.
41-
4240
### Just one language
4341

4442
To run the generator only for a certain language (defined by `.markdown_name`):
4543

4644
```console
47-
./zig/zig build client_docs -- --language=node
48-
```
49-
50-
```console
51-
./zig/zig build client_docs -- --language=node,go
45+
./zig/zig build scripts -- ci --language=go
5246
```
5347

5448
Docs are only regenerated/modified when there would be a diff so the

0 commit comments

Comments
 (0)