Skip to content

Commit f52faf2

Browse files
committed
Add repository database to releases
Creates a SQLite database containing the entire git repository as part of the release process. This allows users to clone the repository directly from the SQLite database using git-remote-sqlite itself. The database is created by: 1. Creating a temporary bare git repository 2. Mirroring the current repository to the temp repo 3. Using git-remote-sqlite to push from temp repo to SQLite The resulting git-remote-sqlite.db file is included in GitHub releases alongside the binary archives. Ran `zig build repo-db` locally and verified: - Database is created successfully at zig-out/git-remote-sqlite.db - Contains 82 git objects and 2 refs - File size is ~264KB - Can be cloned with: git clone sqlite:///path/to/git-remote-sqlite.db
1 parent 75e597d commit f52faf2

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ jobs:
5252
with:
5353
draft: true
5454
generate_release_notes: true
55-
files: zig-out/git-remote-sqlite-${{ matrix.target }}.tar.gz
55+
files: |
56+
zig-out/git-remote-sqlite-${{ matrix.target }}.tar.gz
57+
zig-out/git-remote-sqlite.db

build.zig

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn build(b: *std.Build) void {
2323
.test_unit = b.step("test:unit", "Run unit tests"),
2424
.test_integration = b.step("test:integration", "Run integration tests"),
2525
.release = b.step("release", "Build release archives for all platforms"),
26+
.repo_db = b.step("repo-db", "Create SQLite database of this repository"),
2627
};
2728

2829
const target = b.standardTargetOptions(.{});
@@ -36,6 +37,11 @@ pub fn build(b: *std.Build) void {
3637
build_test(b, .{ .@"test" = steps.@"test", .test_unit = steps.test_unit, .test_integration = steps.test_integration }, .{ .target = target, .optimize = optimize });
3738

3839
build_release(b, steps.release, .{ .target = target });
40+
41+
build_repo_database(b, steps.repo_db);
42+
43+
// Add repo database to release step
44+
steps.release.dependOn(steps.repo_db);
3945
}
4046

4147
fn build_git_remote_sqlite(b: *std.Build, steps: struct {
@@ -173,3 +179,64 @@ fn build_release(b: *std.Build, release_step: *std.Build.Step, options: struct {
173179

174180
release_step.dependOn(&tar_cmd.step);
175181
}
182+
183+
fn build_repo_database(b: *std.Build, repo_db_step: *std.Build.Step) void {
184+
// Ensure the binary is built first
185+
repo_db_step.dependOn(b.getInstallStep());
186+
187+
const db_filename = "git-remote-sqlite.db";
188+
const db_path = b.fmt("{s}/{s}", .{ b.install_path, db_filename });
189+
190+
// Remove existing database if it exists
191+
const rm_cmd = b.addSystemCommand(&[_][]const u8{ "rm", "-f", db_path });
192+
193+
// Script to create the database
194+
const script = b.fmt(
195+
\\#!/bin/bash
196+
\\set -euo pipefail
197+
\\
198+
\\# Remove existing database
199+
\\rm -f {s}
200+
\\
201+
\\# Create temp directory
202+
\\TEMP_DIR=$(mktemp -d)
203+
\\trap "rm -rf $TEMP_DIR" EXIT
204+
\\
205+
\\# Initialize bare repo in temp dir
206+
\\cd "$TEMP_DIR"
207+
\\git init --bare
208+
\\
209+
\\# Configure the SQLite remote
210+
\\git remote add sqlite "sqlite://{s}"
211+
\\
212+
\\# Push current repo to temp bare repo
213+
\\cd {s}
214+
\\git push --mirror "file://$TEMP_DIR"
215+
\\
216+
\\# Push from temp repo to SQLite
217+
\\cd "$TEMP_DIR"
218+
\\export PATH="{s}/bin:$PATH"
219+
\\git push --mirror sqlite
220+
\\
221+
\\# Verify the database was created
222+
\\if [ -f "{s}" ]; then
223+
\\ echo "Repository database created: {s}"
224+
\\ echo "Database size: $(du -h {s} | cut -f1)"
225+
\\ echo "Objects: $(sqlite3 {s} 'SELECT COUNT(*) FROM git_objects')"
226+
\\ echo "Refs: $(sqlite3 {s} 'SELECT COUNT(*) FROM git_refs')"
227+
\\else
228+
\\ echo "ERROR: Database was not created"
229+
\\ exit 1
230+
\\fi
231+
, .{ db_path, db_path, b.build_root.path orelse ".", b.install_path, db_path, db_path, db_path, db_path, db_path });
232+
233+
// Write and execute the script
234+
const script_path = b.fmt("{s}/create-repo-db.sh", .{b.cache_root.path orelse "."});
235+
const write_script = b.addWriteFile(script_path, script);
236+
237+
const create_db = b.addSystemCommand(&[_][]const u8{ "bash", script_path });
238+
create_db.step.dependOn(&write_script.step);
239+
create_db.step.dependOn(&rm_cmd.step);
240+
241+
repo_db_step.dependOn(&create_db.step);
242+
}

0 commit comments

Comments
 (0)