Skip to content

Commit d69d771

Browse files
author
José Valim
committed
Allow releases as an anonymous function
1 parent 7d57dc9 commit d69d771

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/mix/lib/mix/release.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ defmodule Mix.Release do
158158
end
159159

160160
defp find_release(name, config) do
161-
{name, opts} = lookup_release(name, config) || infer_release(config)
161+
{name, opts_fun_or_list} = lookup_release(name, config) || infer_release(config)
162+
opts = if is_function(opts_fun_or_list, 0), do: opts_fun_or_list.(), else: opts_fun_or_list
162163
{apps, opts} = Keyword.pop(opts, :applications, [])
163164

164165
if apps == [] and Mix.Project.umbrella?(config) do

lib/mix/lib/mix/tasks/release.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ defmodule Mix.Tasks.Release do
346346
347347
### Options
348348
349-
The following options can be set inside your mix.exs on each release definition:
349+
The following options can be set inside your `mix.exs` on each release definition:
350350
351351
* `:applications` - a keyword list that configures and adds new applications
352352
to the release. The key is the application name and the value is one of:
@@ -438,6 +438,15 @@ defmodule Mix.Tasks.Release do
438438
* `:steps` - a list of steps to execute when assembling the release. See
439439
the "Steps" section for more information.
440440
441+
Note each release definition can be given as an anonymous function. This
442+
is useful if some release attributes are expensive to compute:
443+
444+
releases: [
445+
demo: fn ->
446+
[version: @version <> "+" <> git_ref()]
447+
end
448+
]
449+
441450
Besides the options above, it is possible to customize the generated
442451
release with custom files, by tweaking the release steps or by running
443452
custom options and commands on boot. We will detail both approaches next.

lib/mix/test/mix/release_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ defmodule Mix.ReleaseTest do
7474
assert release.applications.kernel[:otp_app?]
7575
end
7676

77+
test "allows release to be given as an anonymous function" do
78+
release = from_config!(:foo, config(releases: [foo: fn -> [version: "0.2.0"] end]), [])
79+
assert release.name == :foo
80+
assert release.version == "0.2.0"
81+
end
82+
7783
test "uses chosen release via the CLI" do
7884
release =
7985
from_config!(

0 commit comments

Comments
 (0)