From 95a6e9325d37c4bfb72917d83d3246d6b17898cb Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 17 May 2022 17:52:09 -0400 Subject: [PATCH 01/32] Changed discord as the primary way to get in touch with the comminuty --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fc82985c..7aa842689 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Amber borrows concepts that have already been battle tested and successful, and ## Community -Questions? Join our IRC channel [#amber](https://webchat.freenode.net/?channels=#amber) or [Gitter room](https://gitter.im/amberframework/amber) or ask on Stack Overflow under the [amber-framework](https://stackoverflow.com/questions/tagged/amber-framework) tag. +Questions? Join our [Discord](https://discord.gg/7hcPbC9t8Y). Guidelines? We have adopted the Contributor Covenant to be our [CODE OF CONDUCT](.github/CODE_OF_CONDUCT.md) for Amber. From 7462cc193268f9082ffbe3b92ddb15cab1ad6543 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 17 May 2022 18:20:36 -0400 Subject: [PATCH 02/32] Changed the discord link so that it uses a permanent invite link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7aa842689..920d97289 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Amber borrows concepts that have already been battle tested and successful, and ## Community -Questions? Join our [Discord](https://discord.gg/7hcPbC9t8Y). +Questions? Join our [Discord](https://discord.gg/vwvP5zakSn). Guidelines? We have adopted the Contributor Covenant to be our [CODE OF CONDUCT](.github/CODE_OF_CONDUCT.md) for Amber. From 72d9e6b1b6ecfbf1d4098fab235ffbe8fa3d2ceb Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 17 May 2022 19:03:34 -0400 Subject: [PATCH 03/32] Fixed the version number being out dated from the actual latest release number. --- src/amber/version.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amber/version.cr b/src/amber/version.cr index 1403f7718..c6eb8df01 100644 --- a/src/amber/version.cr +++ b/src/amber/version.cr @@ -1,3 +1,3 @@ module Amber - VERSION = "1.0.0rc2" + VERSION = "1.2.1" end From 5cf7631033a8ce3ab3b3da9370b506e617b5482b Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:09:57 -0400 Subject: [PATCH 04/32] Make default package support older and newer versions of node-sass --- src/amber/cli/templates/app/package.json.ecr | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/amber/cli/templates/app/package.json.ecr b/src/amber/cli/templates/app/package.json.ecr index b8282a501..a3b680617 100644 --- a/src/amber/cli/templates/app/package.json.ecr +++ b/src/amber/cli/templates/app/package.json.ecr @@ -20,8 +20,13 @@ "file-loader": "^6.2.0", "html-webpack-plugin": "^5.3.1", "mini-css-extract-plugin": "^1.6.0", + <% if `node -v`.matches?(/v14|v16/) -%> "node-sass": "^5.0.0", "sass-loader": "^11.0.1", + <% else -%> + "node-sass": "^7.0.0", + "sass-loader": "^13.0.2", + <% end -%> "webpack": "^5.36.2", "webpack-cli": "^4.6.0", "webpack-merge": "^5.7.3" From aa1941e9b2f918cec0f9da3b924aebc7db516a8c Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:10:24 -0400 Subject: [PATCH 05/32] Bump amber version and update Ameba version --- .ameba.yml | 3 +++ shard.yml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .ameba.yml diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 000000000..664da22b2 --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,3 @@ +Excluded: + - tmp/ + - myapp/ \ No newline at end of file diff --git a/shard.yml b/shard.yml index cdba2d9dd..0b716c832 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: amber -version: 1.2.1 +version: 1.3.0 authors: - Amber Team and Contributors @@ -85,4 +85,4 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba - version: ~> 0.13.4 + version: ~> 1.0.0 From 733152af3439c9991db169ad35fa8a13e592e354 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:10:39 -0400 Subject: [PATCH 06/32] Added github actions for CI instead of TravisCI --- .github/workflows/ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..782339793 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +on: + push: +jobs: + build: + runs-on: ubuntu-latest + + container: + image: crystallang/crystal + + steps: + - name: Download source + uses: actions/checkout@v3 + + - name: Install shards + run: shards install + + - name: Run tests + run: bin/amber_spec \ No newline at end of file From 84acb1a9e284b82cdea9c52ccd37ff4a5b44ca33 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:10:52 -0400 Subject: [PATCH 07/32] Amber version bump for these quality of life updates --- src/amber/version.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amber/version.cr b/src/amber/version.cr index be5790c98..bc3427afb 100644 --- a/src/amber/version.cr +++ b/src/amber/version.cr @@ -1,3 +1,3 @@ module Amber - VERSION = "1.2.2" + VERSION = "1.3.0" end From 5ddc56e4869d837311e521f4a8c25b3b4f642e0f Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:11:21 -0400 Subject: [PATCH 08/32] Fix naming warning raised by crystal compiler about positional names being mismatched --- src/amber/router/session/abstract_store.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amber/router/session/abstract_store.cr b/src/amber/router/session/abstract_store.cr index 88f765198..1b79819cb 100644 --- a/src/amber/router/session/abstract_store.cr +++ b/src/amber/router/session/abstract_store.cr @@ -3,7 +3,7 @@ module Amber::Router::Session abstract class AbstractStore abstract def id abstract def destroy - abstract def update(other_hash : Hash(String | Symbol, String)) + abstract def update(hash : Hash(String | Symbol, String)) abstract def set_session abstract def current_session end From 1cb910dfdf36eb78a7b9f4db07b58ae81c59604d Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:18:22 -0400 Subject: [PATCH 09/32] removed the travisCI yml --- src/amber/cli/templates/app/.travis.yml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/amber/cli/templates/app/.travis.yml diff --git a/src/amber/cli/templates/app/.travis.yml b/src/amber/cli/templates/app/.travis.yml deleted file mode 100644 index 846a2fbc7..000000000 --- a/src/amber/cli/templates/app/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: crystal - -script: - - crystal spec - - crystal tool format --check - - bin/ameba From 5287e420d6dc681a18525e6dede147d3077c7a27 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 10:51:27 -0400 Subject: [PATCH 10/32] Fixed amber_spec cookie naming error that relied on old implicit encoding/decoding of cooke name & value --- src/amber/router/cookies/store.cr | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/amber/router/cookies/store.cr b/src/amber/router/cookies/store.cr index 6016cfe69..3caf69f12 100644 --- a/src/amber/router/cookies/store.cr +++ b/src/amber/router/cookies/store.cr @@ -90,6 +90,10 @@ module Amber::Router::Cookies expires : Time? = nil, domain : String? = nil, secure : Bool = false, http_only : Bool = false, extension : String? = nil) + + name = URI.encode_www_form(name) + value = URI.encode_www_form(value) + if @cookies[name]? != value || expires @cookies[name] = value @set_cookies[name] = HTTP::Cookie.new(name, value, path, expires, domain, secure, http_only, extension) From 167b620ed02b8b8b979531642548323a804139d3 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 12:22:38 -0400 Subject: [PATCH 11/32] Fixed areas that ameba caught for format improvements --- shard.yml | 2 +- spec/amber/cli/commands/pipelines/pipelines_spec.cr | 2 +- spec/amber/cli/commands/routes/routes_spec.cr | 6 +++--- src/amber/cli/commands/exec.cr | 2 +- src/amber/cli/commands/pipelines.cr | 4 ++-- src/amber/cli/commands/plugin.cr | 2 +- src/amber/cli/commands/routes.cr | 2 +- src/amber/cli/helpers/process_runner.cr | 2 +- src/amber/cli/recipes/scaffold/controller.cr | 2 +- src/amber/cli/recipes/scaffold/view.cr | 2 +- src/amber/controller/helpers/responders.cr | 2 +- src/amber/pipes/cors.cr | 8 ++++---- src/amber/router/cookies/store.cr | 1 - src/amber/websockets/client_socket.cr | 2 +- 14 files changed, 19 insertions(+), 20 deletions(-) diff --git a/shard.yml b/shard.yml index 0b716c832..e4bcb95dc 100644 --- a/shard.yml +++ b/shard.yml @@ -52,7 +52,7 @@ dependencies: redis: github: stefanwille/crystal-redis - version: ~> 2.7.0 + version: ~> 2.8.0 shell-table: github: luckyframework/shell-table.cr diff --git a/spec/amber/cli/commands/pipelines/pipelines_spec.cr b/spec/amber/cli/commands/pipelines/pipelines_spec.cr index 83b1d0208..4b5e1c482 100644 --- a/spec/amber/cli/commands/pipelines/pipelines_spec.cr +++ b/spec/amber/cli/commands/pipelines/pipelines_spec.cr @@ -59,7 +59,7 @@ module Amber::CLI end pipe_plugs.each do |pipe_name, plugs| - output_plugs = output_lines.select { |line| line.includes?(pipe_name) } + output_plugs = output_lines.select(&.includes?(pipe_name)) plugs.each_with_index do |plug, index| output_plug = output_plugs[index] (output_plug != nil).should be_true diff --git a/spec/amber/cli/commands/routes/routes_spec.cr b/spec/amber/cli/commands/routes/routes_spec.cr index 95d95f6c1..50cc44835 100644 --- a/spec/amber/cli/commands/routes/routes_spec.cr +++ b/spec/amber/cli/commands/routes/routes_spec.cr @@ -24,7 +24,7 @@ module Amber::CLI expected = "Amber::Controller::Static" output.should contain expected - line = output_lines.find("") { |this_line| this_line.includes? expected } + line = output_lines.find("", &.includes?(expected)) expectations = %w(get Amber::Controller::Static index static /*) expectations.each do |expectation| line.should contain expectation @@ -32,7 +32,7 @@ module Amber::CLI expected = "HomeController" output.should contain expected - line = output_lines.find("") { |this_line| this_line.includes? expected } + line = output_lines.find("", &.includes?(expected)) expectations = %w(get HomeController index web /) expectations.each do |expectation| line.should contain expectation @@ -77,7 +77,7 @@ module Amber::CLI expected = "websocket" output.should contain expected - line = output_lines.find("") { |this_line| this_line.includes? expected } + line = output_lines.find("", &.includes?(expected)) expectations = %w(websocket ElectricSocket web /electric) expectations.each do |expectation| line.should contain expectation diff --git a/src/amber/cli/commands/exec.cr b/src/amber/cli/commands/exec.cr index 6d87d7921..ad24a1323 100644 --- a/src/amber/cli/commands/exec.cr +++ b/src/amber/cli/commands/exec.cr @@ -32,7 +32,7 @@ module Amber::CLI _filename = if File.exists?(args.code) args.code elsif options.back.to_i(strict: false) > 0 - Dir.glob("./tmp/*_console.cr").sort.reverse[options.back.to_i(strict: false) - 1]? + Dir.glob("./tmp/*_console.cr").sort.reverse![options.back.to_i(strict: false) - 1]? end system("cp #{_filename} #{@filename}") if _filename diff --git a/src/amber/cli/commands/pipelines.cr b/src/amber/cli/commands/pipelines.cr index a15a07735..a4dc770b2 100644 --- a/src/amber/cli/commands/pipelines.cr +++ b/src/amber/cli/commands/pipelines.cr @@ -88,7 +88,7 @@ module Amber::CLI match = line.match(PIPELINE_REGEX) if match && (pipes = match[1]) - pipes = pipes.split(/,\s*/).map { |s| s.gsub(/[:\"]/, "") } + pipes = pipes.split(/,\s*/).map(&.gsub(/[:\"]/, "")) result << {pipes: pipes, plugs: [] of String} else raise BadRoutesException.new(FAILED_TO_PARSE_ERROR) @@ -113,7 +113,7 @@ module Amber::CLI table.border_color = :dark_gray unless options.no_color? if options.no_plugs? - result.map { |pipes_and_plugs| pipes_and_plugs[:pipes] }.flatten.uniq.each do |pipe| + result.flat_map { |pipes_and_plugs| pipes_and_plugs[:pipes] }.uniq!.each do |pipe| row = table.add_row row.add_column(pipe) end diff --git a/src/amber/cli/commands/plugin.cr b/src/amber/cli/commands/plugin.cr index 9101513cf..edb7fc9df 100644 --- a/src/amber/cli/commands/plugin.cr +++ b/src/amber/cli/commands/plugin.cr @@ -25,7 +25,7 @@ module Amber::CLI if Amber::Plugins::Plugin.can_generate?(args.name) template = Amber::Plugins::Plugin.new(args.name, "./src/plugins", options.args) - template.generate (options.uninstall? ? "uninstall" : "install") + template.generate(options.uninstall? ? "uninstall" : "install") end end diff --git a/src/amber/cli/commands/routes.cr b/src/amber/cli/commands/routes.cr index c1f4bb26a..d8244a3c0 100644 --- a/src/amber/cli/commands/routes.cr +++ b/src/amber/cli/commands/routes.cr @@ -126,7 +126,7 @@ module Amber::CLI private def print_routes_table_json puts routes.map { |route| - route.transform_keys { |key| key.to_s.downcase.gsub(' ', '_') } + route.transform_keys(&.to_s.downcase.gsub(' ', '_')) }.to_json end diff --git a/src/amber/cli/helpers/process_runner.cr b/src/amber/cli/helpers/process_runner.cr index 08ae839d9..1b753a516 100644 --- a/src/amber/cli/helpers/process_runner.cr +++ b/src/amber/cli/helpers/process_runner.cr @@ -79,7 +79,7 @@ module Sentry private def check_processes @processes.each do |task, procs| # clean up process list and restart if terminated - if procs.any? + if !procs.empty? procs.reject!(&.terminated?) if procs.empty? diff --git a/src/amber/cli/recipes/scaffold/controller.cr b/src/amber/cli/recipes/scaffold/controller.cr index 846761aa7..027c6fc87 100644 --- a/src/amber/cli/recipes/scaffold/controller.cr +++ b/src/amber/cli/recipes/scaffold/controller.cr @@ -24,7 +24,7 @@ module Amber::Recipes::Scaffold @fields += %w(created_at:time updated_at:time).map do |f| Amber::CLI::Field.new(f, hidden: true, database: @database) end - @visible_fields = @fields.reject { |f| f.hidden } + @visible_fields = @fields.reject(&.hidden) field_hash @template = RecipeFetcher.new("scaffold", @recipe).fetch diff --git a/src/amber/cli/recipes/scaffold/view.cr b/src/amber/cli/recipes/scaffold/view.cr index 2eab38424..d1aa4879c 100644 --- a/src/amber/cli/recipes/scaffold/view.cr +++ b/src/amber/cli/recipes/scaffold/view.cr @@ -21,7 +21,7 @@ module Amber::Recipes::Scaffold Amber::CLI::Field.new(f, hidden: true, database: @database) end - @visible_fields = @fields.reject { |f| f.hidden } + @visible_fields = @fields.reject(&.hidden) @template = RecipeFetcher.new("scaffold", @recipe).fetch unless @template.nil? diff --git a/src/amber/controller/helpers/responders.cr b/src/amber/controller/helpers/responders.cr index 5abe63606..b5e919a0c 100644 --- a/src/amber/controller/helpers/responders.cr +++ b/src/amber/controller/helpers/responders.cr @@ -90,7 +90,7 @@ module Amber::Controller::Helpers accept = context.request.headers["Accept"]? if accept && !accept.empty? accepts = accept.split(";").first?.try(&.split(Content::ACCEPT_SEPARATOR_REGEX)) - return accepts if !accepts.nil? && accepts.any? + return accepts if !accepts.nil? && !accepts.empty? end end diff --git a/src/amber/pipes/cors.cr b/src/amber/pipes/cors.cr index 9dd3b571b..76814f91a 100644 --- a/src/amber/pipes/cors.cr +++ b/src/amber/pipes/cors.cr @@ -63,7 +63,7 @@ module Amber private def put_response_headers(response) response.headers[Headers::ALLOW_CREDENTIALS] = @credentials.to_s if @credentials response.headers[Headers::ALLOW_ORIGIN] = @origin.request_origin.not_nil! - response.headers[Headers::VARY] = vary unless @origin.any? + response.headers[Headers::VARY] = vary if @origin.empty? end private def vary @@ -122,7 +122,7 @@ module Amber def match?(request) return false if @origins.empty? return false unless origin_header?(request) - return true if any? + return true if !empty? @origins.any? do |origin| case origin @@ -132,8 +132,8 @@ module Amber end end - def any? - @origins.includes? "*" + def empty? + !@origins.includes? "*" end protected def origin_header?(request) diff --git a/src/amber/router/cookies/store.cr b/src/amber/router/cookies/store.cr index 3caf69f12..1f0a455ae 100644 --- a/src/amber/router/cookies/store.cr +++ b/src/amber/router/cookies/store.cr @@ -90,7 +90,6 @@ module Amber::Router::Cookies expires : Time? = nil, domain : String? = nil, secure : Bool = false, http_only : Bool = false, extension : String? = nil) - name = URI.encode_www_form(name) value = URI.encode_www_form(value) diff --git a/src/amber/websockets/client_socket.cr b/src/amber/websockets/client_socket.cr index 17fb0d818..f7a77de47 100644 --- a/src/amber/websockets/client_socket.cr +++ b/src/amber/websockets/client_socket.cr @@ -45,7 +45,7 @@ module Amber def self.get_topic_channel(topic_path) topic_channels = @@channels.select { |ch| WebSockets.topic_path(ch[:path]) == topic_path } - return topic_channels[0][:channel] if topic_channels.any? + return topic_channels[0][:channel] if !topic_channels.empty? end # Broadcast a message to all subscribers of the topic From 05139bb0302ec282b09f3aa2c2284a638fb343d2 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 12:37:09 -0400 Subject: [PATCH 12/32] Changed ubuntu to an older version instead of latest --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 782339793..04802998c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ on: push: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 container: image: crystallang/crystal From 1d52c9dd7a47ef8b8f160e2d9fa5ce34f02163fb Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 12:42:00 -0400 Subject: [PATCH 13/32] Changed ci workflow to remove an extra sqlite3 dev library that may be causing issues --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04802998c..f591ffa85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,12 +2,14 @@ on: push: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest container: image: crystallang/crystal steps: + - name: Remove sqllite3 dev library + run: sudo apt uninstall libsqlite3-dev - name: Download source uses: actions/checkout@v3 From 34e853652d0d5501ce4b570471280983c9dd3865 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 12:43:54 -0400 Subject: [PATCH 14/32] Changed from uninstall to install to fix sqlite3 issue --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f591ffa85..38e4f592d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,8 @@ jobs: image: crystallang/crystal steps: - - name: Remove sqllite3 dev library - run: sudo apt uninstall libsqlite3-dev + - name: Install sqllite3 dev library + run: apt install libsqlite3-dev - name: Download source uses: actions/checkout@v3 From 02674c7fc91c1220e6507bc9287e2203f393c547 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 13:06:39 -0400 Subject: [PATCH 15/32] Changed installation of sqlite3 based on further reading --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38e4f592d..3a5b5eded 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,9 @@ jobs: image: crystallang/crystal steps: - - name: Install sqllite3 dev library - run: apt install libsqlite3-dev + - name: Update & install sqlite3 + run: apt update && apt install sqlite3 + - name: Download source uses: actions/checkout@v3 From 0cd0a5302c201195a0bc4024174ed50b68c5f377 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 13:07:57 -0400 Subject: [PATCH 16/32] Set apt install to automatically agree to prompts --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a5b5eded..9f8732d0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,8 @@ jobs: steps: - name: Update & install sqlite3 - run: apt update && apt install sqlite3 - + run: apt update && apt install -y sqlite3 + - name: Download source uses: actions/checkout@v3 From 9cac5401da669f22ad95374fd65a0b5e1d4933d7 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 13:15:34 -0400 Subject: [PATCH 17/32] changed packed installed from full sqlite3 to sqlite3-dev --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f8732d0f..bca9c9c93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Update & install sqlite3 - run: apt update && apt install -y sqlite3 + run: apt update && apt install -y libsqlite3-dev - name: Download source uses: actions/checkout@v3 From db6cade3de471dc410d6d4f3d7be583a929a5962 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 14:26:22 -0400 Subject: [PATCH 18/32] Adds redis for the test suite --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bca9c9c93..2d4ab0b1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,9 @@ jobs: steps: - name: Update & install sqlite3 run: apt update && apt install -y libsqlite3-dev + + - name: Redis Server in GitHub Actions + uses: supercharge/redis-github-action@1.4.0 - name: Download source uses: actions/checkout@v3 From 78954a6a6f99e3a5dd6e74fbaaccc6881174a070 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Tue, 23 Aug 2022 14:44:49 -0400 Subject: [PATCH 19/32] Added redis dependencies to the apt install step --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d4ab0b1b..11622c6ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Update & install sqlite3 - run: apt update && apt install -y libsqlite3-dev + run: apt update && apt install -y libsqlite3-dev redis-server redis-tools - name: Redis Server in GitHub Actions uses: supercharge/redis-github-action@1.4.0 From 3e49484807db00701a192ed90f524fcbafc85e5a Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 07:21:55 -0400 Subject: [PATCH 20/32] Changed steps to stop using the supercharge redis installation and added a step to check that redis is running --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11622c6ba..f9f73037b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,9 +10,9 @@ jobs: steps: - name: Update & install sqlite3 run: apt update && apt install -y libsqlite3-dev redis-server redis-tools - - - name: Redis Server in GitHub Actions - uses: supercharge/redis-github-action@1.4.0 + + - name: Check redis is running + run: redis-cli ping - name: Download source uses: actions/checkout@v3 From 84e11620f1bf9d494ed5a5bfa1a06ebee06ad45c Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 07:37:53 -0400 Subject: [PATCH 21/32] Trying redis as a service --- .github/workflows/ci.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9f73037b..4858ba697 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,25 @@ on: push: jobs: - build: + container-job: + runs-on: ubuntu-latest container: image: crystallang/crystal + services: + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: Update & install sqlite3 - run: apt update && apt install -y libsqlite3-dev redis-server redis-tools - - - name: Check redis is running - run: redis-cli ping + run: apt update && apt install -y libsqlite3-dev - name: Download source uses: actions/checkout@v3 @@ -21,4 +28,6 @@ jobs: run: shards install - name: Run tests - run: bin/amber_spec \ No newline at end of file + run: bin/amber_spec + env: + REDIS_URL: "redis:6379" \ No newline at end of file From ab39ee1b07577043b47ef8bc4a8a0de15ac90764 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 07:45:01 -0400 Subject: [PATCH 22/32] Tweaked the redis service settings to map the port for the host container to access redis using localhost:6379 --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4858ba697..d07a280d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 6379:6379 steps: - name: Update & install sqlite3 @@ -29,5 +31,4 @@ jobs: - name: Run tests run: bin/amber_spec - env: - REDIS_URL: "redis:6379" \ No newline at end of file + \ No newline at end of file From 8c82e466f6aeb1a44943b037da2366e5fd750f4d Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 07:59:44 -0400 Subject: [PATCH 23/32] Added a step to check access to the redis service before the tests run --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d07a280d5..552c712c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ on: push: jobs: - container-job: + amber-spec: runs-on: ubuntu-latest @@ -21,7 +21,7 @@ jobs: steps: - name: Update & install sqlite3 - run: apt update && apt install -y libsqlite3-dev + run: apt update && apt install -y libsqlite3-dev redis-cli - name: Download source uses: actions/checkout@v3 @@ -29,6 +29,8 @@ jobs: - name: Install shards run: shards install + - name: Check redis availability + run: redis-cli ping + - name: Run tests run: bin/amber_spec - \ No newline at end of file From 29ece194ea9423f75bee2232b897a69a06938870 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 08:04:22 -0400 Subject: [PATCH 24/32] redis-cli stopped existing so trying to install plain redis --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 552c712c1..afdfb4f83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: steps: - name: Update & install sqlite3 - run: apt update && apt install -y libsqlite3-dev redis-cli + run: apt update && apt install -y libsqlite3-dev redis - name: Download source uses: actions/checkout@v3 From 46c25f83bf3cfa901a1537b8ee7348e73eae8349 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 08:21:06 -0400 Subject: [PATCH 25/32] removed the port mapping to test if redis becomes accessible from the runner --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afdfb4f83..4b9777dae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,6 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - ports: - - 6379:6379 steps: - name: Update & install sqlite3 From 8345859a9c220b5b432fb071bae06962744c8896 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 08:25:17 -0400 Subject: [PATCH 26/32] specified the host when testing the redis connection --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b9777dae..8cd403a40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: run: shards install - name: Check redis availability - run: redis-cli ping + run: redis-cli -h localhost ping - name: Run tests run: bin/amber_spec From 78b3bc35d28355b6328b94acd78b53150cf1ccbc Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 08:28:16 -0400 Subject: [PATCH 27/32] Added ports mapping back to the redis service container to see if this resolves the redis-cli not reaching the redis service --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cd403a40..feca0bd18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 6379:6379 steps: - name: Update & install sqlite3 From 9094d9be6a07548eaa8d8e634ff51c82eef3a616 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 08:37:09 -0400 Subject: [PATCH 28/32] Changed host from localhost to redis to see if that maps correctly --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feca0bd18..cc637d97f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: run: shards install - name: Check redis availability - run: redis-cli -h localhost ping + run: redis-cli -h redis ping - name: Run tests run: bin/amber_spec From 7365ed4a15e3338d6c6aa3dc5553e0186c2823b5 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 08:42:33 -0400 Subject: [PATCH 29/32] Added the REDIS_URL with the hostname of the redis service and removed the redis connection verification step now that it's working --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc637d97f..9a52575c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,8 +29,7 @@ jobs: - name: Install shards run: shards install - - name: Check redis availability - run: redis-cli -h redis ping - - name: Run tests run: bin/amber_spec + env: + REDIS_URL: "redis://redis:6379" From 875785d0b1414e5190a8bc5af07817cfec398dd2 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 24 Aug 2022 09:53:17 -0400 Subject: [PATCH 30/32] Changed the empty? method to be more clear about 'any origin' being the actual question, and fixed the to_h method doing too much to return a hash --- spec/amber/router/session/redis_store_spec.cr | 2 +- src/amber/pipes/cors.cr | 8 ++++---- src/amber/router/session/redis_store.cr | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/amber/router/session/redis_store_spec.cr b/spec/amber/router/session/redis_store_spec.cr index d951938e1..152d3d5a5 100644 --- a/spec/amber/router/session/redis_store_spec.cr +++ b/spec/amber/router/session/redis_store_spec.cr @@ -152,7 +152,7 @@ module Amber::Router::Session cookie_store.delete("ses") cookie_store.to_h.keys.should eq %w(a b c) - cookie_store.to_h["c"].should eq "x" + cookie_store.to_h.dig("c").should eq "x" end end diff --git a/src/amber/pipes/cors.cr b/src/amber/pipes/cors.cr index 76814f91a..88b9b2499 100644 --- a/src/amber/pipes/cors.cr +++ b/src/amber/pipes/cors.cr @@ -63,7 +63,7 @@ module Amber private def put_response_headers(response) response.headers[Headers::ALLOW_CREDENTIALS] = @credentials.to_s if @credentials response.headers[Headers::ALLOW_ORIGIN] = @origin.request_origin.not_nil! - response.headers[Headers::VARY] = vary if @origin.empty? + response.headers[Headers::VARY] = vary unless @origin.any_origin? end private def vary @@ -122,7 +122,7 @@ module Amber def match?(request) return false if @origins.empty? return false unless origin_header?(request) - return true if !empty? + return true if any_origin? @origins.any? do |origin| case origin @@ -132,8 +132,8 @@ module Amber end end - def empty? - !@origins.includes? "*" + def any_origin? + @origins.includes? "*" end protected def origin_header?(request) diff --git a/src/amber/router/session/redis_store.cr b/src/amber/router/session/redis_store.cr index 0e85e8e2e..8815ec606 100644 --- a/src/amber/router/session/redis_store.cr +++ b/src/amber/router/session/redis_store.cr @@ -56,7 +56,7 @@ module Amber::Router::Session end def to_h - store.hgetall(session_id).each_slice(2).to_h + store.hgetall(session_id) end def update(hash : Hash(String | Symbol, String)) From 2325ccb5bb6ad1c95149327bfa2c3cc3a6b380ff Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 14 Sep 2022 08:44:48 -0400 Subject: [PATCH 31/32] Include the discord link into the generated home page templates --- src/amber/cli/templates/app/src/views/home/index.ecr.ecr | 1 + src/amber/cli/templates/app/src/views/home/index.slang.ecr | 1 + 2 files changed, 2 insertions(+) diff --git a/src/amber/cli/templates/app/src/views/home/index.ecr.ecr b/src/amber/cli/templates/app/src/views/home/index.ecr.ecr index 751a19bcf..5988c1901 100644 --- a/src/amber/cli/templates/app/src/views/home/index.ecr.ecr +++ b/src/amber/cli/templates/app/src/views/home/index.ecr.ecr @@ -6,6 +6,7 @@ Getting Started with Amber Framework List of Awesome Crystal projects and shards What's hot in Crystal right now + Join the Amber Discord! diff --git a/src/amber/cli/templates/app/src/views/home/index.slang.ecr b/src/amber/cli/templates/app/src/views/home/index.slang.ecr index 87a877339..000ebad9c 100644 --- a/src/amber/cli/templates/app/src/views/home/index.slang.ecr +++ b/src/amber/cli/templates/app/src/views/home/index.slang.ecr @@ -6,3 +6,4 @@ a.list-group-item.list-group-item-action target="_blank" href="https://docs.amberframework.org" Getting Started with Amber Framework a.list-group-item.list-group-item-action target="_blank" href="https://github.com/veelenga/awesome-crystal" List of Awesome Crystal projects and shards a.list-group-item.list-group-item-action target="_blank" href="https://crystalshards.xyz" What's hot in Crystal right now + a.list-grouo-item.list-group-item-action target="_blank" href="https://discord.gg/vwvP5zakSn" Join the Amber Discord! From 10f1cedb6fb69e9ad58f006e9252f8a3e48bae26 Mon Sep 17 00:00:00 2001 From: crimson-knight Date: Wed, 14 Sep 2022 08:54:52 -0400 Subject: [PATCH 32/32] Tweaked how the PG test data is configured --- .github/workflows/ci.yml | 11 +++++++++++ .../templates/app/config/environments/test.yml.ecr | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a52575c1..71d82b97a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,17 @@ jobs: --health-retries 5 ports: - 6379:6379 + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 steps: - name: Update & install sqlite3 diff --git a/src/amber/cli/templates/app/config/environments/test.yml.ecr b/src/amber/cli/templates/app/config/environments/test.yml.ecr index acd13de38..f440f874f 100644 --- a/src/amber/cli/templates/app/config/environments/test.yml.ecr +++ b/src/amber/cli/templates/app/config/environments/test.yml.ecr @@ -19,7 +19,7 @@ redis_url: "redis://localhost:6379" when "mysql" -%> database_url: mysql://root@localhost:3306/<%= database_name %>_test <% when "pg" -%> -database_url: postgres://postgres:password@localhost:5432/<%= database_name %>_test +database_url: <%= "postgres://postgres:#{ENV["POSTGRES_PASSWORD"]? || "password"}@localhost:5432/#{database_name}_test" %> <% when "sqlite" -%> database_url: sqlite3:./db/<%= database_name %>_test.db <% else