From b1dc086afb668345c5fddc41f5c4a68681d8f75e Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Thu, 14 Nov 2024 18:17:24 +0000 Subject: [PATCH] GH actions fixes Fix `/.json` root path detection --- .github/workflows/CI.yml | 12 ++++++------ cli/build.zig | 7 +------ cli/commands/database.zig | 2 -- src/jetzig/http/Path.zig | 20 ++++++++++++++++---- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 47a8a48..54f3b92 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,7 +28,7 @@ jobs: - name: Setup Zig # You may pin to the exact commit or the version. # uses: goto-bus-stop/setup-zig@41ae19e72e21b9a1380e86ff9f058db709fc8fc6 - uses: goto-bus-stop/setup-zig@v2.2.0 + uses: goto-bus-stop/setup-zig@v2 with: version: master cache: true # Let's see how this behaves @@ -40,7 +40,7 @@ jobs: run: zig build --verbose - name: Run Tests - run: zig build test + run: zig build test --summary all - name: Run App Tests run: | @@ -67,25 +67,25 @@ jobs: - name: Upload artifacts Target Windows if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: build-windows path: artifacts/x86_64-windows - name: Upload artifacts Target Linux if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: build-linux path: artifacts/x86_64-linux - name: Upload artifacts Target MacOS if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: build-macos-x86 path: artifacts/x86_64-macos - name: Upload artifacts Target MacOS 2 if: ${{ matrix.os == 'ubuntu-latest' && !contains(fromJSON('["pull_request"]'), github.event_name) }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: build-macos-aarch64 path: artifacts/aarch64-macos diff --git a/cli/build.zig b/cli/build.zig index 5e5fe0f..a0fc17f 100644 --- a/cli/build.zig +++ b/cli/build.zig @@ -20,13 +20,8 @@ pub fn build(b: *std.Build) !void { .jetquery_migrations_path = @as([]const u8, "src/app/database/migrations"), }); 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( - "init_data", - try compile.initDataModule(b), - ); + exe.root_module.addImport("init_data", try compile.initDataModule(b)); b.installArtifact(exe); diff --git a/cli/commands/database.zig b/cli/commands/database.zig index 38989ee..ca1c93c 100644 --- a/cli/commands/database.zig +++ b/cli/commands/database.zig @@ -1,8 +1,6 @@ const std = @import("std"); const args = @import("args"); -const jetquery = @import("jetquery"); -const Migrate = @import("jetquery_migrate"); const util = @import("../util.zig"); const cli = @import("../cli.zig"); diff --git a/src/jetzig/http/Path.zig b/src/jetzig/http/Path.zig index 0427e1d..442a288 100644 --- a/src/jetzig/http/Path.zig +++ b/src/jetzig/http/Path.zig @@ -17,8 +17,6 @@ resource_id: []const u8, extension: ?[]const u8, query: ?[]const u8, -// TODO: Fix edge case `/foo/bar/` <-- strip trailing slash. - const Self = @This(); /// Initialize a new HTTP Path. @@ -92,9 +90,12 @@ fn getBasePath(path: []const u8) []const u8 { return path[0..query_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 { - 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)" { 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); } +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)" { const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");