mix.exs 12 KB

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