mix.exs 12.1 KB
Newer Older
lain's avatar
lain committed
1
2
3
4
defmodule Pleroma.Mixfile do
  use Mix.Project

  def project do
lain's avatar
lain committed
5
6
    [
      app: :pleroma,
7
      version: version("2.2.50"),
Steven Fuchs's avatar
Steven Fuchs committed
8
      elixir: "~> 1.9",
lain's avatar
lain committed
9
10
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
11
      elixirc_options: [warnings_as_errors: warnings_as_errors(Mix.env())],
12
      xref: [exclude: [:eldap]],
lain's avatar
lain committed
13
14
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
Haelwenn's avatar
Haelwenn committed
15
      deps: deps(),
feld's avatar
feld committed
16
      test_coverage: [tool: ExCoveralls],
Maksim's avatar
Maksim committed
17
      preferred_cli_env: ["coveralls.html": :test],
Haelwenn's avatar
Haelwenn committed
18
19
20
      # Docs
      name: "Pleroma",
      homepage_url: "https://pleroma.social/",
xse's avatar
xse committed
21
      source_url: "https://git.pleroma.social/pleroma/pleroma",
Haelwenn's avatar
Haelwenn committed
22
      docs: [
xse's avatar
xse committed
23
24
        source_url_pattern:
          "https://git.pleroma.social/pleroma/pleroma/blob/develop/%{path}#L%{line}",
25
        logo: "priv/static/images/logo.png",
rinpatch's avatar
rinpatch committed
26
        extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"),
rinpatch's avatar
rinpatch committed
27
28
29
30
31
        groups_for_extras: [
          "Installation manuals": Path.wildcard("docs/installation/*.md"),
          Configuration: Path.wildcard("docs/config/*.md"),
          Administration: Path.wildcard("docs/admin/*.md"),
          "Pleroma's APIs and Mastodon API extensions": Path.wildcard("docs/api/*.md")
rinpatch's avatar
rinpatch committed
32
        ],
33
34
        main: "readme",
        output: "priv/static/doc"
rinpatch's avatar
rinpatch committed
35
36
37
38
      ],
      releases: [
        pleroma: [
          include_executables_for: [:unix],
39
          applications: [ex_syslogger: :load, syslog: :load, eldap: :transient],
Alexander Strizhakov's avatar
Alexander Strizhakov committed
40
41
          steps: [:assemble, &put_otp_version/1, &copy_files/1, &copy_nginx_config/1],
          config_providers: [{Pleroma.Config.ReleaseRuntimeProvider, nil}]
rinpatch's avatar
rinpatch committed
42
        ]
Haelwenn's avatar
Haelwenn committed
43
      ]
lain's avatar
lain committed
44
    ]
lain's avatar
lain committed
45
46
  end

kPherox's avatar
kPherox committed
47
  def put_otp_version(%{path: target_path} = release) do
48
49
50
51
52
53
54
55
    File.write!(
      Path.join([target_path, "OTP_VERSION"]),
      Pleroma.OTPVersion.version()
    )

    release
  end

56
57
  def copy_files(%{path: target_path} = release) do
    File.cp_r!("./rel/files", target_path)
rinpatch's avatar
rinpatch committed
58
59
60
    release
  end

61
  def copy_nginx_config(%{path: target_path} = release) do
rinpatch's avatar
rinpatch committed
62
63
64
65
66
    File.cp!(
      "./installation/pleroma.nginx",
      Path.join([target_path, "installation", "pleroma.nginx"])
    )

67
68
69
    release
  end

lain's avatar
lain committed
70
71
72
73
  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
Haelwenn's avatar
Haelwenn committed
74
75
    [
      mod: {Pleroma.Application, []},
rinpatch's avatar
rinpatch committed
76
77
78
79
80
81
      extra_applications: [
        :logger,
        :runtime_tools,
        :comeonin,
        :quack,
        :fast_sanitize,
82
        :ssl
rinpatch's avatar
rinpatch committed
83
      ],
Haelwenn's avatar
Haelwenn committed
84
85
      included_applications: [:ex_syslogger]
    ]
lain's avatar
lain committed
86
87
88
  end

  # Specifies which paths to compile per environment.
Alexander Strizhakov's avatar
Alexander Strizhakov committed
89
  defp elixirc_paths(:benchmark), do: ["lib", "benchmarks"]
lain's avatar
lain committed
90
  defp elixirc_paths(:test), do: ["lib", "test/support"]
lain's avatar
lain committed
91
  defp elixirc_paths(_), do: ["lib"]
lain's avatar
lain committed
92

