Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
12KB

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