Skip to content

Commit d47c130

Browse files
committed
fix release assets
1 parent 98a9f23 commit d47c130

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ jobs:
4343
GATORCAT_RELEASE: 1
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4545

46-
- name: Add binaries to release
46+
- name: Add binaries to release assets
4747
uses: softprops/action-gh-release@v2
4848
if: ${{ github.event_name == 'release' }}
4949
with:
50+
fail_on_unmatched_files: true
5051
files: |
51-
zig-out/x86_64-linux-musl/
52-
zig-out/aarch64-linux-musl/
53-
zig-out/x86_64-windows-gnu/
52+
zig-out/release/*

build.zig

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33

4+
const build_zig_zon = @embedFile("build.zig.zon");
5+
46
pub fn build(b: *std.Build) void {
57
// const git_describe = std.mem.trimRight(u8, b.run(&.{ "git", "describe", "--tags" }), '\n');
68

@@ -49,7 +51,7 @@ pub fn build(b: *std.Build) void {
4951
}
5052

5153
// zig build
52-
_ = buildCli(b, step_cli, target, optimize, module, .default);
54+
_ = buildCli(b, step_cli, target, optimize, module, .default, "gatorcat");
5355

5456
// zig build release
5557
const installs = buildRelease(b, step_release) catch @panic("oom");
@@ -185,6 +187,7 @@ pub fn buildCli(
185187
optimize: std.builtin.OptimizeMode,
186188
gatorcat_module: *std.Build.Module,
187189
dest_dir: std.Build.Step.InstallArtifact.Options.Dir,
190+
exe_name: []const u8,
188191
) *std.Build.Step.InstallArtifact {
189192
const flags_module = b.dependency("flags", .{
190193
.target = target,
@@ -199,7 +202,7 @@ pub fn buildCli(
199202
.optimize = optimize,
200203
}).module("zenoh");
201204
const cli = b.addExecutable(.{
202-
.name = "gatorcat",
205+
.name = exe_name,
203206
.root_source_file = b.path("src/cli/main.zig"),
204207
.target = target,
205208
.optimize = optimize,
@@ -253,14 +256,38 @@ pub fn buildRelease(
253256
},
254257
else => {},
255258
}
256-
try installs.append(buildCli(
257-
b,
258-
step,
259-
options.target,
260-
options.optimize,
261-
gatorcat_module,
262-
.{ .override = .{ .custom = target.zigTriple(b.allocator) catch @panic("oom") } },
263-
));
259+
const triple = target.zigTriple(b.allocator) catch @panic("oom");
260+
try installs.append(
261+
buildCli(
262+
b,
263+
step,
264+
options.target,
265+
options.optimize,
266+
gatorcat_module,
267+
.{ .override = .{ .custom = "release" } },
268+
try std.fmt.allocPrint(b.allocator, "gatorcat-{}-{s}", .{ getVersionFromZon(), triple }),
269+
),
270+
);
264271
}
265272
return installs;
266273
}
274+
275+
fn getVersionFromZon() std.SemanticVersion {
276+
var buffer: [10 * build_zig_zon.len]u8 = undefined;
277+
var fba = std.heap.FixedBufferAllocator.init(&buffer);
278+
const version = std.zon.parse.fromSlice(
279+
struct { version: []const u8 },
280+
fba.allocator(),
281+
build_zig_zon,
282+
null,
283+
.{ .ignore_unknown_fields = true },
284+
) catch @panic("Invalid build.zig.zon!");
285+
const semantic_version = std.SemanticVersion.parse(version.version) catch @panic("Invalid version!");
286+
return std.SemanticVersion{
287+
.major = semantic_version.major,
288+
.minor = semantic_version.minor,
289+
.patch = semantic_version.patch,
290+
.build = null, // dont return pointers to stack memory
291+
.pre = null, // dont return pointers to stack memory
292+
};
293+
}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .gatorcat,
3-
.version = "0.3.1",
3+
.version = "0.3.2",
44
.fingerprint = 0xb9356c7c4de9ca59, // Changing this has security and trust implications.
55
.minimum_zig_version = "0.14.0",
66
.dependencies = .{

src/ci/release_docker.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,18 @@ pub fn main() !void {
117117
const version_str_nl = try std.fmt.allocPrint(allocator, "{s}\n", .{version_str});
118118
const tag = try std.fmt.allocPrint(allocator, "ghcr.io/kj4tmp/gatorcat:{s}", .{version_str});
119119

120-
const dockerfile =
120+
const dockerfile_fmt =
121121
\\FROM scratch AS build-amd64
122-
\\COPY zig-out/x86_64-linux-musl/gatorcat gatorcat
122+
\\COPY zig-out/release/gatorcat-{}-x86_64-linux-musl gatorcat
123123
\\FROM scratch AS build-arm64
124-
\\COPY zig-out/aarch64-linux-musl/gatorcat gatorcat
124+
\\COPY zig-out/release/gatorcat-{}-aarch64-linux-musl gatorcat
125125
\\ARG TARGETARCH
126-
\\FROM build-${TARGETARCH}
126+
\\FROM build-${{TARGETARCH}}
127127
\\ENTRYPOINT ["/gatorcat"]
128128
;
129129

130+
const dockerfile = try std.fmt.allocPrint(allocator, dockerfile_fmt, .{ getVersionFromZon(), getVersionFromZon() });
131+
130132
const docker_build_arm64 = try runWithStdin(.{
131133
.allocator = allocator,
132134
.argv = &.{

0 commit comments

Comments
 (0)