-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathmix.exs
319 lines (287 loc) · 9.59 KB
/
mix.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
defmodule FunWithFlags.Mixfile do
use Mix.Project
@source_url "https://github.com/tompave/fun_with_flags"
@version "1.12.0"
def project do
[
app: :fun_with_flags,
version: @version,
elixir: "~> 1.15",
elixirc_paths: elixirc_paths(Mix.env),
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps(),
description: description(),
package: package(),
docs: docs(),
aliases: aliases(),
dialyzer: dialyzer(),
]
end
def application do
# Specify extra applications you'll use from Erlang/Elixir
[extra_applications: extra_applications(Mix.env),
mod: {FunWithFlags.Application, []}]
end
defp extra_applications(:test), do: local_extra_applications()
defp extra_applications(:dev), do: local_extra_applications()
defp extra_applications(_), do: [:logger]
# When working locally with the Ecto adapter, start the ecto_sql
# and postgrex applications. They're not started automatically
# because they're optional, I think.
#
# Also start the Phoenix PubSub application if that notification
# adapter is configured.
#
defp local_extra_applications do
# Required to run the Erlang observer with Elixir 1.15 and above.
# https://elixirforum.com/t/cannot-start-observer-undefinedfunctionerror-function-observer-start-0-is-undefined/56642
# https://github.com/elixir-lang/elixir/blob/v1.15/CHANGELOG.md#potential-incompatibilities
apps =
if Version.match?(System.version, ">= 1.15.0") do
[:logger, :observer, :wx, :runtime_tools]
else
[:logger]
end
apps =
if System.get_env("PERSISTENCE") == "ecto" do
apps ++ [:ecto, :ecto_sql, :postgrex]
else
apps
end
apps =
if System.get_env("PUBSUB_BROKER") == "phoenix_pubsub" do
[:phoenix_pubsub | apps]
else
apps
end
apps
end
defp deps do
[
{:redix, "~> 1.0", optional: true},
{:ecto_sql, "~> 3.0", optional: true},
{:ecto_sqlite3, "~> 0.8", optional: true, only: [:dev, :test]},
{:postgrex, "~> 0.16", optional: true, only: [:dev, :test]},
{:myxql, "~> 0.2", optional: true, only: [:dev, :test]},
{:phoenix_pubsub, "~> 2.0", optional: true},
{:mock, "~> 0.3", only: :test},
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
{:credo, "~> 1.7", only: :dev, runtime: false},
{:dialyxir, "~> 1.0", only: :dev, runtime: false}
]
end
defp dialyzer do
[
# Add optional dependencies to avoid "unknown_function" warnings.
plt_add_apps: [:redix, :ecto, :ecto_sql, :phoenix_pubsub],
]
end
defp aliases do
[
{:"test.all", [&run_all_tests/1]},
{:"test.phx", [&run_tests__redis_pers__phoenix_pubsub/1]},
{:"test.ecto.postgres", [&run_tests__ecto_pers_postgres__phoenix_pubsub/1]},
{:"test.ecto.mysql", [&run_tests__ecto_pers_mysql__phoenix_pubsub/1]},
{:"test.ecto.sqlite", [&run_tests__ecto_pers_sqlite__phoenix_pubsub/1]},
{:"test.redis", [&run_tests__redis_pers__redis_pubsub/1]},
]
end
# Runs all the test configurations.
# If any fails, exit with status code 1, so that this can properly fail in CI.
#
defp run_all_tests(arg) do
tests = [
&run_tests__redis_pers__redis_pubsub/1, &run_integration_tests__redis_pers__redis_pubsub__no_cache/1,
&run_tests__redis_pers__phoenix_pubsub/1, &run_integration_tests__redis_pers__phoenix_pubsub__no_cache/1,
&run_tests__ecto_pers_postgres__phoenix_pubsub/1, &run_integration_tests__ecto_pers_postgres__phoenix_pubsub__no_cache/1,
&run_tests__ecto_pers_mysql__phoenix_pubsub/1, &run_integration_tests__ecto_pers_mysql__phoenix_pubsub__no_cache/1,
&run_tests__ecto_pers_sqlite__phoenix_pubsub/1, &run_integration_tests__ecto_pers_sqlite__phoenix_pubsub__no_cache/1,
]
exit_codes = case System.get_env("CI") do
"true" ->
tests |> Enum.map(fn test_fn -> _run_test_with_retries(3, 500, fn -> test_fn.(arg) end) end)
_ ->
tests |> Enum.map(fn test_fn -> test_fn.(arg) end)
end
if Enum.any?(exit_codes, &(&1 != 0)) do
require Logger
Logger.error("Some test configuration did not pass.")
exit({:shutdown, 1})
end
end
# Because some tests are flaky in CI.
#
defp _run_test_with_retries(attempts, sleep_ms, test_fn) when attempts > 0 do
IO.puts("---\nRunning a test task with retries. Attempts left: #{attempts}, sleep ms: #{sleep_ms}.\n---")
case test_fn.() do
0 -> 0 # Successful run, simply return the status.
_ ->
:timer.sleep(sleep_ms)
remaining = attempts - 1
IO.puts("Test failed. Retries left: #{remaining}.")
_run_test_with_retries(remaining, sleep_ms, test_fn)
end
end
defp _run_test_with_retries(_, _, _) do
IO.puts("---\nAll retries failed. Returning exit code 1.\n---")
1
end
# Run the tests with Redis as persistent store and Redis PubSub as broker.
#
# Cache enabled, force re-compilation.
#
defp run_tests__redis_pers__redis_pubsub(arg) do
Mix.shell.cmd(
"mix test --color --force --exclude phoenix_pubsub --exclude ecto_persistence #{arg}",
env: [
{"CACHE_ENABLED", "true"},
]
)
end
# Runs the integration tests only.
# Cache disabled, Redis as persistent store and Redis PubSub as broker.
#
defp run_integration_tests__redis_pers__redis_pubsub__no_cache(arg) do
Mix.shell.cmd(
"mix test --color --force --only integration #{arg}",
env: [
{"CACHE_ENABLED", "false"},
]
)
end
# Run the tests with Redis as persistent store and Phoenix.PubSub as broker.
#
defp run_tests__redis_pers__phoenix_pubsub(arg) do
Mix.shell.cmd(
"mix test --color --force --exclude redis_pubsub --exclude ecto_persistence #{arg}",
env: [
{"CACHE_ENABLED", "true"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
]
)
end
# Runs the integration tests only.
# Cache disabled, Redis as persistent store and Phoenix.PubSubas broker.
#
defp run_integration_tests__redis_pers__phoenix_pubsub__no_cache(arg) do
Mix.shell.cmd(
"mix test --color --force --only integration #{arg}",
env: [
{"CACHE_ENABLED", "false"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
]
)
end
# Run the tests with Ecto+PostgreSQL as persistent store and Phoenix.PubSub as broker.
#
defp run_tests__ecto_pers_postgres__phoenix_pubsub(arg) do
Mix.shell.cmd(
"mix test --color --force --exclude redis_pubsub --exclude redis_persistence #{arg}",
env: [
{"CACHE_ENABLED", "true"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
{"PERSISTENCE", "ecto"},
{"RDBMS", "postgres"},
]
)
end
# Run the tests with Ecto+MySQL as persistent store and Phoenix.PubSub as broker.
#
defp run_tests__ecto_pers_mysql__phoenix_pubsub(arg) do
Mix.shell.cmd(
"mix test --color --force --exclude redis_pubsub --exclude redis_persistence #{arg}",
env: [
{"CACHE_ENABLED", "true"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
{"PERSISTENCE", "ecto"},
{"RDBMS", "mysql"},
]
)
end
# Run the tests with Ecto+SQLite as persistent store and Phoenix.PubSub as broker.
#
defp run_tests__ecto_pers_sqlite__phoenix_pubsub(arg) do
Mix.shell.cmd(
"mix test --color --force --exclude redis_pubsub --exclude redis_persistence #{arg}",
env: [
{"CACHE_ENABLED", "true"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
{"PERSISTENCE", "ecto"},
{"RDBMS", "sqlite"},
]
)
end
# Runs the integration tests only.
# Cache disabled, Ecto+PostgreSQL as persistent store and Phoenix.PubSub as broker.
#
defp run_integration_tests__ecto_pers_postgres__phoenix_pubsub__no_cache(arg) do
Mix.shell.cmd(
"mix test --color --force --only integration #{arg}",
env: [
{"CACHE_ENABLED", "false"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
{"PERSISTENCE", "ecto"},
{"RDBMS", "postgres"},
]
)
end
# Runs the integration tests only.
# Cache disabled, Ecto+MySQL as persistent store and Phoenix.PubSub as broker.
#
defp run_integration_tests__ecto_pers_mysql__phoenix_pubsub__no_cache(arg) do
Mix.shell.cmd(
"mix test --color --force --only integration #{arg}",
env: [
{"CACHE_ENABLED", "false"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
{"PERSISTENCE", "ecto"},
{"RDBMS", "mysql"},
]
)
end
# Runs the integration tests only.
# Cache disabled, Ecto+SQLite as persistent store and Phoenix.PubSub as broker.
#
defp run_integration_tests__ecto_pers_sqlite__phoenix_pubsub__no_cache(arg) do
Mix.shell.cmd(
"mix test --color --force --only integration #{arg}",
env: [
{"CACHE_ENABLED", "false"},
{"PUBSUB_BROKER", "phoenix_pubsub"},
{"PERSISTENCE", "ecto"},
{"RDBMS", "sqlite"},
]
)
end
defp elixirc_paths(:test), do: ["lib", "test/support", "dev_support"]
defp elixirc_paths(:dev), do: ["lib", "dev_support"]
defp elixirc_paths(_), do: ["lib"]
defp description do
"""
FunWithFlags, a flexible and fast feature toggle library for Elixir.
"""
end
defp package do
[
maintainers: [
"Tommaso Pavese"
],
licenses: [
"MIT"
],
links: %{
"GitHub" => @source_url,
"Changelog" => "#{@source_url}/blob/master/CHANGELOG.md"
}
]
end
defp docs do
[
extras: ["README.md", "CHANGELOG.md"],
main: "FunWithFlags",
source_url: @source_url,
source_ref: "v#{@version}"
]
end
end