Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/978
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Feb 13, 2025
1 parent 83737cf commit 0a0284b
Show file tree
Hide file tree
Showing 13 changed files with 605 additions and 73 deletions.
117 changes: 59 additions & 58 deletions lib/mix/mixer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ if not Code.ensure_loaded?(Bonfire.Mixer) do
def deps_recompile(deps \\ deps_names(:bonfire)),
do: Mix.Task.run("bonfire.dep.compile", ["--force"] ++ List.wrap(deps))

# def flavour_path(path) when is_binary(path), do: path
def flavour_path(config \\ mix_config()),
do: System.get_env("FLAVOUR_PATH", "flavours/" <> flavour(config))

def flavour(config \\ mix_config())

def flavour(default_flavour) when is_binary(default_flavour),
Expand All @@ -133,8 +129,6 @@ if not Code.ensure_loaded?(Bonfire.Mixer) do
def config_path(path \\ nil, filename),
do: Path.expand(Path.join([path || "config", filename]))

# flavour_path(config_or_flavour)

def forks_path(), do: System.get_env("FORKS_PATH", "extensions/")
def forks_paths(), do: [forks_path(), "forks/"]

Expand All @@ -155,70 +149,70 @@ if not Code.ensure_loaded?(Bonfire.Mixer) do
# |> log(label: "messy")
end

def mess_other_flavour_deps(current_flavour \\ System.get_env("FLAVOUR", "classic")) do
current_flavour_sources =
mess_source_files(System.get_env("WITH_FORKS", "1"), System.get_env("WITH_GIT_DEPS", "1"))
# def mess_other_flavour_deps(current_flavour \\ System.get_env("FLAVOUR", "ember")) do
# current_flavour_sources =
# mess_source_files(System.get_env("WITH_FORKS", "1"), System.get_env("WITH_GIT_DEPS", "1"))

current_flavour_deps =
enum_mess_sources(current_flavour_sources)
# |> log(label: "current_mess_sources")
|> Mess.deps([], [])
|> deps_names_list()
# current_flavour_deps =
# enum_mess_sources(current_flavour_sources)
# # |> log(label: "current_mess_sources")
# |> Mess.deps([], [])
# |> deps_names_list()

# |> log(label: "current_flavour_deps", limit: :infinity)
# # |> log(label: "current_flavour_deps", limit: :infinity)

other_flavours_sources = other_flavour_sources(current_flavour_sources, current_flavour)
# |> log(label: "other_flavours_sources")
# other_flavours_sources = other_flavour_sources(current_flavour_sources, current_flavour)
# # |> log(label: "other_flavours_sources")

Mess.deps(other_flavours_sources, [], [])
# |> log(label: "other_flavours_deps")
|> Enum.reject(fn
{dep, _} -> dep in current_flavour_deps
{dep, _, _} -> dep in current_flavour_deps
end)
|> log("other_flavour_deps")
end
# Mess.deps(other_flavours_sources, [], [])
# # |> log(label: "other_flavours_deps")
# |> Enum.reject(fn
# {dep, _} -> dep in current_flavour_deps
# {dep, _, _} -> dep in current_flavour_deps
# end)
# |> log("other_flavour_deps")
# end

def mess_other_flavour_dep_names(current_flavour \\ System.get_env("FLAVOUR", "classic")) do
mess_other_flavour_deps(current_flavour)
|> deps_names_list()
end
# def mess_other_flavour_dep_names(current_flavour \\ System.get_env("FLAVOUR", "ember")) do
# mess_other_flavour_deps(current_flavour)
# |> deps_names_list()
# end

defp maybe_all_flavour_sources(
existing_sources,
current_flavour,
"1" = _WITH_ALL_FLAVOUR_DEPS
) do
(enum_mess_sources(existing_sources) ++
[disabled: other_flavour_sources(existing_sources, current_flavour)])
enum_mess_sources(existing_sources)
# ++ [disabled: other_flavour_sources(existing_sources, current_flavour)]
|> log("all_flavour_sources")
end

defp maybe_all_flavour_sources(existing_sources, _flavour, _not_WITH_ALL_FLAVOUR_DEPS) do
enum_mess_sources(existing_sources)
end

def other_flavour_sources(
existing_sources \\ mess_source_files(
System.get_env("WITH_FORKS", "1"),
System.get_env("WITH_GIT_DEPS", "1")
),
current_flavour \\ System.get_env("FLAVOUR", "classic")
) do
flavour_paths =
for path <- "flavours/*/config/" |> Path.wildcard() do
path
end
|> Enum.reject(&(&1 == "flavours/#{current_flavour}/config"))

# |> log(label: "creams")

Enum.map(
flavour_paths,
&(List.first(existing_sources)
|> enum_mess_sources(&1))
)
end
# def other_flavour_sources(
# existing_sources \\ mess_source_files(
# System.get_env("WITH_FORKS", "1"),
# System.get_env("WITH_GIT_DEPS", "1")
# ),
# current_flavour \\ System.get_env("FLAVOUR", "ember")
# ) do
# flavour_paths =
# for path <- "flavours/*/config/" |> Path.wildcard() do
# path
# end
# |> Enum.reject(&(&1 == "flavours/#{current_flavour}/config"))

