Conversation
Closes hexpm#234.
|
Also, this always rewrites all files, even if the content is the same. |
| defp to_matchable(string) do | ||
| destructure [version, pre], String.split(string, "-", parts: 2) | ||
|
|
||
| components = | ||
| version | ||
| |> String.split(".") | ||
| |> Enum.map(&String.to_integer/1) | ||
|
|
||
| {components, pre || []} | ||
| end | ||
|
|
||
| defp cmp_erlang_components({[left | lefts], left_pre}, {[right | rights], right_pre}) do | ||
| cond do | ||
| left > right -> :gt | ||
| left < right -> :lt | ||
| true -> cmp_erlang_components({lefts, left_pre}, {rights, right_pre}) | ||
| end | ||
| end | ||
|
|
||
| defp cmp_erlang_components({[], left_pre}, {[], right_pre}) do | ||
| cond do | ||
| left_pre == [] and right_pre != [] -> :gt | ||
| left_pre != [] and right_pre == [] -> :lt | ||
| left_pre > right_pre -> :gt | ||
| left_pre < right_pre -> :lt | ||
| true -> :eq | ||
| end | ||
| end | ||
|
|
||
| defp cmp_erlang_components({[], _left_pre}, {_rights, _right_pre}) do | ||
| :lt | ||
| end | ||
|
|
||
| defp cmp_erlang_components({_lefts, _left_pre}, {[], _right_pre}) do | ||
| :gt | ||
| end |
There was a problem hiding this comment.
That could live in some shared utils module. Taken from DockerChecker.
| # elixir:1.19.5-erlang-28.3.1.txt | ||
| 1.19.5-erlang-28.3.1-ubuntu-noble-20260210.1 amd64,arm64 | ||
| 1.19.5-erlang-28.3.1-debian-trixie-20260202-slim amd64,arm64 | ||
| 1.19.5-erlang-28.3.1-debian-bookworm-20260202-slim amd64,arm64 |
There was a problem hiding this comment.
We could think about adding a header line or first line comment explaining that people consuming this should be prepared to handle added columns in the future.
# If you consume this file programmatically, always skip the first line. The second line contains a header. Columns are whitespace separated and we may add new columns in the future.
# tag architectures
# ...
| ], | ||
| [ | ||
| module: Bob.Job.DockerTxtUpdater, | ||
| period: {60, :min}, |
There was a problem hiding this comment.
No idea what's appropriate there.
|
|
||
| key = | ||
| "builds/docker/" <> | ||
| String.trim_leading(repo, "hexpm/") <> ":" <> elixir <> "-erlang-" <> erlang <> ".txt" |
There was a problem hiding this comment.
As you likely want to replace only the first occurrence? Not sure if you have multiple anyway...
| String.trim_leading(repo, "hexpm/") <> ":" <> elixir <> "-erlang-" <> erlang <> ".txt" | |
| String.replace_leading(repo, "hexpm/", "") <> ":" <> elixir <> "-erlang-" <> erlang <> ".txt" |
| |> Enum.map(fn {elixir, erlang} -> | ||
| parsed_erl = to_matchable(erlang) | ||
| {Version.parse!(normalize_version(elixir)), parsed_erl} | ||
| end) | ||
| |> Enum.filter(fn {vsn, {_erl_major, erl_pre}} -> vsn.pre == [] and erl_pre == [] end) | ||
| |> Enum.group_by(fn {vsn, _} -> {vsn.major, vsn.minor} end) |
There was a problem hiding this comment.
If the concern is performance, this could be a single Enum.reduce with a Map.update(...) but, other than that, I haven't seen many more optimization points.
Closes #234.
This uses a lot of Enum calls, so it is very much not memory efficient, but I don't know if that's a problem.
I decided to just assume that the cached tags are available. Since I have no good way to test this code in full, I wrote it in a Livebook with the Repo and Cache stubbed: https://gist.github.com/SteffenDE/c523ea5ccd9b97711ba07918d45e905d
(Note that it uses the files I scraped from Docker Hub, available at https://hex-bob-docker.steffend.me/all.zip)