93
94
95
  defp warnings_as_errors(:prod), do: false
  defp warnings_as_errors(_), do: true

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  # Specifies OAuth dependencies.
  defp oauth_deps do
    oauth_strategy_packages =
      System.get_env("OAUTH_CONSUMER_STRATEGIES")
      |> to_string()
      |> String.split()
      |> Enum.map(fn strategy_entry ->
        with [_strategy, dependency] <- String.split(strategy_entry, ":") do
          dependency
        else
          [strategy] -> "ueberauth_#{strategy}"
        end
      end)

    for s <- oauth_strategy_packages, do: {String.to_atom(s), ">= 0.0.0"}
  end

lain's avatar
lain committed
113
114
115
116
  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
lain's avatar
lain committed
117
    [
118
      {:phoenix, "~> 1.5.5"},
119
      {:tzdata, "~> 1.0.3"},
Maksim's avatar
Maksim committed
120
      {:plug_cowboy, "~> 2.3"},
121
      {:phoenix_pubsub, "~> 2.0"},
rinpatch's avatar
rinpatch committed
122
      {:phoenix_ecto, "~> 4.0"},
123
      {:ecto_enum, "~> 1.4"},
Maksim's avatar
Maksim committed
124
      {:ecto_sql, "~> 3.4.4"},
Maksim's avatar
Maksim committed
125
      {:postgrex, ">= 0.15.5"},
feld's avatar
feld committed
126
      {:oban, "~> 2.3.4"},
Maksim's avatar
Maksim committed
127
128
      {:gettext, "~> 0.18"},
      {:bcrypt_elixir, "~> 2.2"},
ArtikBanana's avatar
ArtikBanana committed
129
      {:trailing_format_plug, "~> 0.0.7"},
130
      {:fast_sanitize, "~> 0.2.0"},
rinpatch's avatar
rinpatch committed
131
      {:html_entities, "~> 0.5", override: true},
Maksim's avatar
Maksim committed
132
      {:phoenix_html, "~> 2.14"},
Maksim's avatar
Maksim committed
133
      {:calendar, "~> 1.0"},
rinpatch's avatar
rinpatch committed
134
      {:cachex, "~> 3.2"},
Ivan Tashkinov's avatar
Ivan Tashkinov committed
135
      {:poison, "~> 3.0", override: true},
Haelwenn's avatar
Haelwenn committed
136
      {:tesla, "~> 1.4.0", override: true},
Alexander Strizhakov's avatar
Alexander Strizhakov committed
137
      {:castore, "~> 0.1"},
Maksim's avatar
Maksim committed
138
      {:cowlib, "~> 2.9", override: true},
Alexander Strizhakov's avatar
Alexander Strizhakov committed
139
      {:gun,
href's avatar
href committed
140
       github: "ninenines/gun", ref: "921c47146b2d9567eac7e9a4d2ccc60fffd4f327", override: true},
Maksim's avatar
Maksim committed
141
      {:jason, "~> 1.2"},
Maksim's avatar
Maksim committed
142
      {:mogrify, "~> 0.7.4"},
feld's avatar
feld committed
143
      {:ex_aws, "~> 2.1.6"},
144
      {:ex_aws_s3, "~> 2.0"},
145
      {:sweet_xml, "~> 0.6.6"},
Maksim's avatar
Maksim committed
146
      {:earmark, "1.4.3"},
147
      {:bbcode_pleroma, "~> 0.2.0"},
148
      {:crypt,
149
150
       git: "https://git.pleroma.social/pleroma/elixir-libraries/crypt.git",
       ref: "cf2aa3f11632e8b0634810a15b3e612c7526f6a3"},
Maksim's avatar
Maksim committed
151
      {:cors_plug, "~> 2.0"},
Maksim's avatar
Maksim committed
152
      {:web_push_encryption, "~> 0.3"},
Maksim's avatar
Maksim committed
153
154
      {:swoosh, "~> 1.0"},
      {:phoenix_swoosh, "~> 0.3"},
155
      {:gen_smtp, "~> 0.13"},
156
      {:ex_syslogger, "~> 1.4"},
Maksim's avatar
Maksim committed
157
158
      {:floki, "~> 0.27"},
      {:timex, "~> 3.6"},
Ivan Tashkinov's avatar
Ivan Tashkinov committed
159
      {:ueberauth, "~> 0.4"},
feld's avatar
feld committed
160
      {:linkify, "~> 0.4.1"},
Maksim's avatar
Maksim committed
161
      {:http_signatures, "~> 0.1.0"},
href's avatar
href committed
162
      {:telemetry, "~> 0.3"},
163
      {:poolboy, "~> 1.5"},
164
      {:prometheus, "~> 4.6"},
feld's avatar
feld committed
165
166
167
168
      {:prometheus_ex,
       git: "https://git.pleroma.social/pleroma/elixir-libraries/prometheus.ex.git",
       ref: "a4e9beb3c1c479d14b352fd9d6dd7b1f6d7deee5",
       override: true},
href's avatar
href committed
169
      {:prometheus_plugs, "~> 1.1"},
170
      {:prometheus_phoenix, "~> 1.3"},
171
      # Note: once `prometheus_phx` is integrated into `prometheus_phoenix`, remove the former:
172
173
174
      {:prometheus_phx,
       git: "https://git.pleroma.social/pleroma/elixir-libraries/prometheus-phx.git",
       branch: "no-logging"},
href's avatar
href committed
175
      {:prometheus_ecto, "~> 1.4"},
176
      {:recon, "~> 2.5"},
lain's avatar
lain committed
177
      {:quack, "~> 0.1.1"},
Roman Chvanikov's avatar
Roman Chvanikov committed
178
      {:joken, "~> 2.0"},
179
      {:benchee, "~> 1.0"},
Maksim's avatar
Maksim committed
180
      {:pot, "~> 0.11"},
181
      {:esshd, "~> 0.1.0", runtime: Application.get_env(:esshd, :enabled, false)},
kaniini's avatar
kaniini committed
182
      {:ex_const, "~> 0.2"},
feld's avatar
feld committed
183
      {:plug_static_index_html, "~> 1.0.0"},
184
      {:flake_id, "~> 0.1.0"},
rinpatch's avatar
rinpatch committed
185
      {:concurrent_limiter,
186
       git: "https://git.pleroma.social/pleroma/elixir-libraries/concurrent_limiter.git",
rinpatch's avatar
rinpatch committed
187
       ref: "d81be41024569330f296fc472e24198d7499ba78"},
minibikini's avatar
minibikini committed
188
189
      {:remote_ip,
       git: "https://git.pleroma.social/pleroma/remote_ip.git",
190
       ref: "b647d0deecaa3acb140854fe4bda5b7e1dc6d1c8"},
191
192
      {:captcha,
       git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
minibikini's avatar
minibikini committed
193
       ref: "e0f16822d578866e186a0974d65ad58cddc1e2ab"},
minibikini's avatar
minibikini committed
194
      {:restarter, path: "./restarter"},
195
      {:majic,
196
197
       git: "https://git.pleroma.social/pleroma/elixir-libraries/majic.git",
       ref: "4c692e544b28d1f5e543fb8a44be090f8cd96f80"},
198
199
      {:open_api_spex,
       git: "https://git.pleroma.social/pleroma/elixir-libraries/open_api_spex.git",
Maksim's avatar
Maksim committed
200
201
202
203
204
205
206
       ref: "f296ac0924ba3cf79c7a588c4c252889df4c2edd"},

      ## dev & test
      {:ex_doc, "~> 0.22", only: :dev, runtime: false},
      {:ex_machina, "~> 2.4", only: :test},
      {:credo, "~> 1.4", only: [:dev, :test], runtime: false},
      {:mock, "~> 0.3.5", only: :test},
207
      # temporary downgrade for excoveralls, hackney until hackney max_connections bug will be fixed
Alexander Strizhakov's avatar
Alexander Strizhakov committed
208
      {:excoveralls, "0.12.3", only: :test},
209
210
211
212
      {:hackney,
       git: "https://git.pleroma.social/pleroma/elixir-libraries/hackney.git",
       ref: "7d7119f0651515d6d7669c78393fd90950a3ec6e",
       override: true},
213
      {:mox, "~> 1.0", only: :test},
Maksim's avatar
Maksim committed
214
      {:websocket_client, git: "https://github.com/jeremyong/websocket_client.git", only: :test}
215
    ] ++ oauth_deps()
