Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ci/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ flexapp_build_linux:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
services:
- name: docker:28.5.1-dind
- name: docker:29.1.3-dind
alias: docker
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG =~ /^v/'
Expand All @@ -35,7 +35,7 @@ flexapp_build_windows:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
services:
- name: docker:28.5.1-dind
- name: docker:29.1.3-dind
alias: docker
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG =~ /^v/'
Expand Down
2 changes: 0 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"mads-hartmann.bash-ide-vscode",
"aaron-bond.better-comments",
"ms-azuretools.vscode-docker",
"ms-python.debugpy",
"ms-python.python",
"ms-python.vscode-pylance",
"tamasfe.even-better-toml",
"waderyan.gitblame",
"PKief.material-icon-theme",
Expand Down
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ flexapp_testing:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
services:
- name: docker:28.5.1-dind
- name: docker:29.1.3-dind
alias: docker
rules:
- if: $CI_COMMIT_TAG =~ /^release-.*/
Expand All @@ -33,7 +33,7 @@ flexapp_build_linux:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
services:
- name: docker:28.5.1-dind
- name: docker:29.1.3-dind
alias: docker
rules:
- if: $CI_COMMIT_TAG =~ /^release-.*/
Expand All @@ -55,12 +55,12 @@ flexapp_build_linux:

flexapp_build_windows:
stage: build
image: docker:28.5.1-dind
image: docker:29.1.3-dind
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
services:
- name: docker:28.5.1-dind
- name: docker:29.1.3-dind
alias: docker
rules:
- if: $CI_COMMIT_TAG =~ /^release-.*/
Expand Down
2 changes: 0 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"waderyan.gitblame",
"mads-hartmann.bash-ide-vscode",
"ms-azuretools.vscode-containers",
"ms-python.debugpy",
"ms-python.python",
"ms-python.vscode-pylance",
"pkief.material-icon-theme",
"tamasfe.even-better-toml",
"yzhang.markdown-all-in-one",
Expand Down
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[hooks]

[settings]
auto_install = false
activate_aggressive = true
aqua.cosign = false
aqua.slsa = false
Expand Down
9 changes: 9 additions & 0 deletions src/download.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const std = @import("std");
const helper = @import("helper.zig");
const testing = std.testing;

pub fn download(allocator: std.mem.Allocator, url: []const u8) ![]const u8 {
std.debug.print("{s} {s}\n", .{ "Starting download for", url });

Expand Down Expand Up @@ -91,6 +93,13 @@ pub fn download(allocator: std.mem.Allocator, url: []const u8) ![]const u8 {
return filename_final;
}

test "checking failed download" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
try testing.expect(std.mem.eql(u8, try download(allocator, "https://durrrrr.io"), "unknown.txt"));
}

