Skip to content

Commit

Permalink
Windows support (#1919)
Browse files Browse the repository at this point in the history
* Remove the postinstall scripts and move precompiled tasks to executables in bin

* Adding windows to CI

* cleaning up some paths to differentiate between windows and not

* fixing another path in specs

* do all of the Path need to use .new....

* More work on making windows specs pass

* a few test for windows

* also ignore ameba.exe

* Fixing more specs for Windows
  • Loading branch information
jwoertink authored Oct 13, 2024
1 parent 8884d3b commit 382549a
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 81 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
fail-fast: false
runs-on: ubuntu-latest
continue-on-error: false
env:
SKIP_LUCKY_TASK_PRECOMPILATION: "1"
steps:
- uses: actions/checkout@v4
- uses: crystal-lang/install-crystal@v1
Expand All @@ -29,6 +27,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
shard_file:
- shard.yml
crystal_version:
Expand All @@ -40,19 +41,21 @@ jobs:
- shard_file: shard.edge.yml
crystal_version: latest
experimental: true
os: ubuntu-latest
- shard_file: shard.override.yml
crystal_version: nightly
experimental: true
runs-on: ubuntu-latest
os: ubuntu-latest
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
env:
SKIP_LUCKY_TASK_PRECOMPILATION: "1"
steps:
- uses: actions/checkout@v4
- uses: crystal-lang/install-crystal@v1
with:
crystal: ${{matrix.crystal_version}}
- name: Install shards
run: SHARDS_OVERRIDE=${{ matrix.shard_file }} shards install --ignore-crystal-version
run: shards install --skip-postinstall --skip-executables
env:
SHARDS_OVERRIDE: ${{ matrix.shard_file }}
- name: Run tests
run: crystal spec
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/docs/
/libs/
/lib/
/bin/
/bin/ameba
/bin/ameba.*
/tmp/
/.shards/
server
Expand Down
2 changes: 1 addition & 1 deletion src/precompiled_tasks/exec.cr → bin/lucky.exec.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../tasks/exec"
require "lucky/tasks/exec"

Lucky::Exec.new.print_help_or_call(ARGV)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../../../tasks/gen/action/api"
require "lucky/tasks/gen/action/api"

Gen::Action::Api.new.print_help_or_call(ARGV)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../../../tasks/gen/action/browser"
require "lucky/tasks/gen/action/browser"

Gen::Action::Browser.new.print_help_or_call(ARGV)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../../tasks/gen/component"
require "lucky/tasks/gen/component"

Gen::Component.new.print_help_or_call(ARGV)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../../tasks/gen/page"
require "lucky/tasks/gen/page"

Gen::Page.new.print_help_or_call(ARGV)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../../tasks/gen/secret_key"
require "lucky/tasks/gen/secret_key"

Gen::SecretKey.new.print_help_or_call(ARGV)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../../tasks/gen/task"
require "lucky/tasks/gen/task"

Gen::Task.new.print_help_or_call(ARGV)
2 changes: 1 addition & 1 deletion src/precompiled_tasks/watch.cr → bin/lucky.watch.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../tasks/watch"
require "lucky/tasks/watch"

Watch.new.print_help_or_call(ARGV)
17 changes: 0 additions & 17 deletions script/precompile_tasks

This file was deleted.

32 changes: 10 additions & 22 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,16 @@ crystal: ">= 1.10.0"
authors:
- Paul Smith <paulcsmith0218@gmail.com>

targets:
lucky.exec:
main: src/precompiled_tasks/exec.cr
lucky.watch:
main: src/precompiled_tasks/watch.cr
lucky.gen.action:
main: src/precompiled_tasks/gen/action/helpful_error.cr
lucky.gen.action.browser:
main: src/precompiled_tasks/gen/action/browser.cr
lucky.gen.action.api:
main: src/precompiled_tasks/gen/action/api.cr
lucky.gen.page:
main: src/precompiled_tasks/gen/page.cr
lucky.gen.component:
main: src/precompiled_tasks/gen/component.cr
lucky.gen.task:
main: src/precompiled_tasks/gen/task.cr
lucky.gen.secret_key:
main: src/precompiled_tasks/gen/secret_key.cr
executables:
- lucky.exec.cr
- lucky.watch.cr
- lucky.gen.action.cr
- lucky.gen.action.browser.cr
- lucky.gen.action.api.cr
- lucky.gen.page.cr
- lucky.gen.component.cr
- lucky.gen.task.cr
- lucky.gen.secret_key.cr

dependencies:
lucky_task:
Expand Down Expand Up @@ -63,7 +54,4 @@ development_dependencies:
github: crystal-ameba/ameba
version: ~> 1.5.0

scripts:
postinstall: BUILD_WITHOUT_DEVELOPMENT=true script/precompile_tasks

license: MIT
12 changes: 8 additions & 4 deletions spec/lucky/component_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ describe "components rendering" do
it "prints a comment when configured to do so" do
Lucky::HTMLPage.temp_config(render_component_comments: true) do
contents = TestMountPage.new(context_with_csrf).render.to_s
contents.should contain("<!-- BEGIN: ComplexTestComponent spec/lucky/component_spec.cr -->")
contents.should contain("<!-- BEGIN: ComplexTestComponent #{component_path} -->")
contents.should contain("<!-- END: ComplexTestComponent -->")
contents.should contain("<!-- BEGIN: ComponentWithBlock spec/lucky/component_spec.cr -->")
contents.should contain("<!-- BEGIN: ComponentWithBlock #{component_path} -->")
contents.should contain("<!-- END: ComponentWithBlock -->")
end
end
Expand All @@ -142,9 +142,9 @@ describe "components rendering" do
it "prints a comment when configured to do so" do
Lucky::HTMLPage.temp_config(render_component_comments: true) do
contents = TestMountInstancePage.new(build_context).render.to_s
contents.should contain("<!-- BEGIN: ComplexInstanceTestComponent spec/lucky/component_spec.cr -->")
contents.should contain("<!-- BEGIN: ComplexInstanceTestComponent #{component_path} -->")
contents.should contain("<!-- END: ComplexInstanceTestComponent -->")
contents.should contain("<!-- BEGIN: ComponentWithBlock spec/lucky/component_spec.cr -->")
contents.should contain("<!-- BEGIN: ComponentWithBlock #{component_path} -->")
contents.should contain("<!-- END: ComponentWithBlock -->")
end
end
Expand All @@ -158,6 +158,10 @@ describe "components rendering" do
end
end

private def component_path : String
Path.new("spec", "lucky", "component_spec.cr").to_s
end

private def context_with_csrf : HTTP::Server::Context
context = build_context
context.session.set(Lucky::ProtectFromForgery::SESSION_KEY, "my_token")
Expand Down
4 changes: 2 additions & 2 deletions spec/support/generator_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module GeneratorHelper

private def should_create_files_with_contents(io : IO, **files_and_contents)
files_and_contents.each do |file_location, file_contents|
File.read(file_location.to_s).should contain(file_contents)
io.to_s.should contain(file_location.to_s)
File.read(Path[file_location.to_s].normalize.to_s).should contain(file_contents)
io.to_s.should contain(Path[file_location.to_s].normalize.to_s)
end
end

Expand Down
16 changes: 10 additions & 6 deletions spec/tasks/exec_spec.cr
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
require "../spec_helper"

describe Lucky::Exec do
it "runs the editor" do
with_test_template do
Lucky::Exec.new.print_help_or_call(args: ["--once", "--editor", %(echo '5 + 5' >)])
{% if flag?(:win32) %}
pending "Cry on Windows needs updating"
{% else %}
it "runs the editor" do
with_test_template do
Lucky::Exec.new.print_help_or_call(args: ["--once", "--editor", %(echo '5 + 5' >)])

newest_code.should eq <<-CODE
newest_code.should eq <<-CODE
5 + 5
CODE
end
end
end
{% end %}
end

private def with_test_template(&)
Lucky::Exec.temp_config(template_path: "spec/support/exec_template.cr.template") do
Lucky::Exec.temp_config(template_path: Path["spec/support/exec_template.cr.template"].normalize.to_s) do
yield
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/tasks/gen/action_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe Gen::Action do
should_have_generated "#{valid_action_name} < BrowserAction", inside: filename

io.to_s.should contain(valid_action_name)
io.to_s.should contain("/src/actions/users")
io.to_s.should contain(Path["src/actions/users"].normalize.to_s)
end
end

Expand All @@ -29,8 +29,8 @@ describe Gen::Action do
should_have_generated "#{valid_action_name}Page < MainLayout", inside: page_filename

io.to_s.should contain(valid_action_name)
io.to_s.should contain("/src/actions/users")
io.to_s.should contain("/src/pages/users")
io.to_s.should contain(Path["src/actions/users"].normalize.to_s)
io.to_s.should contain(Path["src/pages/users"].normalize.to_s)
end
end

Expand All @@ -43,7 +43,7 @@ describe Gen::Action do
should_have_generated "#{valid_action_name} < ApiAction", inside: filename

io.to_s.should contain(valid_action_name)
io.to_s.should contain("/src/actions/api/users")
io.to_s.should contain(Path["src/actions/api/users"].normalize.to_s)
io.to_s.should contain("No page generated for ApiActions")
end
end
Expand All @@ -58,7 +58,7 @@ describe Gen::Action do
should_have_generated "#{valid_action_name} < ApiAction", inside: filename

io.to_s.should contain(valid_action_name)
io.to_s.should contain("/src/actions/api/users")
io.to_s.should contain(Path["src/actions/api/users"].normalize.to_s)
end
end

Expand All @@ -72,7 +72,7 @@ describe Gen::Action do
should_have_generated %(get "/users/announcements"), inside: filename

io.to_s.should contain(valid_nested_action_name)
io.to_s.should contain("/src/actions/users/announcements")
io.to_s.should contain(Path["src/actions/users/announcements"].normalize.to_s)
end

with_cleanup do
Expand All @@ -83,7 +83,7 @@ describe Gen::Action do
should_have_generated "#{valid_nested_action_name} < ApiAction", inside: filename

io.to_s.should contain(valid_nested_action_name)
io.to_s.should contain("/src/actions/api/users/announcements")
io.to_s.should contain(Path["src/actions/api/users/announcements"].normalize.to_s)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/tasks/gen/task_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe Gen::Task do
it "generates a task" do
with_cleanup do
output = run_with_args ["search.reindex"]
output.to_s.should contain("./tasks/search/reindex.cr")
output.to_s.should contain(Path["./tasks/search/reindex.cr"].normalize.to_s)
should_create_files_with_contents output,
"./tasks/search/reindex.cr": "Search::Reindex"
end
Expand Down
2 changes: 1 addition & 1 deletion src/lucky/base_component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract class Lucky::BaseComponent
# Returns the relative file location to the
# project root. e.g. src/components/my_component.cr
def self.file_location
__FILE__.gsub("#{Dir.current}/", "")
__FILE__.gsub(Dir.current, "").byte_slice(1)
end
end

Expand Down
3 changes: 1 addition & 2 deletions src/lucky/static_compression_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class Lucky::StaticCompressionHandler
def call(context)
original_path = context.request.path.to_s
request_path = URI.decode(original_path)
expanded_path = File.expand_path(request_path, "/")
file_path = File.join(@public_dir, expanded_path)
file_path = File.join(@public_dir, request_path)
compressed_path = "#{file_path}.#{@file_ext}"
content_type = MIME.from_filename(file_path, "application/octet-stream")

Expand Down
2 changes: 1 addition & 1 deletion tasks/exec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Lucky::Exec < LuckyTask::Task

Habitat.create do
setting editor : String = "vim"
setting template_path : String = "#{__DIR__}/exec_template.cr.template"
setting template_path : String = Path["#{__DIR__}/exec_template.cr.template"].normalize.to_s
end

def help_message
Expand Down
2 changes: 1 addition & 1 deletion tasks/gen/action/action_generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module Gen::ActionGenerator
end

private def output_path
Path["./src/actions/#{path}"]
Path["./src/actions/#{path}"].normalize
end

private def path
Expand Down
2 changes: 1 addition & 1 deletion tasks/gen/component.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Gen::Component < LuckyTask::Task
private def output_path
parts = component_class.split("::")
parts.pop
Path["./src/components/#{parts.map(&.underscore.downcase).join('/')}"]
Path["./src/components/#{parts.map(&.underscore.downcase).join('/')}"].normalize
end

private def output_path_with_filename
Expand Down
2 changes: 1 addition & 1 deletion tasks/gen/page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Gen::Page < LuckyTask::Task
private def output_path
page_parts = page_class.split("::")
page_parts.pop
Path["./src/pages/#{page_parts.map(&.underscore.downcase).join('/')}"]
Path["./src/pages/#{page_parts.map(&.underscore.downcase).join('/')}"].normalize
end

private def output_path_with_filename
Expand Down

0 comments on commit 382549a

Please sign in to comment.