GH actions fixes

Fix `/.json` root path detection
This commit is contained in:
Bob Farrell 2024-11-14 18:17:24 +00:00
parent d9b5f7af63
commit b1dc086afb
4 changed files with 23 additions and 18 deletions

View File

@ -28,7 +28,7 @@ jobs:
- name: Setup Zig - name: Setup Zig
# You may pin to the exact commit or the version. # You may pin to the exact commit or the version.
# uses: goto-bus-stop/setup-zig@41ae19e72e21b9a1380e86ff9f058db709fc8fc6 # uses: goto-bus-stop/setup-zig@41ae19e72e21b9a1380e86ff9f058db709fc8fc6
uses: goto-bus-stop/setup-zig@v2.2.0 uses: goto-bus-stop/setup-zig@v2
with: with:
version: master version: master
cache: true # Let's see how this behaves cache: true # Let's see how this behaves
@ -40,7 +40,7 @@ jobs:
run: zig build --verbose run: zig build --verbose
- name: Run Tests - name: Run Tests
run: zig build test run: zig build test --summary all
- name: Run App Tests - name: Run App Tests
run: | run: |
@ -67,25 +67,25 @@ jobs:
- name: Upload artifacts Target Windows - name: Upload artifacts Target Windows
if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }}
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v4
with: with:
name: build-windows name: build-windows
path: artifacts/x86_64-windows path: artifacts/x86_64-windows
- name: Upload artifacts Target Linux - name: Upload artifacts Target Linux
if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }}
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v4
with: with:
name: build-linux name: build-linux
path: artifacts/x86_64-linux path: artifacts/x86_64-linux
- name: Upload artifacts Target MacOS - name: Upload artifacts Target MacOS
if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }}
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v4
with: with:
name: build-macos-x86 name: build-macos-x86
path: artifacts/x86_64-macos path: artifacts/x86_64-macos
- name: Upload artifacts Target MacOS 2 - name: Upload artifacts Target MacOS 2
if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }}
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v4
with: with:
name: build-macos-aarch64 name: build-macos-aarch64
path: artifacts/aarch64-macos path: artifacts/aarch64-macos

View File

@ -20,13 +20,8 @@ pub fn build(b: *std.Build) !void {
.jetquery_migrations_path = @as([]const u8, "src/app/database/migrations"), .jetquery_migrations_path = @as([]const u8, "src/app/database/migrations"),
}); });
exe.root_module.addImport("jetquery", jetquery_dep.module("jetquery")); exe.root_module.addImport("jetquery", jetquery_dep.module("jetquery"));
exe.root_module.addImport("jetquery_migrate", jetquery_dep.module("jetquery_migrate"));
exe.root_module.addImport("args", zig_args_dep.module("args")); exe.root_module.addImport("args", zig_args_dep.module("args"));
exe.root_module.addImport( exe.root_module.addImport("init_data", try compile.initDataModule(b));
"init_data",
try compile.initDataModule(b),
);
b.installArtifact(exe); b.installArtifact(exe);

View File

@ -1,8 +1,6 @@
const std = @import("std"); const std = @import("std");
const args = @import("args"); const args = @import("args");
const jetquery = @import("jetquery");
const Migrate = @import("jetquery_migrate");
const util = @import("../util.zig"); const util = @import("../util.zig");
const cli = @import("../cli.zig"); const cli = @import("../cli.zig");

View File

@ -17,8 +17,6 @@ resource_id: []const u8,
extension: ?[]const u8, extension: ?[]const u8,
query: ?[]const u8, query: ?[]const u8,
// TODO: Fix edge case `/foo/bar/` <-- strip trailing slash.
const Self = @This(); const Self = @This();
/// Initialize a new HTTP Path. /// Initialize a new HTTP Path.
@ -92,9 +90,12 @@ fn getBasePath(path: []const u8) []const u8 {
return path[0..query_index]; return path[0..query_index];
} }
} else if (std.mem.lastIndexOfScalar(u8, path, '.')) |extension_index| { } else if (std.mem.lastIndexOfScalar(u8, path, '.')) |extension_index| {
return if (std.mem.eql(u8, path, "/")) path else std.mem.trimRight(u8, path[0..extension_index], "/"); return if (isRootPath(path[0..extension_index]))
path[0..extension_index]
else
std.mem.trimRight(u8, path[0..extension_index], "/");
} else { } else {
return if (std.mem.eql(u8, path, "/")) path else std.mem.trimRight(u8, path, "/"); return if (isRootPath(path)) path else std.mem.trimRight(u8, path, "/");
} }
} }
@ -163,6 +164,10 @@ fn getQuery(path: []const u8) ?[]const u8 {
} }
} }
inline fn isRootPath(path: []const u8) bool {
return std.mem.eql(u8, path, "/");
}
test ".base_path (with extension, with query)" { test ".base_path (with extension, with query)" {
const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault"); const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");
@ -193,6 +198,13 @@ test ".base_path (root path)" {
try std.testing.expectEqualStrings("/", path.base_path); try std.testing.expectEqualStrings("/", path.base_path);
} }
test ".base_path (root path with extension)" {
const path = Self.init("/.json");
try std.testing.expectEqualStrings("/", path.base_path);
try std.testing.expectEqualStrings(".json", path.extension.?);
}
test ".directory (with extension, with query)" { test ".directory (with extension, with query)" {
const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault"); const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");