Skip to content

Commit ee407a7

Browse files
authored
Merge pull request #1 from togethercomputer/aj/eng-32100-assign-ownership-and-add-ci-workflows-to-shared-elixir
Post-publication cleanup
2 parents c889207 + 94da1f2 commit ee407a7

File tree

8 files changed

+251
-58
lines changed

8 files changed

+251
-58
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@togethercomputer/elixir

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
on: pull_request
3+
4+
permissions:
5+
contents: read
6+
issues: read
7+
checks: write
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
container: hexpm/elixir:1.18.3-erlang-27.3.3-debian-bookworm-20250407-slim
18+
steps:
19+
- name: Install Tools
20+
run: apt update && apt install --no-install-recommends --yes build-essential git
21+
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Fetch Hex Cache
26+
uses: actions/cache@v4
27+
id: hex-cache
28+
with:
29+
path: |
30+
deps
31+
_build
32+
key: ${{ runner.os }}-mix-${{ hashFiles('mix.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-mix-
35+
36+
- name: Run Tests
37+
run: |
38+
mix local.hex --force
39+
mix local.rebar --force
40+
git config --global --add safe.directory '*'
41+
mix deps.get
42+
MIX_ENV=test mix compile --warnings-as-errors
43+
mix test
44+
45+
- name: Publish Results
46+
uses: mikepenz/action-junit-report@v5
47+
if: ${{ failure() }}
48+
with:
49+
check_name: Test Results
50+
report_paths: _build/test/lib/together/*.xml
51+
52+
style:
53+
name: Style
54+
runs-on: ubuntu-latest
55+
container: hexpm/elixir:1.18.3-erlang-27.3.3-debian-bookworm-20250407-slim
56+
steps:
57+
- name: Install Tools
58+
run: apt update && apt install --no-install-recommends --yes build-essential git
59+
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
63+
- name: Fetch Hex Cache
64+
uses: actions/cache/restore@v4
65+
id: hex-cache
66+
with:
67+
path: |
68+
deps
69+
_build
70+
key: ${{ runner.os }}-mix-${{ hashFiles('mix.lock') }}
71+
restore-keys: |
72+
${{ runner.os }}-mix-
73+
74+
- name: Install
75+
run: |
76+
mix local.hex --force
77+
mix local.rebar --force
78+
git config --global --add safe.directory '*'
79+
mix deps.get
80+
81+
- name: Check Unused Dependencies
82+
run: mix deps.unlock --check-unused
83+
84+
- name: Check Formatting
85+
run: mix format --check-formatted
86+
if: always()
87+
88+
- name: Check Credo
89+
run: mix credo
90+
if: always()

.github/workflows/main.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Cache & Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch: {}
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
cache:
15+
name: "Cache"
16+
outputs:
17+
page_url: ${{ steps.docs.outputs.page_url }}
18+
runs-on: ubuntu-latest
19+
container: hexpm/elixir:1.18.3-erlang-27.3.3-debian-bookworm-20250407-slim
20+
steps:
21+
- name: Install Tools
22+
run: apt update && apt install --no-install-recommends --yes build-essential git
23+
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Fetch Hex Cache
28+
uses: actions/cache@v4
29+
id: hex-cache
30+
with:
31+
path: |
32+
deps
33+
_build
34+
key: ${{ runner.os }}-mix-${{ hashFiles('mix.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-mix-
37+
38+
- name: Precompile
39+
run: |
40+
mix local.hex --force
41+
mix local.rebar --force
42+
mix deps.get
43+
MIX_ENV=dev mix compile
44+
MIX_ENV=test mix compile
45+
MIX_ENV=prod mix compile
46+
MIX_ENV=prod mix docs
47+
48+
- name: Upload Docs
49+
id: docs
50+
uses: actions/upload-pages-artifact@v3
51+
with:
52+
path: doc/
53+
54+
docs:
55+
name: "Docs"
56+
needs: cache
57+
permissions:
58+
pages: write
59+
id-token: write
60+
environment:
61+
name: github-pages
62+
url: ${{ needs.cache.outputs.page_url }}
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v4

lib/together.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
defmodule Together do
2+
@moduledoc false
23
end

lib/together/test/fixtures.ex

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,62 +62,63 @@ defmodule Together.Test.Fixtures do
6262
@spec randomize(any, [String.t()]) :: any
6363
def randomize(value, extra_keys) do
6464
id_map = Process.get(@id_map_dictionary_key, %{})
65-
{id_map, value} = randomize(id_map, value, extra_keys)
65+
{id_map, value} = do_randomize(id_map, value, extra_keys, false)
6666
Process.put(@id_map_dictionary_key, id_map)
6767

6868
value
6969
end
7070

71-
@spec randomize(map, any, [String.t()]) :: {map, any}
72-
defp randomize(id_map, map_value, extra_keys) when is_map(map_value) do
73-
Enum.reduce(map_value, {id_map, %{}}, fn
74-
{key, value}, {id_map, modified_map} ->
75-
if key == "id" or String.ends_with?(key, "_id") or key in extra_keys do
76-
cond do
77-
is_nil(value) ->
78-
{id_map, modified_map}
79-
80-
is_integer(value) ->
81-
new_id = Map.get_lazy(id_map, value, fn -> System.unique_integer([:positive]) end)
82-
{Map.put(id_map, value, new_id), Map.put(modified_map, key, new_id)}
83-
84-
is_binary(value) ->
85-
case Regex.scan(@uuid_re, value) do
86-
[] ->
87-
new_id = Map.get_lazy(id_map, value, fn -> "gen_" <> Ecto.UUID.generate() end)
88-
{Map.put(id_map, value, new_id), Map.put(modified_map, key, new_id)}
89-
90-
matches ->
91-
{id_map, modified_value} =
92-
Enum.reduce(matches, {id_map, value}, fn [match], {id_map, modified_value} ->
93-
new_id = Map.get_lazy(id_map, match, fn -> Ecto.UUID.generate() end)
94-
95-
{Map.put(id_map, match, new_id),
96-
String.replace(modified_value, match, new_id)}
97-
end)
98-
99-
{id_map, Map.put(modified_map, key, modified_value)}
100-
end
101-
102-
:else ->
103-
{id_map, modified_map}
104-
end
105-
else
106-
{id_map, modified_value} = randomize(id_map, value, extra_keys)
107-
{id_map, Map.put(modified_map, key, modified_value)}
108-
end
71+
@spec do_randomize(map, any, [String.t()], boolean) :: {map, any}
72+
defp do_randomize(ids, value, extra_keys, is_id?)
73+
74+
# Maps
75+
defp do_randomize(id_map, map_value, extra_keys, _is_id?) when is_map(map_value) do
76+
Enum.reduce(map_value, {id_map, %{}}, fn {key, value}, {id_map, modified_map} ->
77+
is_id? = key == "id" or String.ends_with?(key, "_id") or key in extra_keys
78+
79+
{id_map, modified_value} = do_randomize(id_map, value, extra_keys, is_id?)
80+
{id_map, Map.put(modified_map, key, modified_value)}
10981
end)
11082
end
11183

112-
defp randomize(id_map, list_value, extra_keys) when is_list(list_value) do
84+
# Lists
85+
defp do_randomize(id_map, list_value, extra_keys, _is_id?) when is_list(list_value) do
11386
{id_map, list_value} =
11487
Enum.reduce(list_value, {id_map, []}, fn list_element, {id_map, modified_list} ->
115-
{id_map, modified_list_element} = randomize(id_map, list_element, extra_keys)
88+
{id_map, modified_list_element} = do_randomize(id_map, list_element, extra_keys, false)
11689
{id_map, [modified_list_element | modified_list]}
11790
end)
11891

11992
{id_map, Enum.reverse(list_value)}
12093
end
12194

122-
defp randomize(id_map, value, _extra_keys), do: {id_map, value}
95+
# Integer IDs
96+
defp do_randomize(id_map, integer_value, _extra_keys, true) when is_integer(integer_value) do
97+
new_id = Map.get_lazy(id_map, integer_value, fn -> System.unique_integer([:positive]) end)
98+
new_id_map = Map.put_new(id_map, integer_value, new_id)
99+
100+
{new_id_map, new_id}
101+
end
102+
103+
# Binary IDs
104+
defp do_randomize(id_map, binary_value, _extra_keys, true) when is_binary(binary_value) do
105+
case Regex.scan(@uuid_re, binary_value) do
106+
[] ->
107+
new_id = Map.get_lazy(id_map, binary_value, fn -> "gen_" <> Ecto.UUID.generate() end)
108+
{Map.put(id_map, binary_value, new_id), new_id}
109+
110+
matches ->
111+
{id_map, modified_value} =
112+
Enum.reduce(matches, {id_map, binary_value}, fn [match], {id_map, modified_value} ->
113+
new_id = Map.get_lazy(id_map, match, fn -> Ecto.UUID.generate() end)
114+
115+
{Map.put(id_map, match, new_id), String.replace(modified_value, match, new_id)}
116+
end)
117+
118+
{id_map, modified_value}
119+
end
120+
end
121+
122+
# Nil and non-ID values
123+
defp do_randomize(id_map, value, _extra_keys, _is_id?), do: {id_map, value}
123124
end

mix.exs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ defmodule Together.MixProject do
77
version: "0.1.0",
88
elixir: "~> 1.18",
99
start_permanent: Mix.env() == :prod,
10-
deps: deps()
10+
deps: deps(),
11+
12+
# Docs
13+
docs: docs(),
14+
name: "Together Elixir Common",
15+
source_url: "https://github.com/togethercomputer/elixir-common",
16+
homepage_url: "https://github.com/togethercomputer/elixir-common"
1117
]
1218
end
1319

@@ -19,7 +25,24 @@ defmodule Together.MixProject do
1925

2026
defp deps do
2127
[
22-
{:ecto, "~> 3.5", optional: true}
28+
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
29+
{:ecto, "~> 3.5", optional: true},
30+
{:ex_doc, "~> 0.38", only: [:dev], runtime: false}
31+
]
32+
end
33+
34+
defp docs do
35+
[
36+
main: "readme",
37+
extras: [
38+
"README.md": [title: "Introduction"],
39+
LICENSE: [title: "License"]
40+
],
41+
formatters: ["html"],
42+
groups_for_modules: [
43+
Testing: [~r/Together.Test/]
44+
],
45+
source_ref: "main"
2346
]
2447
end
2548
end

mix.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
%{
2+
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
3+
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
24
"decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"},
5+
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
36
"ecto": {:hex, :ecto, "3.13.0", "7528ef4f3a4cdcfebeb7eb6545806c8109529b385a69f701fc3d77b5b8bde6e7", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "061f095f1cc097f71f743b500affc792d6869df22b1946a73ab5495eb9b4a280"},
7+
"ex_doc": {:hex, :ex_doc, "0.38.2", "504d25eef296b4dec3b8e33e810bc8b5344d565998cd83914ffe1b8503737c02", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "732f2d972e42c116a70802f9898c51b54916e542cc50968ac6980512ec90f42b"},
8+
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
9+
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
10+
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
11+
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
12+
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
13+
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
414
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
515
}

0 commit comments

Comments
 (0)