Skip to content

CI: Add current Elixir and Erlang/OTP GA versions to test matrix #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ jobs:
strategy:
matrix:
version:
- otp: 27.2
elixir: 1.18
os: ubuntu-latest
- otp: 26.0
elixir: 1.16.0
os: ubuntu-latest
- otp: 22.0
elixir: 1.12.0
# It's necessary to run on ubunto 20.04 for OTP 20 - 25
# It's necessary to run on Ubuntu 20.04 for OTP 20 - 25
# See https://github.com/erlef/setup-beam
os: ubuntu-20.04
runs-on: ${{ matrix.version.os }}
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Config

if Mix.env == :test do
if Mix.env() == :test do
import_config "test.exs"
end
22 changes: 18 additions & 4 deletions lib/mix/pow_assent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ defmodule Mix.PowAssent do
def validate_schema_args!([schema, plural | _rest] = args, task) do
cond do
not schema_valid?(schema) ->
raise_invalid_schema_args_error!("Expected the schema argument, #{inspect schema}, to be a valid module name", task)
raise_invalid_schema_args_error!(
"Expected the schema argument, #{inspect(schema)}, to be a valid module name",
task
)

not plural_valid?(plural) ->
raise_invalid_schema_args_error!("Expected the plural argument, #{inspect plural}, to be all lowercase using snake_case convention", task)
raise_invalid_schema_args_error!(
"Expected the plural argument, #{inspect(plural)}, to be all lowercase using snake_case convention",
task
)

true ->
schema_options_from_args(args)
end
end

def validate_schema_args!([_schema | _rest], task) do
raise_invalid_schema_args_error!("Invalid arguments", task)
end

def validate_schema_args!([], _task), do: schema_options_from_args()

defp schema_valid?(schema), do: schema =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/
Expand All @@ -35,6 +45,10 @@ defmodule Mix.PowAssent do
end

defp schema_options_from_args(_opts \\ [])
defp schema_options_from_args([schema, plural | _rest]), do: %{schema_name: schema, schema_plural: plural}
defp schema_options_from_args(_any), do: %{schema_name: "UserIdentities.UserIdentity", schema_plural: "user_identities"}

defp schema_options_from_args([schema, plural | _rest]),
do: %{schema_name: schema, schema_plural: plural}

defp schema_options_from_args(_any),
do: %{schema_name: "UserIdentities.UserIdentity", schema_plural: "user_identities"}
end
20 changes: 16 additions & 4 deletions lib/mix/tasks/ecto/pow_assent.ecto.gen.migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,22 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do
|> Enum.each(&create_migration_file/1)
end

defp create_migration_file(%{repo: repo, binary_id: binary_id, users_table: users_table, schema_plural: schema_plural}) do
context_base = Pow.app_base(Pow.otp_app())
schema = UserIdentitiesMigration.new(context_base, schema_plural, repo: repo, binary_id: binary_id, users_table: users_table)
content = UserIdentitiesMigration.gen(schema)
defp create_migration_file(%{
repo: repo,
binary_id: binary_id,
users_table: users_table,
schema_plural: schema_plural
}) do
context_base = Pow.app_base(Pow.otp_app())

schema =
UserIdentitiesMigration.new(context_base, schema_plural,
repo: repo,
binary_id: binary_id,
users_table: users_table
)

content = UserIdentitiesMigration.gen(schema)

Migration.create_migration_file(repo, schema.migration_name, content)
end
Expand Down
16 changes: 9 additions & 7 deletions lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do
|> Map.merge(config)
end

defp create_schema_file(%{binary_id: binary_id, schema_name: schema_name, schema_plural: schema_plural} = config) do
context_app = Map.get(config, :context_app) || Pow.otp_app()
defp create_schema_file(
%{binary_id: binary_id, schema_name: schema_name, schema_plural: schema_plural} = config
) do
context_app = Map.get(config, :context_app) || Pow.otp_app()
context_base = Pow.app_base(context_app)
schema = SchemaModule.new(context_base, schema_name, schema_plural, binary_id: binary_id)
content = SchemaModule.gen(schema)
dir_name = dir_name(schema_name)
file_name = file_name(schema.module)
schema = SchemaModule.new(context_base, schema_name, schema_plural, binary_id: binary_id)
content = SchemaModule.gen(schema)
dir_name = dir_name(schema_name)
file_name = file_name(schema.module)

context_app
|> Pow.context_lib_path(dir_name)
Expand Down Expand Up @@ -84,7 +86,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do
|> File.exists?()
|> case do
false -> path
_ -> Mix.raise("schema file can't be created, there is already a schema file in #{path}.")
_ -> Mix.raise("schema file can't be created, there is already a schema file in #{path}.")
end
end
end
29 changes: 17 additions & 12 deletions lib/mix/tasks/ecto/pow_assent.ecto.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,28 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do

config
end

defp maybe_run_gen_migration(config, _args), do: config

defp maybe_run_gen_schema(%{schema: true} = config, args) do
SchemaTask.run(args)

config
end

defp maybe_run_gen_schema(config, _args), do: config

defp parse_structure(config) do
context_app = Map.get(config, :context_app) || Pow.otp_app()
context_app = Map.get(config, :context_app) || Pow.otp_app()
context_base = Pow.app_base(context_app)
user_module = Module.concat([context_base, "Users.User"])
user_file = Path.join(["lib", "#{context_app}", "users", "user.ex"])

