Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jun 28, 2023
1 parent 5d17412 commit 951660d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ jobs:
- uses: goto-bus-stop/setup-zig@v2
with:
version: ${{ matrix.zig-version }}
- name: Set Environment Variables
run: |
echo "BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_ENV
- name: Build
run: |
zig build -Dtarget=${{ matrix.targets }} -Doptimize=ReleaseSafe
zig build -Dtarget=${{ matrix.targets }} -Doptimize=ReleaseSafe \
-Dgit_commit=${{ github.head_ref }}-${{ github.sha }} \
-Dbuild_date=${{ env.BUILD_DATE }}
# https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
tar -cvf zigcli.tar zig-out/bin/
- name: Upload
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

build:
zig build -Doptimize=ReleaseFast
zig build -Doptimize=ReleaseFast -Dbuild_date=$(shell date +"%Y-%m-%dT%H:%M:%S%z") \
-Dgit_commit=$(shell git rev-parse --short HEAD)

fmt:
zig fmt --check .
Expand Down
6 changes: 4 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ pub fn build(b: *Build) void {
const table_dep = b.dependency("table-helper", .{});

const opt = b.addOptions();
opt.addOption(i64, "build_date", std.time.milliTimestamp());
opt.addOption([]const u8, "git_commit", b.option([]const u8, "git_commit", "Git commit") orelse "Unknown");
opt.addOption([]const u8, "build_date", b.option([]const u8, "build_date", "Build date") orelse
b.fmt("{d}", .{std.time.milliTimestamp()}));
opt.addOption([]const u8, "git_commit", b.option([]const u8, "git_commit", "Git commit") orelse
"Unknown");
b.modules.put("build_info", opt.createModule()) catch @panic("OOM");
b.modules.put("simargs", simargs_dep.module("simargs")) catch @panic("OOM");
b.modules.put("table-helper", table_dep.module("table-helper")) catch @panic("OOM");
Expand Down
2 changes: 1 addition & 1 deletion src/common.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const info = @import("build_info");

pub fn print_build_info(writer: anytype) !void {
try writer.print("Build date: {d}\nGit commit: {s}", .{ info.build_date, info.git_commit });
try writer.print("Build date: {s}\nGit commit: {s}", .{ info.build_date, info.git_commit });
}

0 comments on commit 951660d

Please sign in to comment.