Skip to content

Commit ef95d67

Browse files
committed
Fix OTP archive root
1 parent f996de4 commit ef95d67

2 files changed

Lines changed: 94 additions & 2 deletions

File tree

scripts/release_hex.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ function build {
136136

137137
echo "Building ${elixir_version} ${otp_version} ${ubuntu_version}"
138138
rm -rf _build src/mix_safe_erl_term.erl
139+
archive_ez=hex-${hex_version}.ez
139140
hex_ez=hex-${hex_version}-otp-${otp_release}.ez
140141

141142
mkdir -p "$installs_dir/${saved_elixir_version}"
142143
docker run -v $(pwd):/hex hexpm/elixir:${elixir_version}-erlang-${otp_version}-ubuntu-${ubuntu_version} sh -c " \
143144
cd /hex && \
144-
MIX_ENV=prod mix archive.build -o ${hex_ez}"
145+
MIX_ENV=prod mix archive.build -o ${archive_ez}"
145146

146-
mv "${hex_ez}" "${installs_dir}/${saved_elixir_version}/${hex_ez}"
147+
mv "${archive_ez}" "${installs_dir}/${saved_elixir_version}/${hex_ez}"
147148
sha=$(shasum -a 512 "${installs_dir}/${saved_elixir_version}/${hex_ez}")
148149
sha=($sha)
149150
echo "${hex_version},${sha},${saved_elixir_version},${otp_release}" >> "${hex_csv}"

test/scripts/release_hex_test.exs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
defmodule ReleaseHexTest do
2+
use ExUnit.Case, async: true
3+
4+
@script Path.expand("../../scripts/release_hex.sh", __DIR__)
5+
6+
test "OTP-specific archives are built with the canonical internal directory" do
7+
tmp = Path.join(System.tmp_dir!(), "hex-release-#{System.unique_integer([:positive])}")
8+
bin = Path.join(tmp, "bin")
9+
10+
on_exit(fn -> File.rm_rf!(tmp) end)
11+
12+
File.rm_rf!(tmp)
13+
File.mkdir_p!(bin)
14+
File.mkdir_p!(Path.join(tmp, "tmp"))
15+
16+
docker_log = Path.join(tmp, "docker.log")
17+
write_aws_stub(Path.join(bin, "aws"))
18+
write_docker_stub(Path.join(bin, "docker"))
19+
20+
path = bin <> ":" <> System.get_env("PATH", "")
21+
22+
{output, status} =
23+
System.cmd("bash", [@script, "--dry-run", "2.4.3"],
24+
cd: tmp,
25+
env: [{"PATH", path}, {"HEX_RELEASE_TEST_DOCKER_LOG", docker_log}],
26+
stderr_to_stdout: true
27+
)
28+
29+
assert status == 0, output
30+
31+
docker_commands = File.read!(docker_log)
32+
33+
assert docker_commands =~ "MIX_ENV=prod mix archive.build -o hex-2.4.3.ez"
34+
refute docker_commands =~ "MIX_ENV=prod mix archive.build -o hex-2.4.3-otp-"
35+
36+
archives = Path.wildcard(Path.join([tmp, "tmp", "installs", "*", "hex-2.4.3-otp-*.ez"]))
37+
38+
assert archives != []
39+
assert Enum.all?(archives, &(File.read!(&1) == "hex-2.4.3.ez\n"))
40+
end
41+
42+
defp write_aws_stub(path) do
43+
File.write!(path, """
44+
#!/bin/sh
45+
if [ "$1" = "s3" ] && [ "$2" = "cp" ]; then
46+
src="$3"
47+
dest="$4"
48+
49+
case "$src" in
50+
s3://*)
51+
mkdir -p "$(dirname "$dest")"
52+
: > "$dest"
53+
exit 0
54+
;;
55+
esac
56+
fi
57+
58+
exit 0
59+
""")
60+
61+
File.chmod!(path, 0o755)
62+
end
63+
64+
defp write_docker_stub(path) do
65+
File.write!(path, """
66+
#!/bin/sh
67+
printf '%s\\n' "$*" >> "$HEX_RELEASE_TEST_DOCKER_LOG"
68+
69+
cmd=""
70+
while [ "$#" -gt 0 ]; do
71+
if [ "$1" = "-c" ]; then
72+
shift
73+
cmd="$1"
74+
break
75+
fi
76+
77+
shift
78+
done
79+
80+
output=$(printf '%s\\n' "$cmd" | sed -n 's/.*mix archive.build -o \\([^ "]*\\).*/\\1/p')
81+
82+
if [ -n "$output" ]; then
83+
printf '%s\\n' "$output" > "$output"
84+
fi
85+
86+
exit 0
87+
""")
88+
89+
File.chmod!(path, 0o755)
90+
end
91+
end

0 commit comments

Comments
 (0)