Skip to content

Commit

Permalink
Fix plugins only specified in an environment
Browse files Browse the repository at this point in the history
When specifying a plugin in an environment only (and not a release) the
plugin is prepended to the profile.plugins attribute. However since
this defaults to nil, the result is an improper list in the format:

    [SampleApp.TestPlugin | nil]

This commit fixes it so that the profile.plugins defaults to an empty
list, resulting in:

    [SampleApp.TestPlugin | []]

A test has been added which loads a sample plugin from the rel
directory and verifies that the list contains a list with the plugin.
This test will fail when the list is an improper list.

When merging the profile and environment, there is a check in place so
that lists are correctly merged together.

The integration test has been modified to ensure that all the plugins
run.
  • Loading branch information
Gazler committed Aug 15, 2016
1 parent 6d1fad8 commit a2be65b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/mix/lib/releases/assembler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ defmodule Mix.Releases.Assembler do
profile = Enum.reduce(env_profile, rel_profile, fn {k, v}, acc ->
case v do
nil -> acc
[] -> nil
_ -> Map.put(acc, k, v)
end
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/lib/releases/models/profile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Mix.Releases.Profile do
include_src: nil, # boolean
include_system_libs: nil, # boolean | "path/to/libs"
strip_debug_info: nil, # boolean
plugins: nil, # list of module names
plugins: [], # list of module names
overlay_vars: nil, # keyword list
overlays: nil, # overlay list
overrides: nil, # override list [app: app_path]
Expand Down
14 changes: 14 additions & 0 deletions test/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ defmodule ConfigTest do
default_release: :default, default_environment: :default} = config
end
end

describe "plugin config" do
test "read!" do
config = Mix.Project.in_project(:standard_app, @standard_app, fn _mixfile ->
Mix.Releases.Config.read!(Path.join([@standard_app, "rel", "config.exs"]))
end)
assert %Config{environments: %{
dev: %Environment{profile: %Profile{plugins: []}},
prod: %Environment{profile: %Profile{plugins: [SampleApp.ProdPlugin]}}},
releases: %{
standard_app: %Release{profile: %Profile{plugins: [SampleApp.ReleasePlugin]}}}
} = config
end
end
end
4 changes: 4 additions & 0 deletions test/fixtures/standard_app/rel/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Code.require_file("rel/sample_app_plugin.ex")
Code.require_file("rel/release_plugin.ex")
use Mix.Releases.Config,
default_environment: :dev

Expand All @@ -10,8 +12,10 @@ environment :prod do
set dev_mode: false
set strip_debug_info: false
set include_erts: true
plugin SampleApp.ProdPlugin
end

release :standard_app do
set version: "0.0.1"
plugin SampleApp.ReleasePlugin
end
10 changes: 10 additions & 0 deletions test/fixtures/standard_app/rel/release_plugin.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule SampleApp.ReleasePlugin do
use Mix.Releases.Plugin

def before_assembly(_), do: info("Release Plugin - before_assembly") && nil
def after_assembly(_), do: info("Release Plugin - after_assembly") && nil

def before_package(_), do: info("Release Plugin - before_package") && nil
def after_package(_), do: info("Release Plugin - after_package") && nil
def after_cleanup(_), do: info("Release Plugin - after_cleanup") && nil
end
10 changes: 10 additions & 0 deletions test/fixtures/standard_app/rel/sample_app_plugin.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule SampleApp.ProdPlugin do
use Mix.Releases.Plugin

def before_assembly(_), do: info("Prod Plugin - before_assembly") && nil
def after_assembly(_), do: info("Prod Plugin - after_assembly") && nil

def before_package(_), do: info("Prod Plugin - before_package") && nil
def after_package(_), do: info("Prod Plugin - after_package") && nil
def after_cleanup(_), do: info("Prod Plugin - after_cleanup") && nil
end
29 changes: 17 additions & 12 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ defmodule IntegrationTest do
File.cd!(@standard_app_path)
{:ok, _} = File.rm_rf(Path.join(@standard_app_path, "_build"))
_ = File.rm(Path.join(@standard_app_path, "mix.lock"))
:ok = mix("deps.get")
:ok = mix("deps.compile", ["distillery"])
:ok = mix("compile")
:ok = mix("release.clean")
{:ok, _} = mix("deps.get")
{:ok, _} = mix("deps.compile", ["distillery"])
{:ok, _} = mix("compile")
{:ok, _} = mix("release.clean")
unquote(body)
File.cd!(old_dir)
end
Expand All @@ -42,12 +42,17 @@ defmodule IntegrationTest do
# Build release
result = mix("release", ["--verbose", "--env=prod"])
r = case result do
:ok -> :ok
{:ok, output} -> {:ok, output}
{:error, _code, output} ->
IO.puts(output)
:error
end
assert :ok = r
assert {:ok, output} = r
for callback <- ~w(before_assembly after_assembly before_package after_package) do
assert output =~ "Prod Plugin - #{callback}"
end
refute String.contains?(output, "Release Plugin")

assert ["0.0.1"] == Utils.get_release_versions(@standard_output_path)
# Boot it, ping it, and shut it down
assert {:ok, tmpdir} = Utils.insecure_mkdir_temp()
Expand Down Expand Up @@ -80,12 +85,12 @@ defmodule IntegrationTest do
# Build v1 release
result = mix("release", ["--verbose", "--env=prod"])
r = case result do
:ok -> :ok
{:ok, output} -> {:ok, output}
{:error, _code, output} ->
IO.puts(output)
:error
end
assert :ok = r
assert {:ok, _output} = r
# Update config for v2
project_config_path = Path.join(@standard_app_path, "mix.exs")
project = File.read!(project_config_path)
Expand Down Expand Up @@ -122,15 +127,15 @@ defmodule IntegrationTest do
File.write!(a_mod_path, new_a_mod)
File.write!(b_mod_path, new_b_mod)
# Build v2 release
:ok = mix("compile")
{:ok, _} = mix("compile")
result = mix("release", ["--verbose", "--env=prod", "--upgrade"])
r = case result do
:ok -> :ok
{:ok, output} -> {:ok, output}
{:error, _code, output} ->
IO.puts(output)
:error
end
assert :ok = r
assert {:ok, _} = r
assert ["0.0.2", "0.0.1"] == Utils.get_release_versions(@standard_output_path)
# Deploy it
assert {:ok, tmpdir} = Utils.insecure_mkdir_temp()
Expand Down Expand Up @@ -214,7 +219,7 @@ defmodule IntegrationTest do
if System.get_env("VERBOSE_TESTS") do
IO.puts(output)
end
:ok
{:ok, output}
{output, err} -> {:error, err, output}
end
end
Expand Down

0 comments on commit a2be65b

Please sign in to comment.