From 2793e1e17b37be64accb8110931deac06d658d04 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 12 Jan 2022 17:42:54 -0800 Subject: [PATCH] drone support for versionstep --- VersionStep.zig | 28 ++++++++++++++++++++++++---- src/aws_http.zig | 4 ---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/VersionStep.zig b/VersionStep.zig index 0426bb7..0ea871b 100644 --- a/VersionStep.zig +++ b/VersionStep.zig @@ -84,6 +84,9 @@ fn getGitVersion(allocator: std.mem.Allocator, git_working_root: ?[]const u8, en // 2022-01-12 12:21:28 -0800 // HEAD -> zig-native + if (std.os.getenv("DRONE_COMMIT_SHA") != null) + return getGitVersionFromDrone(allocator); + const log_output = try run( allocator, &[_][]const u8{ @@ -126,6 +129,18 @@ fn getGitVersion(allocator: std.mem.Allocator, git_working_root: ?[]const u8, en } break :blk ""; }; + + return GitVersion{ + .hash = hash, + .abbreviated_hash = abbrev_hash, + .commit_date = date, + .branch = branch, + .allocator = allocator, + .dirty = dirty, + .pretty_version = try prettyVersion(allocator, abbrev_hash, date, dirty_str), + }; +} +fn prettyVersion(allocator: std.mem.Allocator, abbrev_hash: []const u8, date: []const u8, dirty_str: []const u8) ![]const u8 { const pretty_version: []const u8 = try std.fmt.allocPrint( allocator, "version {s}, committed at {s}{s}", @@ -135,15 +150,20 @@ fn getGitVersion(allocator: std.mem.Allocator, git_working_root: ?[]const u8, en dirty_str, }, ); + return pretty_version; +} +fn getGitVersionFromDrone(allocator: std.mem.Allocator) !GitVersion { + const abbrev_hash = std.os.getenv("DRONE_COMMIT_SHA").?[0..7]; // This isn't quite how git works, but ok + const date = std.os.getenv("DRONE_BUILD_STARTED").?; // this is a timestamp :( return GitVersion{ - .hash = hash, + .hash = std.os.getenv("DRONE_COMMIT_SHA").?, .abbreviated_hash = abbrev_hash, .commit_date = date, - .branch = branch, + .branch = std.os.getenv("DRONE_COMMIT_BRANCH").?, .allocator = allocator, - .dirty = dirty, - .pretty_version = pretty_version, + .dirty = false, + .pretty_version = try prettyVersion(allocator, abbrev_hash, date, ""), }; } fn getLines(allocator: std.mem.Allocator, comptime line_count: u32, data: []const u8) ![line_count][]u8 { diff --git a/src/aws_http.zig b/src/aws_http.zig index 4cc3381..6bf95ad 100644 --- a/src/aws_http.zig +++ b/src/aws_http.zig @@ -184,10 +184,6 @@ fn addHeaders(allocator: std.mem.Allocator, z_headers: *zfetch.Headers, host: [] } } -fn fullCast(comptime T: type, val: anytype) T { - return @ptrCast(T, @alignCast(@alignOf(T), val)); -} - fn regionSubDomain(allocator: std.mem.Allocator, service: []const u8, region: []const u8, useDualStack: bool) !EndPoint { const environment_override = std.os.getenv("AWS_ENDPOINT_URL"); if (environment_override) |override| {