From b820a1d0f9a2090f64e5563d35557abda929ba85 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol <990485+sdogruyol@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:30:26 +0300 Subject: [PATCH 1/2] Windows support MVP --- spec/helpers_spec.cr | 15 +++++++++++++-- spec/run_spec.cr | 9 +++++++-- spec/view_spec.cr | 6 +++++- src/kemal/config.cr | 2 +- src/kemal/static_file_handler.cr | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index ec587bb0..2e38914d 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -106,8 +106,14 @@ describe "Macros" do request = HTTP::Request.new("GET", "/") response = call_request_on_app(request) response.status_code.should eq(200) + response.headers["Content-Type"].should eq("application/octet-stream") - response.headers["Content-Length"].should eq("18") + + {% if flag?(:windows) %} + response.headers["Content-Length"].should eq("19") + {% else %} + response.headers["Content-Length"].should eq("18") + {% end %} end it "sends file with given path and given mime-type" do @@ -119,7 +125,12 @@ describe "Macros" do response = call_request_on_app(request) response.status_code.should eq(200) response.headers["Content-Type"].should eq("image/jpeg") - response.headers["Content-Length"].should eq("18") + + {% if flag?(:windows) %} + response.headers["Content-Length"].should eq("19") + {% else %} + response.headers["Content-Length"].should eq("18") + {% end %} end it "sends file with binary stream" do diff --git a/spec/run_spec.cr b/spec/run_spec.cr index a629eac3..c15a7e94 100644 --- a/spec/run_spec.cr +++ b/spec/run_spec.cr @@ -38,8 +38,13 @@ describe "Run" do Kemal.config.env = "test" Kemal.run do |config| server = config.server.not_nil! - server.bind_tcp "127.0.0.1", 3000, reuse_port: true - server.bind_tcp "0.0.0.0", 3001, reuse_port: true + + {% if flag?(:windows) %} + server.bind_tcp "127.0.0.1", 3000 + {% else %} + server.bind_tcp "127.0.0.1", 3000, reuse_port: true + server.bind_tcp "0.0.0.0", 3001, reuse_port: true + {% end %} end CR end diff --git a/spec/view_spec.cr b/spec/view_spec.cr index 79b87687..205f94fa 100644 --- a/spec/view_spec.cr +++ b/spec/view_spec.cr @@ -22,7 +22,11 @@ describe "Views" do end request = HTTP::Request.new("GET", "/view/world") client_response = call_request_on_app(request) - client_response.body.strip.should eq("Hello world\n") + {% if flag?(:windows) %} + client_response.body.strip.should eq("Hello world\r\n") + {% else %} + client_response.body.strip.should eq("Hello world\n") + {% end %} end it "renders layout" do diff --git a/src/kemal/config.cr b/src/kemal/config.cr index f728f57b..b079c7b1 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -1,5 +1,5 @@ module Kemal - VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }} + VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }} # Stores all the configuration options for a Kemal application. # It's a singleton and you can access it like. diff --git a/src/kemal/static_file_handler.cr b/src/kemal/static_file_handler.cr index 4f917669..3b4cf0ec 100644 --- a/src/kemal/static_file_handler.cr +++ b/src/kemal/static_file_handler.cr @@ -27,7 +27,7 @@ module Kemal return end - expanded_path = File.expand_path(request_path, "/") + expanded_path = request_path is_dir_path = if original_path.ends_with?('/') && !expanded_path.ends_with? '/' expanded_path = expanded_path + '/' true From 28c1b02bcb231d366d54735e4c8df76b2f3b17b1 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol <990485+sdogruyol@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:00:08 +0300 Subject: [PATCH 2/2] Update CI for Windows --- .gitattributes | 2 ++ .github/workflows/ci.yml | 47 +++++++++++++++++++++++++++++++++++----- spec/helpers_spec.cr | 14 ++---------- spec/view_spec.cr | 6 +---- 4 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..4bf9126f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.cr text eol=lf +*.ecr text eol=lf \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 983dc679..f473bda2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,31 +11,66 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] crystal: [latest, nightly] runs-on: ${{ matrix.os }} steps: - name: Install Crystal - uses: oprypin/install-crystal@v1 + uses: crystal-lang/install-crystal@v1 with: crystal: ${{ matrix.crystal }} - name: Download source - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install dependencies run: shards install - env: - SHARDS_OPTS: --ignore-crystal-version - name: Run specs run: | crystal spec - crystal spec --release --no-debug + + format: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + crystal: [latest, nightly] + runs-on: ${{ matrix.os }} + + steps: + - name: Install Crystal + uses: crystal-lang/install-crystal@v1 + with: + crystal: ${{ matrix.crystal }} + + - name: Download source + uses: actions/checkout@v4 - name: Check formatting run: crystal tool format --check + + ameba: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + crystal: [latest] + runs-on: ${{ matrix.os }} + + steps: + - name: Install Crystal + uses: crystal-lang/install-crystal@v1 + with: + crystal: ${{ matrix.crystal }} + + - name: Download source + uses: actions/checkout@v4 + + - name: Install dependencies + run: shards install - name: Run ameba linter run: bin/ameba + \ No newline at end of file diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index 2e38914d..334d4ccf 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -108,12 +108,7 @@ describe "Macros" do response.status_code.should eq(200) response.headers["Content-Type"].should eq("application/octet-stream") - - {% if flag?(:windows) %} - response.headers["Content-Length"].should eq("19") - {% else %} - response.headers["Content-Length"].should eq("18") - {% end %} + response.headers["Content-Length"].should eq("18") end it "sends file with given path and given mime-type" do @@ -125,12 +120,7 @@ describe "Macros" do response = call_request_on_app(request) response.status_code.should eq(200) response.headers["Content-Type"].should eq("image/jpeg") - - {% if flag?(:windows) %} - response.headers["Content-Length"].should eq("19") - {% else %} - response.headers["Content-Length"].should eq("18") - {% end %} + response.headers["Content-Length"].should eq("18") end it "sends file with binary stream" do diff --git a/spec/view_spec.cr b/spec/view_spec.cr index 205f94fa..79b87687 100644 --- a/spec/view_spec.cr +++ b/spec/view_spec.cr @@ -22,11 +22,7 @@ describe "Views" do end request = HTTP::Request.new("GET", "/view/world") client_response = call_request_on_app(request) - {% if flag?(:windows) %} - client_response.body.strip.should eq("Hello world\r\n") - {% else %} - client_response.body.strip.should eq("Hello world\n") - {% end %} + client_response.body.strip.should eq("Hello world\n") end it "renders layout" do