-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_otp_builds_text.exs
executable file
·51 lines (41 loc) · 1.25 KB
/
prepare_otp_builds_text.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
defmodule Line do
defstruct [:datetime, :path, :ref, :sha, :otp]
def from_line(line) do
pattern = ~r|builds/otp/ubuntu-14.04/(.*?)\.tar.gz|
[date, time, _, path] = String.split(line)
[ref, otp] =
case Regex.run(pattern, path, capture: :all_but_first) do
[ref] -> [ref, ""]
[ref, otp] -> [ref, otp]
end
%Line{
datetime: "#{date}T#{time}Z",
path: path,
ref: ref,
otp: otp
}
end
def get_sha(line, repo_dir) do
System.cmd("git", ["checkout", line.ref], cd: repo_dir)
{sha, 0} = System.cmd("git", ["rev-parse", "HEAD"], cd: repo_dir)
%{line | sha: String.trim(sha)}
end
def to_builds_txt(line) do
[line.ref <> line.otp, line.sha, line.datetime] |> Enum.join(" ")
end
end
# aws s3 ls s3:https://s3.hex.pm/builds/otp/ubuntu-14.04 --recursive
input = "otp-ls.txt"
output = "builds.txt"
repo = "https://github.com/erlang/otp.git"
repo_dir = "otp"
if !File.dir?(repo_dir) do
System.cmd("git", ["clone", repo, repo_dir])
end
(content =
File.stream!(input)
|> Enum.map(&Line.from_line/1)
|> Enum.map(&Line.get_sha(&1, repo_dir))
|> Enum.map_join("\n", &Line.to_builds_txt/1))
File.write!(output, content)
{_, 0} = System.cmd("sort", ["-u", "-k1,1", "-o", output, output])