Map.put(config, :structure, %{context_app: context_app, user_module: user_module, user_file: user_file})
Map.put(config, :structure, %{
context_app: context_app,
user_module: user_module,
user_file: user_file
})
end

defp print_shell_instructions(%{structure: structure} = config) do
Expand All @@ -80,7 +86,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do
config

:error ->
Mix.raise "Couldn't install PowAssent! Did you run this inside your Ecto app?"
Mix.raise("Couldn't install PowAssent! Did you run this inside your Ecto app?")
end
end

Expand All @@ -96,17 +102,16 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do
needle: "use Pow.Ecto.Schema"
}
],
instructions:
"""
Add the `PowAssent.Ecto.Schema` macro to #{Path.relative_to_cwd(file)} after `use Pow.Ecto.Schema`:
instructions: """
Add the `PowAssent.Ecto.Schema` macro to #{Path.relative_to_cwd(file)} after `use Pow.Ecto.Schema`:

defmodule #{inspect(structure.user_module)} do
use Ecto.Schema
use Pow.Ecto.Schema
use PowAssent.Ecto.Schema
defmodule #{inspect(structure.user_module)} do
use Ecto.Schema
use Pow.Ecto.Schema
use PowAssent.Ecto.Schema

# ...
"""
# ...
"""
}
end
end
8 changes: 4 additions & 4 deletions lib/mix/tasks/phoenix/pow_assent.phoenix.gen.templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.Templates do
end

@templates [
{"registration", ~w(add_user_id)},
{"registration", ~w(add_user_id)}
]

defp create_template_files({config, _parsed, _invalid}) do
structure = Phoenix.parse_structure(config)
web_module = structure[:web_module]
web_prefix = structure[:web_prefix]
structure = Phoenix.parse_structure(config)
web_module = structure[:web_module]
web_prefix = structure[:web_prefix]

Enum.each(@templates, fn {name, actions} ->
Phoenix.create_template_module(Elixir.PowAssent, name, web_module, web_prefix)
Expand Down
40 changes: 20 additions & 20 deletions lib/mix/tasks/phoenix/pow_assent.phoenix.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Install do
config

:error ->
Mix.raise "Couldn't install PowAssent! Did you run this inside your Phoenix app?"
Mix.raise("Couldn't install PowAssent! Did you run this inside your Phoenix app?")
end
end

Expand Down Expand Up @@ -111,33 +111,32 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Install do
needle: "pow_routes()"
}
],
instructions:
"""
Update `#{Path.relative_to_cwd(file)}` with the PowAssent routes:
instructions: """
Update `#{Path.relative_to_cwd(file)}` with the PowAssent routes:

defmodule #{inspect(structure.web_module)}.Router do
use #{inspect(structure.web_module)}, :router
use Pow.Phoenix.Router
#{router_use_content}
defmodule #{inspect(structure.web_module)}.Router do
use #{inspect(structure.web_module)}, :router
use Pow.Phoenix.Router
#{router_use_content}

# ...
# ...

#{router_pipeline_content}
#{router_pipeline_content}

# ...
# ...

#{router_scope_content}
#{router_scope_content}

scope "/" do
pipe_through :browser

pow_routes()
#{router_routes_macro}
end
scope "/" do
pipe_through :browser

# ...
pow_routes()
#{router_routes_macro}
end
"""

# ...
end
"""
}
end

Expand All @@ -146,5 +145,6 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Install do

config
end

defp maybe_run_gen_templates(config, _args), do: config
end
11 changes: 5 additions & 6 deletions lib/mix/tasks/pow_assent.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ defmodule Mix.Tasks.PowAssent.Install do

defp no_umbrella! do
if Project.umbrella?() do
Mix.raise(
"""
mix #{@mix_task} has to be used inside an application directory, but this is an umbrella project.
Mix.raise("""
mix #{@mix_task} has to be used inside an application directory, but this is an umbrella project.

Run mix pow_assent.ecto.install inside your Ecto application directory to create schema module and migrations.
Run mix pow_assent.ecto.install inside your Ecto application directory to create schema module and migrations.

Run mix pow_assent.phoenix.install in your Phoenix application directory for configuration instructions.
""")
Run mix pow_assent.phoenix.install in your Phoenix application directory for configuration instructions.
""")
end

:ok
Expand Down
5 changes: 3 additions & 2 deletions lib/pow_assent/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule PowAssent.Config do
def get(config, key, default \\ nil) do
case Keyword.get(config, key, :not_found) do
:not_found -> get_env_config(config, key, default)
value -> value
value -> value
end
end

Expand All @@ -35,7 +35,7 @@ defmodule PowAssent.Config do
config
|> Keyword.get(:otp_app)
|> case do
nil -> Application.get_all_env(env_key)
nil -> Application.get_all_env(env_key)
otp_app -> Application.get_env(otp_app, env_key, [])
end
|> Keyword.get(key, default)
Expand Down Expand Up @@ -83,6 +83,7 @@ defmodule PowAssent.Config do
deep_merge(left, right)
end)
end

defp deep_merge(_left, right), do: right

@doc """
Expand Down
Loading
Loading