@@ -93,24 +93,59 @@ const MiniCiStep = struct {
9393 fn make (step : * Step , options : Step.MakeOptions ) ! void {
9494 _ = options ;
9595
96- const b = step .owner ;
97-
9896 // Run the sequence of `zig build` commands that make up the
9997 // mini CI pipeline.
100- try runSubBuild (b , "fmt" , "zig build fmt" );
101- try runSubBuild (b , null , "zig build" );
102- try runSubBuild (b , "snapshot" , "zig build snapshot" );
103- try runSubBuild (b , "test" , "zig build test" );
104- try runSubBuild (b , "test-playground" , "zig build test-playground" );
105- try runSubBuild (b , "test-serialization-sizes" , "zig build test-serialization-sizes" );
106- try runSubBuild (b , "test-cli" , "zig build test-cli" );
98+ try runSubBuild (step , "fmt" , "zig build fmt" );
99+ try runSubBuild (step , null , "zig build" );
100+ try runSubBuild (step , "snapshot" , "zig build snapshot" );
101+ try checkSnapshotChanges (step );
102+ try runSubBuild (step , "test" , "zig build test" );
103+ try runSubBuild (step , "test-playground" , "zig build test-playground" );
104+ try runSubBuild (step , "test-serialization-sizes" , "zig build test-serialization-sizes" );
105+ try runSubBuild (step , "test-cli" , "zig build test-cli" );
106+ }
107+
108+ fn checkSnapshotChanges (step : * Step ) ! void {
109+ const b = step .owner ;
110+ std .debug .print ("---- minici: checking for snapshot changes ----\n " , .{});
111+
112+ var child_argv = std .ArrayList ([]const u8 ).empty ;
113+ defer child_argv .deinit (b .allocator );
114+
115+ try child_argv .append (b .allocator , "git" );
116+ try child_argv .append (b .allocator , "diff" );
117+ try child_argv .append (b .allocator , "--exit-code" );
118+ try child_argv .append (b .allocator , "test/snapshots" );
119+
120+ var child = std .process .Child .init (child_argv .items , b .allocator );
121+ child .stdin_behavior = .Inherit ;
122+ child .stdout_behavior = .Inherit ;
123+ child .stderr_behavior = .Inherit ;
124+
125+ const term = try child .spawnAndWait ();
126+
127+ switch (term ) {
128+ .Exited = > | code | {
129+ if (code != 0 ) {
130+ return step .fail (
131+ "Snapshots in 'test/snapshots' have changed. " ++
132+ "Run 'zig build snapshot' locally, review the updates, and commit the changes." ,
133+ .{},
134+ );
135+ }
136+ },
137+ else = > {
138+ return step .fail ("git diff terminated abnormally" , .{});
139+ },
140+ }
107141 }
108142
109143 fn runSubBuild (
110- b : * std.Build ,
144+ step : * Step ,
111145 step_name : ? []const u8 ,
112146 display : []const u8 ,
113147 ) ! void {
148+ const b = step .owner ;
114149 std .debug .print ("---- minici: running `{s}` ----\n " , .{display });
115150
116151 var child_argv = std .ArrayList ([]const u8 ).empty ;
@@ -134,16 +169,11 @@ const MiniCiStep = struct {
134169 switch (term ) {
135170 .Exited = > | code | {
136171 if (code != 0 ) {
137- std .debug .print (
138- "minici: `{s}` failed with exit code {d}\n " ,
139- .{ display , code },
140- );
141- return error .MakeFailed ;
172+ return step .fail ("`{s}` failed with exit code {d}" , .{ display , code });
142173 }
143174 },
144175 else = > {
145- std .debug .print ("minici: `{s}` terminated abnormally\n " , .{display });
146- return error .MakeFailed ;
176+ return step .fail ("`{s}` terminated abnormally" , .{display });
147177 },
148178 }
149179 }
0 commit comments