mix.exs 9.67 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("1.1.50"),
Maxim Filippov's avatar
Maxim Filippov committed
8
      elixir: "~> 1.8",
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}",
Haelwenn's avatar
Haelwenn committed
25
        logo: "priv/static/static/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
39
      ],
      releases: [
        pleroma: [
          include_executables_for: [:unix],
          applications: [ex_syslogger: :load, syslog: :load],
40
          steps: [:assemble, &copy_files/1, &copy_nginx_config/1]
rinpatch's avatar
rinpatch committed
41
        ]
Haelwenn's avatar
Haelwenn committed
42
      ]
lain's avatar
lain committed
43
    ]
lain's avatar
lain committed
44
45
  end

46
47
  def copy_files(%{path: target_path} = release) do
    File.cp_r!("./rel/files", target_path)
rinpatch's avatar
rinpatch committed
48
49
50
    release
  end

51
  def copy_nginx_config(%{path: target_path} = release) do
rinpatch's avatar
rinpatch committed
52
53
54
55
56
    File.cp!(
      "./installation/pleroma.nginx",
      Path.join([target_path, "installation", "pleroma.nginx"])
    )

57
58
59
    release
  end

lain's avatar
lain committed
60
61
62
63
  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
Haelwenn's avatar
Haelwenn committed
64
65
    [
      mod: {Pleroma.Application, []},
Maksim's avatar
Maksim committed
66
      extra_applications: [:logger, :runtime_tools, :comeonin, :quack, :fast_sanitize],
Haelwenn's avatar
Haelwenn committed
67
68
      included_applications: [:ex_syslogger]
    ]
lain's avatar
lain committed
69
70
71
  end

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

76
77
78
79
80
  defp warnings_as_errors(:prod), do: false
  # Uncomment this if you need testing configurable_from_database logic
  # defp warnings_as_errors(:dev), do: false
  defp warnings_as_errors(_), do: true

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  # 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
98
99
100
101
  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
lain's avatar
lain committed
102
    [
feld's avatar
feld committed
103
      {:phoenix, "~> 1.4.8"},
104
      {:tzdata, "~> 0.5.21"},
105
      {:plug_cowboy, "~> 2.0"},
href's avatar
href committed
106
      {:phoenix_pubsub, "~> 1.1"},
rinpatch's avatar
rinpatch committed
107
      {:phoenix_ecto, "~> 4.0"},
108
      {:ecto_enum, "~> 1.4"},
Maksim's avatar
Maksim committed
109
      {:ecto_sql, "~> 3.3.2"},
ArtikBanana's avatar
ArtikBanana committed
110
      {:postgrex, ">= 0.13.5"},
111
      {:oban, "~> 0.12.1"},
ArtikBanana's avatar
ArtikBanana committed
112
113
114
115
      {:gettext, "~> 0.15"},
      {:comeonin, "~> 4.1.1"},
      {:pbkdf2_elixir, "~> 0.12.3"},
      {:trailing_format_plug, "~> 0.0.7"},
rinpatch's avatar
rinpatch committed
116
      {:fast_sanitize, "~> 0.1"},
rinpatch's avatar
rinpatch committed
117
      {:html_entities, "~> 0.5", override: true},
lain's avatar
lain committed
118
      {:phoenix_html, "~> 2.10"},
ArtikBanana's avatar
ArtikBanana committed
119
      {:calendar, "~> 0.17.4"},
rinpatch's avatar
rinpatch committed
120
      {:cachex, "~> 3.2"},
Ivan Tashkinov's avatar
Ivan Tashkinov committed
121
      {:poison, "~> 3.0", override: true},
122
123
124
125
126
      # {:tesla, "~> 1.3", override: true},
      {:tesla,
       github: "alex-strizhakov/tesla",
       ref: "922cc3db13b421763edbea76246b8ea61c38c6fa",
       override: true},
Alexander Strizhakov's avatar
Alexander Strizhakov committed
127
128
129
130
      {:castore, "~> 0.1"},
      {:cowlib, "~> 2.8", override: true},
      {:gun,
       github: "ninenines/gun", ref: "bd6425ab87428cf4c95f4d23e0a48fd065fbd714", override: true},
lain's avatar
lain committed
131
      {:jason, "~> 1.0"},
kaniini's avatar
kaniini committed
132
      {:mogrify, "~> 0.6.1"},
133
      {:ex_aws, "~> 2.1"},
134
      {:ex_aws_s3, "~> 2.0"},
135
      {:sweet_xml, "~> 0.6.6"},
Maksim's avatar
Maksim committed
136
      {:earmark, "~> 1.3"},
137
      {:bbcode, "~> 0.1.1"},
138
      {:ex_machina, "~> 2.3", only: :test},
Haelwenn's avatar
Haelwenn committed
139
      {:credo, "~> 1.1.0", only: [:dev, :test], runtime: false},
140
      {:mock, "~> 0.3.3", only: :test},
141
      {:crypt,
minibikini's avatar
minibikini committed
142
       git: "https://github.com/msantos/crypt", ref: "1f2b58927ab57e72910191a7ebaeff984382a1d3"},
Haelwenn's avatar
Haelwenn committed
143
      {:cors_plug, "~> 1.5"},
Alexander Strizhakov's avatar
Alexander Strizhakov committed
144
      {:ex_doc, "~> 0.21", only: :dev, runtime: false},
Ivan Tashkinov's avatar
Ivan Tashkinov committed
145
      {:web_push_encryption, "~> 0.2.1"},
146
      {:swoosh, "~> 0.23.2"},
Roman Chvanikov's avatar
Roman Chvanikov committed
147
      {:phoenix_swoosh, "~> 0.2"},
148
      {:gen_smtp, "~> 0.13"},
Maxim Filippov's avatar
Maxim Filippov committed
149
      {:websocket_client, git: "https://github.com/jeremyong/websocket_client.git", only: :test},
150
      {:ex_syslogger, "~> 1.4"},
151
      {:floki, "~> 0.25"},
minibikini's avatar
minibikini committed
152
      {:timex, "~> 3.5"},
Ivan Tashkinov's avatar
Ivan Tashkinov committed
153
      {:ueberauth, "~> 0.4"},
minibikini's avatar
minibikini committed
154
155
      {:auto_linker,
       git: "https://git.pleroma.social/pleroma/auto_linker.git",
rinpatch's avatar
rinpatch committed
156
       ref: "95e8188490e97505c56636c1379ffdf036c1fdde"},
157
158
      {:http_signatures,
       git: "https://git.pleroma.social/pleroma/http_signatures.git",
159
       ref: "293d77bb6f4a67ac8bde1428735c3b42f22cbb30"},
href's avatar
href committed
160
      {:telemetry, "~> 0.3"},
161
      {:poolboy, "~> 1.5"},
href's avatar
href committed
162
163
      {:prometheus_ex, "~> 3.0"},
      {:prometheus_plugs, "~> 1.1"},
164
      {:prometheus_phoenix, "~> 1.3"},
href's avatar
href committed
165
      {:prometheus_ecto, "~> 1.4"},
166
      {:recon, "~> 2.5"},
lain's avatar
lain committed
167
      {:quack, "~> 0.1.1"},
Roman Chvanikov's avatar
Roman Chvanikov committed
168
      {:joken, "~> 2.0"},
169
      {:benchee, "~> 1.0"},
170
      {:esshd, "~> 0.1.0", runtime: Application.get_env(:esshd, :enabled, false)},
kaniini's avatar
kaniini committed
171
      {:ex_const, "~> 0.2"},
feld's avatar
feld committed
172
      {:plug_static_index_html, "~> 1.0.0"},
Maksim's avatar
Maksim committed
173
      {:excoveralls, "~> 0.12.1", only: :test},
174
      {:flake_id, "~> 0.1.0"},
minibikini's avatar
minibikini committed
175
176
177
      {:remote_ip,
       git: "https://git.pleroma.social/pleroma/remote_ip.git",
       ref: "825dc00aaba5a1b7c4202a532b696b595dd3bcb3"},
178
179
      {:captcha,
       git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git",
minibikini's avatar
minibikini committed
180
       ref: "e0f16822d578866e186a0974d65ad58cddc1e2ab"},
181
      {:mox, "~> 0.5", only: :test},
Alexander Strizhakov's avatar
Alexander Strizhakov committed
182
      {:restarter, path: "./restarter"}
183
    ] ++ oauth_deps()