# # |> log(label: "creams")

# Enum.map(
# flavour_paths,
# &(List.first(existing_sources)
# |> enum_mess_sources(&1))
# )
# end

defp enum_mess_sources(sublist, path \\ nil)

Expand All @@ -232,20 +226,27 @@ if not Code.ensure_loaded?(Bonfire.Mixer) do
end

defp mess_source_files("0" = _not_WITH_FORKS, "0" = _not_WITH_GIT_DEPS),
do: [[hex: "deps.flavour.hex"], [hex: "deps.hex"]]
do: [[hex: "current_flavour/deps.hex"], [hex: "deps.hex"]]

defp mess_source_files("0" = _not_WITH_FORKS, "1" = _WITH_GIT_DEPS),
do: [[git: "deps.flavour.git", hex: "deps.flavour.hex"], [git: "deps.git", hex: "deps.hex"]]
do: [
[git: "current_flavour/deps.git", hex: "current_flavour/deps.hex"],
[git: "deps.git", hex: "deps.hex"]
]

defp mess_source_files("1" = _WITH_FORKS, "0" = _not_WITH_GIT_DEPS),
do: [
[path: "deps.flavour.path", hex: "deps.flavour.hex"],
[path: "current_flavour/deps.path", hex: "current_flavour/deps.hex"],
[path: "deps.path", hex: "deps.hex"]
]

defp mess_source_files("1" = _WITH_FORKS, "1" = _WITH_GIT_DEPS),
do: [
[path: "deps.flavour.path", git: "deps.flavour.git", hex: "deps.flavour.hex"],
[
path: "current_flavour/deps.path",
git: "current_flavour/deps.git",
hex: "current_flavour/deps.hex"
],
[path: "deps.path", git: "deps.git", hex: "deps.hex"]
]

Expand All @@ -263,7 +264,7 @@ if not Code.ensure_loaded?(Bonfire.Mixer) do
|> deps_names()

# |> log(
# "Running Bonfire #{version(config)} at #{System.get_env("HOSTNAME", "localhost")} with configuration from #{flavour_path(config)} in #{Mix.env()} environment. You can run `just mix bonfire.deps.update` to update these extensions and dependencies"
# "Running Bonfire #{version(config)} at #{System.get_env("HOSTNAME", "localhost")} in #{Mix.env()} environment. You can run `just mix bonfire.deps.update` to update these extensions and dependencies"
# )
end

Expand All @@ -287,8 +288,8 @@ if not Code.ensure_loaded?(Bonfire.Mixer) do
def extra_guide_paths(config) do
deps = deps_names_for(:docs, config) ++ umbrella_extension_paths()

