total rebase
[anni] / mix.exs
1 defmodule Pleroma.Mixfile do
2   use Mix.Project
3
4   def project do
5     [
6       app: :pleroma,
7       version: version("2.6.2"),
8       elixir: "~> 1.11",
9       elixirc_paths: elixirc_paths(Mix.env()),
10       compilers: Mix.compilers(),
11       elixirc_options: [warnings_as_errors: warnings_as_errors()],
12       xref: [exclude: [:eldap]],
13       dialyzer: [plt_add_apps: [:mix, :eldap]],
14       start_permanent: Mix.env() == :prod,
15       aliases: aliases(),
16       deps: deps(),
17       test_coverage: [tool: :covertool, summary: true],
18       # Docs
19       name: "Pleroma",
20       homepage_url: "https://pleroma.social/",
21       source_url: "https://git.logografos.com/anni",
22       docs: [
23         source_url_pattern:
24           "https://git.logografos.com/?p=anni;a=summary",
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, []}]
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   # Configuration for the OTP application.
71   #
72   # Type `mix help compile.app` for more information.
73   def application do
74     [
75       mod: {Pleroma.Application, []},
76       extra_applications: [
77         :logger,
78         :runtime_tools,
79         :comeonin,
80         :fast_sanitize,
81         :os_mon,
82         :ssl
83       ],
84       included_applications: [:ex_syslogger]
85     ]
86   end
87
88   # Specifies which paths to compile per environment.
89   defp elixirc_paths(:benchmark), do: ["lib", "benchmarks", "priv/scrubbers"]
90   defp elixirc_paths(:test), do: ["lib", "test/support"]
91   defp elixirc_paths(_), do: ["lib"]
92
93   defp warnings_as_errors, do: System.get_env("CI") == "true"
94
95   # Specifies OAuth dependencies.
96   defp oauth_deps do
97     oauth_strategy_packages =
98       System.get_env("OAUTH_CONSUMER_STRATEGIES")
99       |> to_string()
100       |> String.split()
101       |> Enum.map(fn strategy_entry ->
102         with [_strategy, dependency] <- String.split(strategy_entry, ":") do
103           dependency
104         else
105           [strategy] -> "ueberauth_#{strategy}"
106         end
107       end)
108
109     for s <- oauth_strategy_packages, do: {String.to_atom(s), ">= 0.0.0"}
110   end
111
112   # Specifies your project dependencies.
113   #
114   # Type `mix help deps` for examples and options.
115   defp deps do
116     [
117       {:phoenix, "~> 1.7.3"},
118       {:phoenix_ecto, "~> 4.4"},
119       {:ecto_sql, "~> 3.10"},
120       {:ecto_enum, "~> 1.4"},
121       {:postgrex, ">= 0.0.0"},
122       {:phoenix_html, "~> 3.3"},
123       {:phoenix_live_reload, "~> 1.3.3", only: :dev},
124       {:phoenix_live_view, "~> 0.19.0"},
125       {:phoenix_live_dashboard, "~> 0.8.0"},
126       {:telemetry_metrics, "~> 0.6"},
127       {:telemetry_poller, "~> 1.0"},
128       {:tzdata, "~> 1.0.3"},
129       {:plug_cowboy, "~> 2.5"},
130       # oban 2.14 requires Elixir 1.12+
131       {:oban, "~> 2.13.4"},
132       {:gettext, "~> 0.20"},
133       {:bcrypt_elixir, "~> 2.2"},
134       {:trailing_format_plug, "~> 0.0.7"},
135       {:fast_sanitize, "~> 0.2.0"},
136       {:html_entities, "~> 0.5", override: true},
137       {:calendar, "~> 1.0"},
138       {:cachex, "~> 3.2"},
139       {:poison, "~> 3.0", override: true},
140       {:tesla, "~> 1.8.0"},
141       {:castore, "~> 0.1"},
142       {:cowlib, "~> 2.9", override: true},
143       {:gun, "~> 2.0.0-rc.1", override: true},
144       {:finch, "~> 0.15"},
145       {:jason, "~> 1.2"},
146       {:mogrify, "~> 0.8.0"},
147       {:ex_aws, "~> 2.1.6"},
148       {:ex_aws_s3, "~> 2.0"},
149       {:sweet_xml, "~> 0.7.2"},
150       # earmark 1.4.23 requires Elixir 1.12+
151       {:earmark, "1.4.22"},
152       {:bbcode_pleroma, "~> 0.2.0"},
153       {:cors_plug, "~> 2.0"},
154       {:web_push_encryption, "~> 0.3.1"},
155       # swoosh 1.11.2+ requires Elixir 1.12+
156       {:swoosh, "~> 1.10.0"},
157       {:phoenix_swoosh, "~> 1.1"},
158       {:gen_smtp, "~> 0.13"},
159       {:ex_syslogger, "~> 1.4"},
160       {:floki, "~> 0.35"},
161       {:timex, "~> 3.6"},
162       {:ueberauth, "~> 0.4"},
163       {:linkify,
164        git: "https://gitgud.io/mintplg/linkify.git",
165        branch: "domain-mention-parsing-fix"},
166       {:http_signatures, "~> 0.1.2"},
167       {:telemetry, "~> 1.0.0", override: true},
168       {:poolboy, "~> 1.5"},
169       {:prom_ex, "~> 1.9"},
170       {:recon, "~> 2.5"},
171       {:joken, "~> 2.0"},
172       {:pot, "~> 1.0"},
173       {:ex_const, "~> 0.2"},
174       {:plug_static_index_html, "~> 1.0.0"},
175       {:flake_id, "~> 0.1.0"},
176       {:concurrent_limiter, "~> 0.1.1"},
177       {:remote_ip,
178        git: "https://git.pleroma.social/pleroma/remote_ip.git",
179        ref: "b647d0deecaa3acb140854fe4bda5b7e1dc6d1c8"},
180       {:captcha,
181        git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
182        ref: "90f6ce7672f70f56708792a98d98bd05176c9176"},
183       {:restarter, path: "./restarter"},
184       {:majic, "~> 1.0"},
185       {:open_api_spex, "~> 3.16"},
186       {:ecto_psql_extras, "~> 0.6"},
187       {:vix, "~> 0.26.0"},
188       {:elixir_make, "~> 0.7.7", override: true},
189       {:blurhash, "~> 0.1.0", hex: :rinpatch_blurhash},
190       {:exile,
191        git: "https://github.com/akash-akya/exile.git",
192        ref: "be87c33b02a7c3c5d22d2ece01fbd462355b28ef"},
193       {:bandit, "~> 1.2"},
194
195       ## dev & test
196       {:ex_doc, "~> 0.22", only: :dev, runtime: false},
197       {:ex_machina, "~> 2.4", only: :test},
198       {:credo, "~> 1.6", only: [:dev, :test], runtime: false},
199       {:mock, "~> 0.3.5", only: :test},
200       {:covertool, "~> 2.0", only: :test},
201       {:hackney, "~> 1.18.0", override: true},
202       {:mox, "~> 1.0", only: :test},
203       {:websockex, "~> 0.4.3", only: :test},
204       {:benchee, "~> 1.0", only: :benchmark},
205       {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
206     ] ++ oauth_deps()
207   end
208
209   # Aliases are shortcuts or tasks specific to the current project.
210   # For example, to create, migrate and run the seeds file at once:
211   #
212   #     $ mix ecto.setup
213   #
214   # See the documentation for `Mix` for more info on aliases.
215   defp aliases do
216     [
217       "ecto.migrate": ["pleroma.ecto.migrate"],
218       "ecto.rollback": ["pleroma.ecto.rollback"],
219       "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
220       "ecto.reset": ["ecto.drop", "ecto.setup"],
221       test: ["ecto.create --quiet", "ecto.migrate", "test"],
222       docs: ["pleroma.docs", "docs"],
223       analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"],
224       copyright: &add_copyright/1,
225       "copyright.bump": &bump_copyright/1
226     ]
227   end
228
229   # Builds a version string made of:
230   # * the application version
231   # * a pre-release if ahead of the tag: the describe string (-count-commithash)
232   # * branch name
233   # * build metadata:
234   #   * a build name if `PLEROMA_BUILD_NAME` or `:pleroma, :build_name` is defined
235   #   * the mix environment if different than prod
236   defp version(version) do
237     identifier_filter = ~r/[^0-9a-z\-]+/i
238
239     git_available? = match?({_output, 0}, System.cmd("sh", ["-c", "command -v git"]))
240     dotgit_present? = File.exists?(".git")
241
242     git_pre_release =
243       if git_available? and dotgit_present? do
244         {tag, tag_err} =
245           System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
246
247         {describe, describe_err} = System.cmd("git", ["describe", "--tags", "--abbrev=8"])
248         {commit_hash, commit_hash_err} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
249
250         # Pre-release version, denoted from patch version with a hyphen
251         cond do
252           tag_err == 0 and describe_err == 0 ->
253             describe
254             |> String.trim()
255             |> String.replace(String.trim(tag), "")
256             |> String.trim_leading("-")
257             |> String.trim()
258
259           commit_hash_err == 0 ->
260             "0-g" <> String.trim(commit_hash)
261
262           true ->
263             nil
264         end
265       end
266
267     # Branch name as pre-release version component, denoted with a dot
268     branch_name =
269       with true <- git_available?,
270            true <- dotgit_present?,
271            {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
272            branch_name <- String.trim(branch_name),
273            branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
274            true <-
275              !Enum.any?(["master", "HEAD", "release/", "stable"], fn name ->
276                String.starts_with?(name, branch_name)
277              end) do
278         branch_name =
279           branch_name
280           |> String.trim()
281           |> String.replace(identifier_filter, "-")
282
283         branch_name
284       else
285         _ -> ""
286       end
287
288     build_name =
289       cond do
290         name = Application.get_env(:pleroma, :build_name) -> name
291         name = System.get_env("PLEROMA_BUILD_NAME") -> name
292         true -> nil
293       end
294
295     env_name = if Mix.env() != :prod, do: to_string(Mix.env())
296     env_override = System.get_env("PLEROMA_BUILD_ENV")
297
298     env_name =
299       case env_override do
300         nil -> env_name
301         env_override when env_override in ["", "prod"] -> nil
302         env_override -> env_override
303       end
304
305     # Pre-release version, denoted by appending a hyphen
306     # and a series of dot separated identifiers
307     pre_release =
308       [git_pre_release, branch_name]
309       |> Enum.filter(fn string -> string && string != "" end)
310       |> Enum.join(".")
311       |> (fn
312             "" -> nil
313             string -> "-" <> String.replace(string, identifier_filter, "-")
314           end).()
315
316     # Build metadata, denoted with a plus sign
317     build_metadata =
318       [build_name, env_name]
319       |> Enum.filter(fn string -> string && string != "" end)
320       |> Enum.join(".")
321       |> (fn
322             "" -> nil
323             string -> "+" <> String.replace(string, identifier_filter, "-")
324           end).()
325
326     [version, pre_release, build_metadata]
327     |> Enum.filter(fn string -> string && string != "" end)
328     |> Enum.join()
329   end
330
331   defp add_copyright(_) do
332     year = NaiveDateTime.utc_now().year
333     template = ~s[\
334 # Pleroma: A lightweight social networking server
335 # Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>
336 # SPDX-License-Identifier: AGPL-3.0-only
337
338 ] |> String.replace("\n", "\\n")
339
340     find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec "
341     grep = "grep -L '# Copyright © [0-9\-]* Pleroma' {} \\;"
342     xargs = "xargs -n1 sed -i'' '1s;^;#{template};'"
343
344     :os.cmd(String.to_charlist("#{find}#{grep} | #{xargs}"))
345   end
346
347   defp bump_copyright(_) do
348     year = NaiveDateTime.utc_now().year
349     find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\)"
350
351     xargs =
352       "xargs sed -i'' 's;# Copyright © [0-9\-]* Pleroma.*$;# Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>;'"
353
354     :os.cmd(String.to_charlist("#{find} | #{xargs}"))
355   end
356 end