lain's avatar
lain committed
216
217
218
219
220
221
222
223
224
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to create, migrate and run the seeds file at once:
  #
  #     $ mix ecto.setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
lain's avatar
lain committed
225
    [
Alexander Strizhakov's avatar
Alexander Strizhakov committed
226
227
      "ecto.migrate": ["pleroma.ecto.migrate"],
      "ecto.rollback": ["pleroma.ecto.rollback"],
lain's avatar
lain committed
228
229
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
230
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
231
      docs: ["pleroma.docs", "docs"],
232
      analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"],
feld's avatar
feld committed
233
234
      copyright: &add_copyright/1,
      "copyright.bump": &bump_copyright/1
lain's avatar
lain committed
235
    ]
lain's avatar
lain committed
236
  end
href's avatar
href committed
237
238
239
240

  # Builds a version string made of:
  # * the application version
  # * a pre-release if ahead of the tag: the describe string (-count-commithash)
241
242
  # * branch name
  # * build metadata:
href's avatar
href committed
243
244
245
  #   * a build name if `PLEROMA_BUILD_NAME` or `:pleroma, :build_name` is defined
  #   * the mix environment if different than prod
  defp version(version) do
246
247
    identifier_filter = ~r/[^0-9a-z\-]+/i

248
    git_available? = match?({_output, 0}, System.cmd("sh", ["-c", "command -v git"]))