# Enum.map(Path.wildcard("flavours/*/README.md"), &flavour_readme/1) ++
List.wrap(config[:guides]) ++
Enum.map(Path.wildcard("flavours/*/README.md"), &flavour_readme/1) ++
Enum.map(Path.wildcard("docs/DEPENDENCIES/*.md"), &flavour_deps_doc/1) ++
Enum.flat_map(
deps,
Expand Down
100 changes: 100 additions & 0 deletions lib/mix/testing.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
defmodule Bonfire.Common.Testing do
def configure_start_test(opts \\ [migrate: false]) do
running_a_second_test_instance? = System.get_env("TEST_INSTANCE") == "yes"

# Start ExUnitSummary application, with recommended config
# ExUnitSummary.start(:normal, %ExUnitSummary.Config{
# filter_results: :success,
# # filter_results: :failed,
# print_delay: 100
# })

ExUnit.configure(
# please note that Mneme overrides any custom formatters
formatters: Bonfire.Common.RuntimeConfig.test_formatters(),
#  miliseconds
timeout: 120_000,
assert_receive_timeout: 1000,
exclude: Bonfire.Common.RuntimeConfig.skip_test_tags(),
# only show log for failed tests (Can be overridden for individual tests via `@tag capture_log: false`)
capture_log: !running_a_second_test_instance? and System.get_env("CAPTURE_LOG") != "no"
)

# ExUnit.configuration()
# |> IO.inspect()

# Code.put_compiler_option(:nowarn_unused_vars, true)

ExUnit.start()

if System.get_env("TEST_WITH_MNEME") != "no",
do: Mneme.start(),
else: Mneme.Options.configure([])

repo = Bonfire.Common.Config.repo()

if repo do
try do
if opts[:migrate] do
Mix.Task.run("ecto.create")
Mix.Task.run("ecto.migrate")
EctoSparkles.Migrator.migrate(repo)
end

# Ecto.Adapters.SQL.Sandbox.mode(repo, :manual)

# if System.get_env("PHX_SERVER") !="yes" do
Ecto.Adapters.SQL.Sandbox.mode(repo, :auto)
# end

# insert fixtures in test instance's repo on startup
if running_a_second_test_instance?,
do:
Bonfire.Common.TestInstanceRepo.apply(fn ->
nil
# EctoSparkles.Migrator.migrate(Bonfire.Common.TestInstanceRepo)
end)
rescue
e in RuntimeError ->
IO.warn("Could not set up database")
IO.inspect(e)
end
end

# ExUnit.after_suite(fn results ->
# # do stuff
# IO.inspect(test_results: results)

# :ok
# end)

try do
Application.put_env(:wallaby, :base_url, Bonfire.Web.Endpoint.url())
chromedriver_path = Bonfire.Common.Config.get([:wallaby, :chromedriver, :path])

if chromedriver_path && File.exists?(chromedriver_path),
do: {:ok, _} = Application.ensure_all_started(:wallaby),
else:
IO.inspect("Note: Wallaby UI tests will not run because the chromedriver is missing")
rescue
e in RuntimeError ->
IO.warn("Could not set up Wallaby UI tests ")
IO.inspect(e)
end

IO.puts("""
Testing shows the presence, not the absence of bugs.
- Edsger W. Dijkstra
""")

if System.get_env("OBSERVE") do
Bonfire.Application.observer()
end

# ExUnit.configuration()
# |> IO.inspect()

:ok
end
end
15 changes: 15 additions & 0 deletions lib/mix/testing_insecure_pw.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Bonfire.Common.Testing.InsecurePW do
# use Comeonin

@impl true
def hash_pwd_salt(password, _opts \\ []) do
password
end

@impl true
def verify_pass(_password, _stored_hash) do
true
end

def no_user_verify, do: nil
end
15 changes: 11 additions & 4 deletions lib/mix_tasks/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ defmodule Bonfire.Common.Mix.Tasks.Helpers do

igniter_copy(igniter, sources, target, opts)
else
contents_to_copy = File.read!(source)
if File.exists?(source) do
contents_to_copy = File.read!(source)

Igniter.create_or_update_file(igniter, target, contents_to_copy, fn source ->
Rewrite.Source.update(source, :content, contents_to_copy)
end)
if String.contains?(target, "/"), do: File.mkdir_p!(Path.dirname(target))

Igniter.create_or_update_file(igniter, target, contents_to_copy, fn source ->
Rewrite.Source.update(source, :content, contents_to_copy)
end)
else
IO.puts("Warning: Source file `#{source}` does not exist")
igniter
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/mix_tasks/install/copy_configs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ defmodule Mix.Tasks.Bonfire.Install.CopyConfigs do
def copy_for_extensions(igniter, extensions, opts) do
IO.inspect(opts, label: "Options")

path = opts[:to] || Path.expand(@default_config_path, Bonfire.Mixer.flavour_path())
to = opts[:to] || @default_config_path

dest_path =
Path.expand(path, File.cwd!())
Path.expand(to, File.cwd!())
|> IO.inspect(label: "to path")

from = opts[:from] || @default_config_path
Expand Down
10 changes: 6 additions & 4 deletions lib/mix_tasks/install/copy_migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Mix.Tasks.Bonfire.Install.CopyMigrations do
"""

@switches [from: :string, to: :string, force: :boolean]
@default_repo_path "repo"
@default_repo_path "priv/repo"
@default_mig_path @default_repo_path <> "/migrations"

def igniter(igniter, args) do
Expand All @@ -46,16 +46,18 @@ defmodule Mix.Tasks.Bonfire.Install.CopyMigrations do
def copy_for_extensions(igniter, extensions, opts) do
IO.inspect(opts, label: "Options")

path = opts[:to] || Path.expand(@default_repo_path, Bonfire.Mixer.flavour_path())
to = opts[:to] || @default_repo_path

dest_path =
Path.expand(path, File.cwd!())
Path.expand(to, File.cwd!())
|> IO.inspect(label: "to path")

from = opts[:from] || @default_mig_path

extension_paths =
extensions
|> IO.inspect(label: "deps to include")
|> Bonfire.Mixer.dep_paths(opts[:from] || "priv/" <> @default_mig_path)
|> Bonfire.Mixer.dep_paths(from)
|> IO.inspect(label: "paths to copy")

if igniter do
Expand Down
6 changes: 3 additions & 3 deletions lib/mix_tasks/install/install_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ defmodule Mix.Tasks.Bonfire.Install.Extension do
defs =
opts[:defs] ||
[
path: "config/deps.flavour.path",
git: "config/deps.flavour.git",
hex: "config/deps.flavour.hex"
path: "config/current_flavour/deps.path",
git: "config/current_flavour/deps.git",
hex: "config/current_flavour/deps.hex"
]

:ok =
Expand Down
4 changes: 3 additions & 1 deletion lib/modularity/extend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,9 @@ defmodule Bonfire.Common.Extend do
:ok
"""
def generate_reverse_router!() do
Utils.maybe_apply(Bonfire.Common.Config.endpoint_module(), :generate_reverse_router!)
Utils.maybe_apply(Config.get(:router_module, Bonfire.Web.Router), :generate_reverse_router!, [
Config.get(:otp_app)
])
|> debug("reverse_router generated?")
end

Expand Down
Loading

0 comments on commit 0a0284b

Please sign in to comment.