Local copy of Pleroma, an ActivityPub server software. Contains modifications running live on fedi.underscore.world
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.

326 lines
11KB

  1. defmodule Pleroma.Mixfile do
  2. use Mix.Project
  3. def project do
  4. [
  5. app: :pleroma,
  6. version: version("2.1.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.underscore.world/d/pleroma",
  21. docs: [
  22. source_url_pattern:
  23. "https://git.pleroma.social/pleroma/pleroma/blob/develop/%{path}#L%{line}",
  24. logo: "priv/static/static/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. ]
  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. :quack,
  73. :fast_sanitize,
  74. :ssl
  75. ],
  76. included_applications: [:ex_syslogger]
  77. ]
  78. end
  79. # Specifies which paths to compile per environment.
  80. defp elixirc_paths(:benchmark), do: ["lib", "benchmarks"]
  81. defp elixirc_paths(:test), do: ["lib", "test/support"]
  82. defp elixirc_paths(_), do: ["lib"]
  83. defp warnings_as_errors(:prod), do: false
  84. defp warnings_as_errors(_), do: 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.4.17"},
  106. {:tzdata, "~> 1.0.3"},
  107. {:plug_cowboy, "~> 2.3"},
  108. {:phoenix_pubsub, "~> 1.1"},
  109. {:phoenix_ecto, "~> 4.0"},
  110. {:ecto_enum, "~> 1.4"},
  111. {:ecto_sql, "~> 3.4.4"},
  112. {:postgrex, ">= 0.15.5"},
  113. {:oban, "~> 2.0.0"},
  114. {:gettext, "~> 0.18"},
  115. {:pbkdf2_elixir, "~> 1.2"},
  116. {:bcrypt_elixir, "~> 2.2"},
  117. {:trailing_format_plug, "~> 0.0.7"},
  118. {:fast_sanitize, "~> 0.2.0"},
  119. {:html_entities, "~> 0.5", override: true},
  120. {:phoenix_html, "~> 2.14"},
  121. {:calendar, "~> 1.0"},
  122. {:cachex, "~> 3.2"},
  123. {:poison, "~> 3.0", override: true},
  124. {:tesla,
  125. git: "https://github.com/teamon/tesla/",
  126. ref: "9f7261ca49f9f901ceb73b60219ad6f8a9f6aa30",
  127. override: true},
  128. {:castore, "~> 0.1"},
  129. {:cowlib, "~> 2.9", override: true},
  130. {:gun,
  131. github: "ninenines/gun", ref: "921c47146b2d9567eac7e9a4d2ccc60fffd4f327", override: true},
  132. {:jason, "~> 1.2"},
  133. {:mogrify, "~> 0.7.4"},
  134. {:ex_aws, "~> 2.1"},
  135. {:ex_aws_s3, "~> 2.0"},
  136. {:sweet_xml, "~> 0.6.6"},
  137. {:earmark, "1.4.3"},
  138. {:bbcode_pleroma, "~> 0.2.0"},
  139. {:crypt,
  140. git: "https://github.com/msantos/crypt.git",
  141. ref: "f63a705f92c26955977ee62a313012e309a4d77a"},
  142. {:cors_plug, "~> 2.0"},
  143. {:web_push_encryption, "~> 0.3"},
  144. {:swoosh, "~> 1.0"},
  145. {:phoenix_swoosh, "~> 0.3"},
  146. {:gen_smtp, "~> 0.13"},
  147. {:ex_syslogger, "~> 1.4"},
  148. {:floki, "~> 0.27"},
  149. {:timex, "~> 3.6"},
  150. {:ueberauth, "~> 0.4"},
  151. {:linkify, "~> 0.2.0"},
  152. {:http_signatures, "~> 0.1.0"},
  153. {:telemetry, "~> 0.3"},
  154. {:poolboy, "~> 1.5"},
  155. {:prometheus, "~> 4.6"},
  156. {:prometheus_ex, "~> 3.0"},
  157. {:prometheus_plugs, "~> 1.1"},
  158. {:prometheus_phoenix, "~> 1.3"},
  159. {:prometheus_ecto, "~> 1.4"},
  160. {:recon, "~> 2.5"},
  161. {:quack, "~> 0.1.1"},
  162. {:joken, "~> 2.0"},
  163. {:benchee, "~> 1.0"},
  164. {:pot, "~> 0.11"},
  165. {:esshd, "~> 0.1.0", runtime: Application.get_env(:esshd, :enabled, false)},
  166. {:ex_const, "~> 0.2"},
  167. {:plug_static_index_html, "~> 1.0.0"},
  168. {:flake_id, "~> 0.1.0"},
  169. {:concurrent_limiter,
  170. git: "https://git.pleroma.social/pleroma/elixir-libraries/concurrent_limiter.git",
  171. ref: "55e92f84b4ed531bd487952a71040a9c69dc2807"},
  172. {:remote_ip,
  173. git: "https://git.pleroma.social/pleroma/remote_ip.git",
  174. ref: "b647d0deecaa3acb140854fe4bda5b7e1dc6d1c8"},
  175. {:captcha,
  176. git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
  177. ref: "e0f16822d578866e186a0974d65ad58cddc1e2ab"},
  178. {:restarter, path: "./restarter"},
  179. {:open_api_spex,
  180. git: "https://git.pleroma.social/pleroma/elixir-libraries/open_api_spex.git",
  181. ref: "f296ac0924ba3cf79c7a588c4c252889df4c2edd"},
  182. ## dev & test
  183. {:ex_doc, "~> 0.22", only: :dev, runtime: false},
  184. {:ex_machina, "~> 2.4", only: :test},
  185. {:credo, "~> 1.4", only: [:dev, :test], runtime: false},
  186. {:mock, "~> 0.3.5", only: :test},
  187. # temporary downgrade for excoveralls, hackney until hackney max_connections bug will be fixed
  188. {:excoveralls, "0.12.3", only: :test},
  189. {:hackney, "1.15.2", override: true},
  190. {:mox, "~> 0.5", only: :test},
  191. {:websocket_client, git: "https://github.com/jeremyong/websocket_client.git", only: :test}
  192. ] ++ oauth_deps()
  193. end
  194. # Aliases are shortcuts or tasks specific to the current project.
  195. # For example, to create, migrate and run the seeds file at once:
  196. #
  197. # $ mix ecto.setup
  198. #
  199. # See the documentation for `Mix` for more info on aliases.
  200. defp aliases do
  201. [
  202. "ecto.migrate": ["pleroma.ecto.migrate"],
  203. "ecto.rollback": ["pleroma.ecto.rollback"],
  204. "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
  205. "ecto.reset": ["ecto.drop", "ecto.setup"],
  206. test: ["ecto.create --quiet", "ecto.migrate", "test"],
  207. docs: ["pleroma.docs", "docs"],
  208. analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"]
  209. ]
  210. end
  211. # Builds a version string made of:
  212. # * the application version
  213. # * a pre-release if ahead of the tag: the describe string (-count-commithash)
  214. # * branch name
  215. # * build metadata:
  216. # * a build name if `PLEROMA_BUILD_NAME` or `:pleroma, :build_name` is defined
  217. # * the mix environment if different than prod
  218. defp version(version) do
  219. identifier_filter = ~r/[^0-9a-z\-]+/i
  220. git_available? = match?({_output, 0}, System.cmd("sh", ["-c", "command -v git"]))
  221. git_pre_release =
  222. if git_available? do
  223. {tag, tag_err} =
  224. System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
  225. {describe, describe_err} = System.cmd("git", ["describe", "--tags", "--abbrev=8"])
  226. {commit_hash, commit_hash_err} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
  227. # Pre-release version, denoted from patch version with a hyphen
  228. cond do
  229. tag_err == 0 and describe_err == 0 ->
  230. describe
  231. |> String.trim()
  232. |> String.replace(String.trim(tag), "")
  233. |> String.trim_leading("-")
  234. |> String.trim()
  235. commit_hash_err == 0 ->
  236. "0-g" <> String.trim(commit_hash)
  237. true ->
  238. nil
  239. end
  240. end
  241. # Branch name as pre-release version component, denoted with a dot
  242. branch_name =
  243. with true <- git_available?,
  244. {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
  245. branch_name <- String.trim(branch_name),
  246. branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
  247. true <-
  248. !Enum.any?(["master", "HEAD", "release/", "stable"], fn name ->
  249. String.starts_with?(name, branch_name)
  250. end) do
  251. branch_name =
  252. branch_name
  253. |> String.trim()
  254. |> String.replace(identifier_filter, "-")
  255. branch_name
  256. else
  257. _ -> ""
  258. end
  259. build_name =
  260. cond do
  261. name = Application.get_env(:pleroma, :build_name) -> name
  262. name = System.get_env("PLEROMA_BUILD_NAME") -> name
  263. true -> nil
  264. end
  265. env_name = if Mix.env() != :prod, do: to_string(Mix.env())
  266. env_override = System.get_env("PLEROMA_BUILD_ENV")
  267. env_name =
  268. case env_override do
  269. nil -> env_name
  270. env_override when env_override in ["", "prod"] -> nil
  271. env_override -> env_override
  272. end
  273. # Pre-release version, denoted by appending a hyphen
  274. # and a series of dot separated identifiers
  275. pre_release =
  276. [git_pre_release, branch_name]
  277. |> Enum.filter(fn string -> string && string != "" end)
  278. |> Enum.join(".")
  279. |> (fn
  280. "" -> nil
  281. string -> "-" <> String.replace(string, identifier_filter, "-")
  282. end).()
  283. # Build metadata, denoted with a plus sign
  284. build_metadata =
  285. [build_name, env_name]
  286. |> Enum.filter(fn string -> string && string != "" end)
  287. |> Enum.join(".")
  288. |> (fn
  289. "" -> nil
  290. string -> "+" <> String.replace(string, identifier_filter, "-")
  291. end).()
  292. [version, pre_release, build_metadata]
  293. |> Enum.filter(fn string -> string && string != "" end)
  294. |> Enum.join()
  295. end
  296. end