lain's avatar
lain committed
184
185
186
187
188
189
190
191
192
  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
193
    [
Alexander Strizhakov's avatar
Alexander Strizhakov committed
194
195
      "ecto.migrate": ["pleroma.ecto.migrate"],
      "ecto.rollback": ["pleroma.ecto.rollback"],
lain's avatar
lain committed
196
197
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
198
199
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
      docs: ["pleroma.docs", "docs"]
lain's avatar
lain committed
200
    ]
lain's avatar
lain committed
201
  end
href's avatar
href committed
202
203
204
205

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

    # Pre-release version, denoted from patch version with a hyphen
minibikini's avatar
minibikini committed
214
    git_pre_release =
215
216
      with {tag, 0} <-
             System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true),
minibikini's avatar
minibikini committed
217
218
219
220
221
222
           {describe, 0} <- System.cmd("git", ["describe", "--tags", "--abbrev=8"]) do
        describe
        |> String.trim()
        |> String.replace(String.trim(tag), "")
        |> String.trim_leading("-")
        |> String.trim()
href's avatar
href committed
223
      else
Alexander Strizhakov's avatar
Alexander Strizhakov committed
224
225
        _ ->
          {commit_hash, 0} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
minibikini's avatar
minibikini committed
226
          "0-g" <> String.trim(commit_hash)
href's avatar
href committed
227
228
      end

229
230
231
    # Branch name as pre-release version component, denoted with a dot
    branch_name =
      with {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
232
           branch_name <- String.trim(branch_name),
233
           branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
234
           true <-
rinpatch's avatar
rinpatch committed
235
             !Enum.any?(["master", "HEAD", "release/", "stable"], fn name ->
236
               String.starts_with?(name, branch_name)
237
             end) do
238
239
240
241
242
        branch_name =
          branch_name
          |> String.trim()
          |> String.replace(identifier_filter, "-")

243
        branch_name
244
245
      end

href's avatar
href committed
246
247
248
249
250
251
252
253
    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())
254
255
256
    env_override = System.get_env("PLEROMA_BUILD_ENV")

    env_name =
257
258
259
260
      case env_override do
        nil -> env_name
        env_override when env_override in ["", "prod"] -> nil
        env_override -> env_override
261
262
      end

263
264
265
266
267
268
269
270
271
272
273
    # 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).()

274
275
    # Build metadata, denoted with a plus sign
    build_metadata =
href's avatar
href committed
276
277
      [build_name, env_name]
      |> Enum.filter(fn string -> string && string != "" end)
278
      |> Enum.join(".")
href's avatar
href committed
279
280
      |> (fn
            "" -> nil
281
            string -> "+" <> String.replace(string, identifier_filter, "-")
href's avatar
href committed
282
283
          end).()

284
    [version, pre_release, build_metadata]
href's avatar
href committed
285
286
287
    |> Enum.filter(fn string -> string && string != "" end)
    |> Enum.join()
  end
lain's avatar
lain committed
288
end