Skip to content

Commit 717490a

Browse files
committed
Respect :path when tar-ing releases, closes #9949
1 parent 8cb1361 commit 717490a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ defmodule Mix.Tasks.Release do
481481
will receive a `Mix.Release` struct and must return the same or
482482
an updated `Mix.Release` struct. It is also possible to build a tarball
483483
of the release by passing the `:tar` step anywhere after `:assemble`.
484-
The tarball is created in `_build/MIX_ENV/RELEASE_NAME-RELEASE_VSN.tar.gz`
484+
If the release `:path` is not configured, the tarball is created in
485+
`_build/MIX_ENV/RELEASE_NAME-RELEASE_VSN.tar.gz` Otherwise it is
486+
created inside the configured `:path`.
485487
486488
See `Mix.Release` for more documentation on the struct and which
487489
fields can be modified. Note that `:steps` field itself can be
@@ -1065,8 +1067,16 @@ defmodule Mix.Tasks.Release do
10651067
end
10661068

10671069
defp make_tar(release) do
1068-
tar_filename = "#{release.name}-#{release.version}.tar.gz"
1069-
out_path = Path.join([release.path, "..", "..", tar_filename]) |> Path.expand()
1070+
build_path = Mix.Project.build_path()
1071+
1072+
dir_path =
1073+
if release.path == Path.join([build_path, "rel", Atom.to_string(release.name)]) do
1074+
build_path
1075+
else
1076+
release.path
1077+
end
1078+
1079+
out_path = Path.join(dir_path, "#{release.name}-#{release.version}.tar.gz")
10701080
info(release, [:green, "* building ", :reset, out_path])
10711081

10721082
lib_dirs =

lib/mix/test/mix/tasks/release_test.exs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ defmodule Mix.Tasks.ReleaseTest do
135135
end
136136

137137
describe "tar" do
138-
test "with ERTS" do
138+
test "with default options" do
139139
in_fixture("release_test", fn ->
140140
config = [releases: [demo: [steps: [:assemble, :tar]]]]
141141

@@ -186,15 +186,13 @@ defmodule Mix.Tasks.ReleaseTest do
186186
end)
187187
end
188188

189-
test "without ERTS" do
189+
test "without ERTS and custom path" do
190190
in_fixture("release_test", fn ->
191-
config = [releases: [demo: [include_erts: false, steps: [:assemble, :tar]]]]
191+
config = [releases: [demo: [include_erts: false, path: "tmp/rel", steps: [:assemble, :tar]]]]
192192

193193
Mix.Project.in_project(:release_test, ".", config, fn _ ->
194-
root = Path.absname("_build/#{Mix.env()}/rel/demo")
195-
196194
Mix.Task.run("release")
197-
tar_path = Path.expand(Path.join([root, "..", "..", "demo-0.1.0.tar.gz"]))
195+
tar_path = Path.expand(Path.join(["tmp", "rel", "demo-0.1.0.tar.gz"]))
198196
message = "* building #{tar_path}"
199197
assert_received {:mix_shell, :info, [^message]}
200198
assert File.exists?(tar_path)

0 commit comments

Comments
 (0)