249

minibikini's avatar
minibikini committed
250
    git_pre_release =
251
      if git_available? do
Haelwenn's avatar
Haelwenn committed
252
253
        {tag, tag_err} =
          System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
254

Haelwenn's avatar
Haelwenn committed
255
256
        {describe, describe_err} = System.cmd("git", ["describe", "--tags", "--abbrev=8"])
        {commit_hash, commit_hash_err} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
257

Haelwenn's avatar
Haelwenn committed
258
259
260
261
262
263
264
265
266
267
268
269
270
        # Pre-release version, denoted from patch version with a hyphen
        cond do
          tag_err == 0 and describe_err == 0 ->
            describe
            |> String.trim()
            |> String.replace(String.trim(tag), "")
            |> String.trim_leading("-")
            |> String.trim()

          commit_hash_err == 0 ->
            "0-g" <> String.trim(commit_hash)

          true ->
271
            nil
Haelwenn's avatar
Haelwenn committed
272
        end
href's avatar
href committed
273
274
      end

275
276
    # Branch name as pre-release version component, denoted with a dot
    branch_name =
277
      with true <- git_available?,
Haelwenn's avatar
Haelwenn committed
278
           {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
279
           branch_name <- String.trim(branch_name),
280
           branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
281
           true <-
rinpatch's avatar
rinpatch committed
282
             !Enum.any?(["master", "HEAD", "release/", "stable"], fn name ->
283
               String.starts_with?(name, branch_name)
284
             end) do
285
286
287
288
289
        branch_name =
          branch_name
          |> String.trim()
          |> String.replace(identifier_filter, "-")

290
        branch_name
291
      else
292
        _ -> ""
293
294
      end

href's avatar
href committed
295
296
297
298
299
300
301
302
    build_name =
      cond do
        name = Application.get_env(:pleroma, :build_name) -> name
        name = System.get_env("PLEROMA_BUILD_NAME") -> name
        true -> nil
      end

    env_name = if Mix.env() != :prod, do: to_string(Mix.env())
303
304
305
    env_override = System.get_env("PLEROMA_BUILD_ENV")

    env_name =
306
307
308
309
      case env_override do
        nil -> env_name
        env_override when env_override in ["", "prod"] -> nil
        env_override -> env_override
310
311
      end

312
313
314
315
316
317
318
319
320
321
322
    # Pre-release version, denoted by appending a hyphen
    # and a series of dot separated identifiers
    pre_release =
      [git_pre_release, branch_name]
      |> Enum.filter(fn string -> string && string != "" end)
      |> Enum.join(".")
      |> (fn
            "" -> nil
            string -> "-" <> String.replace(string, identifier_filter, "-")
          end).()

323
324
    # Build metadata, denoted with a plus sign
    build_metadata =
href's avatar
href committed
325
326
      [build_name, env_name]
      |> Enum.filter(fn string -> string && string != "" end)
327
      |> Enum.join(".")
href's avatar
href committed
328
329
      |> (fn
            "" -> nil
330
            string -> "+" <> String.replace(string, identifier_filter, "-")
href's avatar
href committed
331
332
          end).()

333
    [version, pre_release, build_metadata]
href's avatar
href committed
334
335
336
    |> Enum.filter(fn string -> string && string != "" end)
    |> Enum.join()
  end
337
338

  defp add_copyright(_) do
feld's avatar
feld committed
339
    year = NaiveDateTime.utc_now().year
340
341
342
343
    template = ~s[\
# Pleroma: A lightweight social networking server
# Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
344

345
] |> String.replace("\n", "\\n")
346
347

    find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec "
348
    grep = "grep -L '# Copyright © [0-9\-]* Pleroma' {} \\;"
349
    xargs = "xargs -n1 sed -i'' '1s;^;#{template};'"
350

351
    :os.cmd(String.to_charlist("#{find}#{grep} | #{xargs}"))
352
  end
feld's avatar
feld committed
353
354
355

  defp bump_copyright(_) do
    year = NaiveDateTime.utc_now().year
356
    find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\)"
feld's avatar
feld committed
357

358
359
    xargs =
      "xargs sed -i'' 's;# Copyright © [0-9\-]* Pleroma.*$;# Copyright © 2017-#{year} Pleroma Authors <https://pleroma.social/>;'"
feld's avatar
feld committed
360

361
    :os.cmd(String.to_charlist("#{find} | #{xargs}"))
feld's avatar
feld committed
362
  end
lain's avatar
lain committed
363
end