tests for release config provider
[akkoma] / mix.exs
1 defmodule Pleroma.Mixfile do
2 use Mix.Project
3
4 def project do
5 [
6 app: :pleroma,
7 version: version("2.3.50"),
8 elixir: "~> 1.9",
9 elixirc_paths: elixirc_paths(Mix.env()),
10 compilers: [:phoenix, :gettext] ++ Mix.compilers(),
11 elixirc_options: [warnings_as_errors: warnings_as_errors(Mix.env())],
12 xref: [exclude: [:eldap]],
13 start_permanent: Mix.env() == :prod,
14 aliases: aliases(),
15 deps: deps(),
16 test_coverage: [tool: ExCoveralls],
17 preferred_cli_env: ["coveralls.html": :test],
18 # Docs
19 name: "Pleroma",
20 homepage_url: "https://pleroma.social/",
21 source_url: "https://git.pleroma.social/pleroma/pleroma",
22 docs: [
23 source_url_pattern:
24 "https://git.pleroma.social/pleroma/pleroma/blob/develop/%{path}#L%{line}",
25 logo: "priv/static/images/logo.png",
26 extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"),
27 groups_for_extras: [
28 "Installation manuals": Path.wildcard("docs/installation/*.md"),
29 Configuration: Path.wildcard("docs/config/*.md"),
30 Administration: Path.wildcard("docs/admin/*.md"),
31 "Pleroma's APIs and Mastodon API extensions": Path.wildcard("docs/api/*.md")
32 ],
33 main: "readme",
34 output: "priv/static/doc"
35 ],
36 releases: [
37 pleroma: [
38 include_executables_for: [:unix],
39 applications: [ex_syslogger: :load, syslog: :load, eldap: :transient],
40 steps: [:assemble, &put_otp_version/1, &copy_files/1, &copy_nginx_config/1],
41 config_providers: [{Pleroma.Config.ReleaseRuntimeProvider, release_config_paths()}]
42 ]
43 ]
44 ]
45 end
46
47 def put_otp_version(%{path: target_path} = release) do
48 File.write!(
49 Path.join([target_path, "OTP_VERSION"]),
50 Pleroma.OTPVersion.version()
51 )
52
53 release
54 end
55
56 def copy_files(%{path: target_path} = release) do
57 File.cp_r!("./rel/files", target_path)
58 release
59 end
60
61 def copy_nginx_config(%{path: target_path} = release) do
62 File.cp!(
63 "./installation/pleroma.nginx",
64 Path.join([target_path, "installation", "pleroma.nginx"])
65 )
66
67 release
68 end
69
70 defp release_config_paths do
71 config_path = System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
72
73 exported_config_path =
74 config_path
75 |> Path.dirname()
76 |> Path.join("#{Mix.env()}.exported_from_db.secret.exs")
77
78 [config_path: config_path, exported_config_path: exported_config_path]
79 end
80
81 # Configuration for the OTP application.
82 #
83 # Type `mix help compile.app` for more information.
84 def application do
85 [
86 mod: {Pleroma.Application, []},
87 extra_applications: [
88 :logger,
89 :runtime_tools,
90 :comeonin,
91 :quack,
92 :fast_sanitize,
93 :ssl
94 ],
95 included_applications: [:ex_syslogger]
96 ]
97 end
98
99 # Specifies which paths to compile per environment.
100 defp elixirc_paths(:benchmark), do: ["lib", "benchmarks"]
101 defp elixirc_paths(:test), do: ["lib", "test/support"]
102 defp elixirc_paths(_), do: ["lib"]
103
104 defp warnings_as_errors(:prod), do: false
105 defp warnings_as_errors(_), do: true
106
107 # Specifies OAuth dependencies.
108 defp oauth_deps do
109 oauth_strategy_packages =
110 System.get_env("OAUTH_CONSUMER_STRATEGIES")
111 |> to_string()
112 |> String.split()
113 |> Enum.map(fn strategy_entry ->
114 with [_strategy, dependency] <- String.split(strategy_entry, ":") do
115 dependency
116 else
117 [strategy] -> "ueberauth_#{strategy}"
118 end
119 end)
120
121 for s <- oauth_strategy_packages, do: {String.to_atom(s), ">= 0.0.0"}
122 end
123
124 # Specifies your project dependencies.
125 #
126 # Type `mix help deps` for examples and options.
127 defp deps do
128 [
129 {:phoenix, "~> 1.5.5"},
130 {:tzdata, "~> 1.0.3"},
131 {:plug_cowboy, "~> 2.3"},
132 {:phoenix_pubsub, "~> 2.0"},
133 {:phoenix_ecto, "~> 4.0"},
134 {:ecto_enum, "~> 1.4"},
135 {:ecto_explain, "~> 0.1.2"},
136 {:ecto_sql, "~> 3.4.4"},
137 {:postgrex, ">= 0.15.5"},
138 {:oban, "~> 2.3.4"},
139 {:gettext, "~> 0.18"},
140 {:bcrypt_elixir, "~> 2.2"},
141 {:trailing_format_plug, "~> 0.0.7"},
142 {:fast_sanitize, "~> 0.2.0"},
143 {:html_entities, "~> 0.5", override: true},
144 {:phoenix_html, "~> 2.14"},
145 {:calendar, "~> 1.0"},
146 {:cachex, "~> 3.2"},
147 {:poison, "~> 3.0", override: true},
148 {:tesla, "~> 1.4.0", override: true},
149 {:castore, "~> 0.1"},
150 {:cowlib, "~> 2.9", override: true},
151 {:gun,
152 github: "ninenines/gun", ref: "921c47146b2d9567eac7e9a4d2ccc60fffd4f327", override: true},
153 {:jason, "~> 1.2"},
154 {:mogrify, "~> 0.7.4"},
155 {:ex_aws, "~> 2.1.6"},
156 {:ex_aws_s3, "~> 2.0"},
157 {:sweet_xml, "~> 0.6.6"},
158 {:earmark, "1.4.3"},
159 {:bbcode_pleroma, "~> 0.2.0"},
160 {:crypt,
161 git: "https://git.pleroma.social/pleroma/elixir-libraries/crypt.git",
162 ref: "cf2aa3f11632e8b0634810a15b3e612c7526f6a3"},
163 {:cors_plug, "~> 2.0"},
164 {:web_push_encryption, "~> 0.3"},
165 {:swoosh, "~> 1.0"},
166 {:phoenix_swoosh, "~> 0.3"},
167 {:gen_smtp, "~> 0.13"},
168 {:ex_syslogger, "~> 1.4"},
169 {:floki, "~> 0.27"},
170 {:timex, "~> 3.6"},
171 {:ueberauth, "~> 0.4"},
172 {:linkify, "~> 0.5.0"},
173 {:http_signatures, "~> 0.1.0"},
174 {:telemetry, "~> 0.3"},
175 {:poolboy, "~> 1.5"},
176 {:prometheus, "~> 4.6"},
177 {:prometheus_ex,
178 git: "https://git.pleroma.social/pleroma/elixir-libraries/prometheus.ex.git",
179 ref: "a4e9beb3c1c479d14b352fd9d6dd7b1f6d7deee5",
180 override: true},
181 {:prometheus_plugs, "~> 1.1"},
182 {:prometheus_phoenix, "~> 1.3"},
183 # Note: once `prometheus_phx` is integrated into `prometheus_phoenix`, remove the former:
184 {:prometheus_phx,
185 git: "https://git.pleroma.social/pleroma/elixir-libraries/prometheus-phx.git",
186 branch: "no-logging"},
187 {:prometheus_ecto, "~> 1.4"},
188 {:recon, "~> 2.5"},
189 {:quack, "~> 0.1.1"},
190 {:joken, "~> 2.0"},
191 {:benchee, "~> 1.0"},
192 {:pot, "~> 0.11"},
193 {:esshd, "~> 0.1.0", runtime: Application.get_env(:esshd, :enabled, false)},
194 {:ex_const, "~> 0.2"},
195 {:plug_static_index_html, "~> 1.0.0"},
196 {:flake_id, "~> 0.1.0"},
197 {:concurrent_limiter,
198 git: "https://git.pleroma.social/pleroma/elixir-libraries/concurrent_limiter.git",
199 ref: "d81be41024569330f296fc472e24198d7499ba78"},
200 {:remote_ip,
201 git: "https://git.pleroma.social/pleroma/remote_ip.git",
202 ref: "b647d0deecaa3acb140854fe4bda5b7e1dc6d1c8"},
203 {:captcha,
204 git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
205 ref: "e0f16822d578866e186a0974d65ad58cddc1e2ab"},
206 {:restarter, path: "./restarter"},
207 {:majic,
208 git: "https://git.pleroma.social/pleroma/elixir-libraries/majic.git",
209 ref: "289cda1b6d0d70ccb2ba508a2b0bd24638db2880"},
210 {:open_api_spex, "~> 3.10"},
211
212 ## dev & test
213 {:ex_doc, "~> 0.22", only: :dev, runtime: false},
214 {:ex_machina, "~> 2.4", only: :test},
215 {:credo, "~> 1.4", only: [:dev, :test], runtime: false},
216 {:mock, "~> 0.3.5", only: :test},
217 # temporary downgrade for excoveralls, hackney until hackney max_connections bug will be fixed
218 {:excoveralls, "0.12.3", only: :test},
219 {:hackney,
220 git: "https://git.pleroma.social/pleroma/elixir-libraries/hackney.git",
221 ref: "7d7119f0651515d6d7669c78393fd90950a3ec6e",
222 override: true},
223 {:mox, "~> 1.0", only: :test},
224 {:websocket_client, git: "https://github.com/jeremyong/websocket_client.git", only: :test}
225 ] ++ oauth_deps()
226 end
227
228 # Aliases are shortcuts or tasks specific to the current project.
229 # For example, to create, migrate and run the seeds file at once:
230 #
231 # $ mix ecto.setup
232 #
233 # See the documentation for `Mix` for more info on aliases.
234 defp aliases do
235 [
236 "ecto.migrate": ["pleroma.ecto.migrate"],
237 "ecto.rollback": ["pleroma.ecto.rollback"],
238 "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
239 "ecto.reset": ["ecto.drop", "ecto.setup"],
240 test: ["ecto.create --quiet", "ecto.migrate", "test"],
241 docs: ["pleroma.docs", "docs"],
242 analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"],
243 copyright: &add_copyright/1,
244 "copyright.bump": &bump_copyright/1
245 ]
246 end
247
248 # Builds a version string made of:
249 # * the application version
250 # * a pre-release if ahead of the tag: the describe string (-count-commithash)
251 # * branch name
252 # * build metadata:
253 # * a build name if `PLEROMA_BUILD_NAME` or `:pleroma, :build_name` is defined
254 # * the mix environment if different than prod
255 defp version(version) do
256 identifier_filter = ~r/[^0-9a-z\-]+/i
257
258 git_available? = match?({_output, 0}, System.cmd("sh", ["-c", "command -v git"]))
259
260 git_pre_release =
261 if git_available? do
262 {tag, tag_err} =
263 System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
264
265 {describe, describe_err} = System.cmd("git", ["describe", "--tags", "--abbrev=8"])
266 {commit_hash, commit_hash_err} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
267
268 # Pre-release version, denoted from patch version with a hyphen
269 cond do
270 tag_err == 0 and describe_err == 0 ->
271 describe
272 |> String.trim()
273 |> String.replace(String.trim(tag), "")
274 |> String.trim_leading("-")
275 |> String.trim()
276
277 commit_hash_err == 0 ->
278 "0-g" <> String.trim(commit_hash)
279
280 true ->
281 nil
282 end
283 end
284
285 # Branch name as pre-release version component, denoted with a dot
286 branch_name =
287 with true <- git_available?,
288 {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
289 branch_name <- String.trim(branch_name),
290 branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
291 true <-
292 !Enum.any?(["master", "HEAD", "release/", "stable"], fn name ->
293 String.starts_with?(name, branch_name)
294 end) do
295 branch_name =
296 branch_name
297 |> String.trim()
298 |> String.replace(identifier_filter, "-")
299
300 branch_name
301 else
302 _ -> ""
303 end
304
305 build_name =
306 cond do
307 name = Application.get_env(:pleroma, :build_name) -> name
308 name = System.get_env("PLEROMA_BUILD_NAME") -> name
309 true -> nil
310 end
311
312 env_name = if Mix.env() != :prod, do: to_string(Mix.env())
313 env_override = System.get_env("PLEROMA_BUILD_ENV")
314
315 env_name =
316 case env_override do
317 nil -> env_name
318 env_override when env_override in ["", "prod"] -> nil
319 env_override -> env_override
320 end
321
322 # Pre-release version, denoted by appending a hyphen
323 # and a series of dot separated identifiers
324 pre_release =
325 [git_pre_release, branch_name]
326 |> Enum.filter(fn string -> string && string != "" end)
327 |> Enum.join(".")
328 |> (fn
329 "" -> nil
330 string -> "-" <> String.replace(string, identifier_filter, "-")
331 end).()
332
333 # Build metadata, denoted with a plus sign
334 build_metadata =
335 [build_name, env_name]
336 |> Enum.filter(fn string -> string && string != "" end)
337 |> Enum.join(".")
338 |> (fn
339 "" -> nil
340 string -> "+" <> String.replace(string, identifier_filter, "-")
341 end).()
342
343 [version, pre_release, build_metadata]
344 |> Enum.filter(fn string -> string && string != "" end)
345 |> Enum.join()
346 end
347
348 defp add_copyright(_) do
349 year = NaiveDateTime.utc_now().year
350 template = ~s[\
351 # Pleroma: A lightweight social networking server
352 # Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>
353 # SPDX-License-Identifier: AGPL-3.0-only
354
355 ] |> String.replace("\n", "\\n")
356
357 find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec "
358 grep = "grep -L '# Copyright © [0-9\-]* Pleroma' {} \\;"
359 xargs = "xargs -n1 sed -i'' '1s;^;#{template};'"
360
361 :os.cmd(String.to_charlist("#{find}#{grep} | #{xargs}"))
362 end
363
364 defp bump_copyright(_) do
365 year = NaiveDateTime.utc_now().year
366 find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\)"
367
368 xargs =
369 "xargs sed -i'' 's;# Copyright © [0-9\-]* Pleroma.*$;# Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>;'"
370
371 :os.cmd(String.to_charlist("#{find} | #{xargs}"))
372 end
373 end