Skip to content

Commit 8974f52

Browse files
committed
Release workflow
1 parent 5aa45fb commit 8974f52

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
on:
22
push:
33
branches: [main]
4+
tags:
5+
- "v*"
46
pull_request:
57
branches: [main]
68
workflow_dispatch:
79

810
jobs:
9-
main:
11+
build:
1012
runs-on: ${{ matrix.os }}
1113
strategy:
1214
matrix:
13-
os: [ubuntu-latest, macos-latest]
15+
include:
16+
- os: ubuntu-latest
17+
target: x86_64-linux
18+
- os: macos-latest
19+
target: x86_64-macos
20+
- os: macos-latest
21+
target: aarch64-macos
1422

1523
steps:
1624
- uses: actions/checkout@v4
@@ -33,3 +41,13 @@ jobs:
3341
- run: zig build
3442

3543
- run: zig build test
44+
45+
- run: zig build release
46+
47+
- name: Release
48+
if: github.ref_type == 'tag'
49+
uses: softprops/action-gh-release@v1
50+
with:
51+
draft: true
52+
generate_release_notes: true
53+
files: zig-out/git-remote-sqlite-${{ matrix.target }}.tar.gz

build.zig

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn build(b: *std.Build) void {
2222
.@"test" = b.step("test", "Run tests"),
2323
.test_unit = b.step("test:unit", "Run unit tests"),
2424
.test_integration = b.step("test:integration", "Run integration tests"),
25+
.release = b.step("release", "Build release archives for all platforms"),
2526
};
2627

2728
const target = b.standardTargetOptions(.{});
@@ -33,6 +34,8 @@ pub fn build(b: *std.Build) void {
3334
}, .{ .target = target, .optimize = optimize });
3435

3536
build_test(b, .{ .@"test" = steps.@"test", .test_unit = steps.test_unit, .test_integration = steps.test_integration }, .{ .target = target, .optimize = optimize });
37+
38+
build_release(b, steps.release, .{ .target = target });
3639
}
3740

3841
fn build_git_remote_sqlite(b: *std.Build, steps: struct {
@@ -121,3 +124,52 @@ fn build_test(b: *std.Build, steps: struct {
121124
steps.@"test".dependOn(&run_unit.step);
122125
steps.@"test".dependOn(&integration_cmd.step);
123126
}
127+
128+
fn build_release(b: *std.Build, release_step: *std.Build.Step, options: struct {
129+
target: std.Build.ResolvedTarget,
130+
}) void {
131+
// Use the target passed from build()
132+
const release_target = options.target;
133+
134+
// Determine target triple name based on the actual target
135+
const triple = blk: {
136+
const arch = release_target.result.cpu.arch;
137+
const os = release_target.result.os.tag;
138+
139+
if (arch == .x86_64 and os == .linux) break :blk "x86_64-linux";
140+
if (arch == .x86_64 and os == .macos) break :blk "x86_64-macos";
141+
if (arch == .aarch64 and os == .macos) break :blk "aarch64-macos";
142+
143+
// Fallback for other platforms
144+
break :blk b.fmt("{s}-{s}", .{ @tagName(arch), @tagName(os) });
145+
};
146+
147+
const release_mod = b.createModule(.{
148+
.root_source_file = b.path("src/main.zig"),
149+
.target = release_target,
150+
.optimize = .ReleaseSafe,
151+
});
152+
const release_exe = b.addExecutable(.{
153+
.name = "git-remote-sqlite",
154+
.root_module = release_mod,
155+
});
156+
release_exe.linkSystemLibrary("sqlite3");
157+
release_exe.linkSystemLibrary("git2");
158+
release_exe.linkLibC();
159+
160+
// Install to zig-out/bin/{target}/git-remote-sqlite
161+
const install = b.addInstallArtifact(release_exe, .{
162+
.dest_dir = .{ .override = .{ .custom = b.fmt("bin/{s}", .{triple}) } },
163+
});
164+
165+
// Create tar.gz archive
166+
const tar_cmd = b.addSystemCommand(&[_][]const u8{
167+
"tar", "-czf",
168+
b.fmt("{s}/git-remote-sqlite-{s}.tar.gz", .{ b.install_path, triple }),
169+
"-C", b.fmt("{s}/bin/{s}", .{ b.install_path, triple }),
170+
"git-remote-sqlite",
171+
});
172+
tar_cmd.step.dependOn(&install.step);
173+
174+
release_step.dependOn(&tar_cmd.step);
175+
}

0 commit comments

Comments
 (0)