test "download function" {
const testing_allocator = std.testing.allocator;

Expand Down
101 changes: 101 additions & 0 deletions src/execute.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const std = @import("std");
const helper = @import("helper.zig");
const testing = std.testing;
const main = @import("main.zig");
const builtin = @import("builtin");

pub const ExecuteError = error{
InstallerNotFound,
FpaPackagerNotFound,
ProcessFailed,
} || std.process.Child.RunError || std.mem.Allocator.Error || std.fs.File.OpenError;

pub fn execute(name: []const u8, package_version: []const u8, output: []const u8, installer: []const u8, extra: anytype) ExecuteError![]const u8 {
// std.debug.print("{s}\n", .{name});
if (!(try helper.test_file_path(installer))) {
std.debug.print("{s} not found...\n", .{installer});
return ExecuteError.InstallerNotFound;
}
const path = "C:\\program files (x86)\\Liquidware Labs\\FlexApp Packaging Automation\\fpa-packager.exe";
if (!(try helper.test_file_path(path))) {
std.debug.print("{s}\n", .{"fpa-packager.exe not found..."});
return ExecuteError.FpaPackagerNotFound;
}
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();

var list: std.ArrayList([]const u8) = .empty;
defer list.deinit(allocator);

try list.append(allocator, path);
try list.append(allocator, "package");
try list.append(allocator, "/Name");
try list.append(allocator, name);
try list.append(allocator, "/PackageVersion");
try list.append(allocator, package_version);
try list.append(allocator, "/Path");
try list.append(allocator, output);
try list.append(allocator, "/Installer");
try list.append(allocator, installer);
try list.append(allocator, "/NoSystemRestore");

var list2: std.ArrayList([]const u8) = .empty;
defer list2.deinit(allocator);
for (extra) |pos| {
try list2.append(allocator, pos);
}
if (list2.items.len != 0) {
try list.append(allocator, "/InstallerArgs");
for (list2.items) |n|
try list.append(allocator, n);
}

const result = try std.process.Child.run(.{
.allocator = allocator,
.argv = try list.toOwnedSlice(allocator),
.max_output_bytes = 500 * 1024,
});
defer {
allocator.free(result.stdout);
allocator.free(result.stderr);
}
switch (result.term) {
.Exited => |code| {
if (code == 0) {
std.debug.print("Output:\nSuccess Code: {}\n", .{code});
return "Success";
} else {
std.debug.print("Process failed with code: {}\n", .{code});
return ExecuteError.ProcessFailed;
}
},
.Signal => |sig| {
std.debug.print("Process terminated by signal: {}\n", .{sig});
return ExecuteError.ProcessFailed;
},
.Stopped => |sig| {
std.debug.print("Process stopped by signal: {}\n", .{sig});
return ExecuteError.ProcessFailed;
},
.Unknown => |code| {
std.debug.print("Process terminated with unknown status: {}\n", .{code});
return ExecuteError.ProcessFailed;
},
}
}

test "checking failed execute installer not found" {
const result = execute("", "", "", "test", .{});
try testing.expectError(ExecuteError.InstallerNotFound, result);
}

test "checking failed execute fpa not found" {
if (builtin.os.tag == .windows) {
const result = execute("", "", "", "C:/Windows/System32/drivers/etc/hosts", .{});
try testing.expectError(ExecuteError.FpaPackagerNotFound, result);
} else {
const result = execute("", "", "", "/etc/hosts", .{});
try testing.expectError(ExecuteError.FpaPackagerNotFound, result);
}
}
82 changes: 1 addition & 81 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const clap = @import("clap");
const std = @import("std");
const helper = @import("helper.zig");
const download = @import("download.zig").download;
const execute = @import("execute.zig").execute;

const Version = struct {
major: u16,
Expand Down Expand Up @@ -116,87 +117,6 @@ pub fn main() !void {
}
}

pub const ExecuteError = error{
InstallerNotFound,
FpaPackagerNotFound,
ProcessFailed,
} || std.process.Child.RunError || std.mem.Allocator.Error || std.fs.File.OpenError;

pub fn execute(name: []const u8, package_version: []const u8, output: []const u8, installer: []const u8, extra: anytype) ExecuteError![]const u8 {
// std.debug.print("{s}\n", .{name});
if (!(try helper.test_file_path(installer))) {
std.debug.print("{s} not found...\n", .{installer});
return ExecuteError.InstallerNotFound;
}
const path = "C:\\program files (x86)\\Liquidware Labs\\FlexApp Packaging Automation\\fpa-packager.exe";
if (!(try helper.test_file_path(path))) {
std.debug.print("{s}\n", .{"fpa-packager.exe not found..."});
return ExecuteError.FpaPackagerNotFound;
}
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();

var list: std.ArrayList([]const u8) = .empty;
defer list.deinit(allocator);

try list.append(allocator, path);
try list.append(allocator, "package");
try list.append(allocator, "/Name");
try list.append(allocator, name);
try list.append(allocator, "/PackageVersion");
try list.append(allocator, package_version);
try list.append(allocator, "/Path");
try list.append(allocator, output);
try list.append(allocator, "/Installer");
try list.append(allocator, installer);
try list.append(allocator, "/NoSystemRestore");

var list2: std.ArrayList([]const u8) = .empty;
defer list2.deinit(allocator);
for (extra) |pos| {
try list2.append(allocator, pos);
}
if (list2.items.len != 0) {
try list.append(allocator, "/InstallerArgs");
for (list2.items) |n|
try list.append(allocator, n);
}

const result = try std.process.Child.run(.{
.allocator = allocator,
.argv = try list.toOwnedSlice(allocator),
.max_output_bytes = 500 * 1024,
});
defer {
allocator.free(result.stdout);
allocator.free(result.stderr);
}
switch (result.term) {
.Exited => |code| {
if (code == 0) {
std.debug.print("Output:\nSuccess Code: {}\n", .{code});
return "Success";
} else {
std.debug.print("Process failed with code: {}\n", .{code});
return ExecuteError.ProcessFailed;
}
},
.Signal => |sig| {
std.debug.print("Process terminated by signal: {}\n", .{sig});
return ExecuteError.ProcessFailed;
},
.Stopped => |sig| {
std.debug.print("Process stopped by signal: {}\n", .{sig});
return ExecuteError.ProcessFailed;
},
.Unknown => |code| {
std.debug.print("Process terminated with unknown status: {}\n", .{code});
return ExecuteError.ProcessFailed;
},
}
}

fn build_package(name: []const u8, package_version: []const u8, output: []const u8, installer: []const u8, extra: anytype) !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
Expand Down
29 changes: 6 additions & 23 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ const testing = std.testing;
const main = @import("main.zig");
const helper = @import("helper.zig");
const builtin = @import("builtin");
const download = @import("download.zig").download;

export fn add(a: i32, b: i32) i32 {
return a + b;
}

test "basic add functionality" {
try testing.expect(add(3, 7) == 10);
test {
@import("std").testing.refAllDecls(@This());
_ = @import("./download.zig");
_ = @import("./execute.zig");
}

test "checking failed download" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
try testing.expect(std.mem.eql(u8, try download(allocator, "https://durrrrr.io"), "unknown.txt"));
test "basic add functionality" {
try testing.expect(add(3, 7) == 10);
}

test "checking replacer" {
Expand Down Expand Up @@ -72,21 +70,6 @@ test "checking concat" {
try testing.expect(std.mem.eql(u8, check, "test.txt"));
}

test "checking failed execute installer not found" {
const result = main.execute("", "", "", "test", .{});
try testing.expectError(main.ExecuteError.InstallerNotFound, result);
}

test "checking failed execute fpa not found" {
if (builtin.os.tag == .windows) {
const result = main.execute("", "", "", "C:/Windows/System32/drivers/etc/hosts", .{});
try testing.expectError(main.ExecuteError.FpaPackagerNotFound, result);
} else {
const result = main.execute("", "", "", "/etc/hosts", .{});
try testing.expectError(main.ExecuteError.FpaPackagerNotFound, result);
}
}

test "replace all function" {
const allocator = std.testing.allocator;

Expand Down