mix.exs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. defmodule Toy.MixProject do
  2. use Mix.Project
  3. def project do
  4. [
  5. app: :toy,
  6. version: from_file(),
  7. elixir: "~> 1.12",
  8. elixirc_paths: elixirc_paths(Mix.env()),
  9. compilers: [:gettext] ++ Mix.compilers(),
  10. start_permanent: Mix.env() == :prod,
  11. aliases: aliases(),
  12. deps: deps(),
  13. releases: [toy: [steps: [:assemble, &export_sha1/1, &export_docker_image_tag/1, :tar]]]
  14. ]
  15. end
  16. # Configuration for the OTP application.
  17. #
  18. # Type `mix help compile.app` for more information.
  19. def application do
  20. [
  21. mod: {Toy.Application, []},
  22. extra_applications: [:logger, :runtime_tools]
  23. ]
  24. end
  25. # Specifies which paths to compile per environment.
  26. # "config" is required for Config.Helper module
  27. defp elixirc_paths(:test), do: ["lib", "config", "test/support"]
  28. defp elixirc_paths(_), do: ["lib", "config"]
  29. # Specifies your project dependencies.
  30. #
  31. # Type `mix help deps` for examples and options.
  32. defp deps do
  33. [
  34. {:phoenix, "~> 1.6.2"},
  35. {:phoenix_ecto, "~> 4.4"},
  36. {:ecto_sql, "~> 3.6"},
  37. {:postgrex, ">= 0.0.0"},
  38. {:phoenix_html, "~> 3.0"},
  39. {:phoenix_live_reload, "~> 1.2", only: :dev},
  40. {:phoenix_live_view, "~> 0.16.0"},
  41. {:floki, ">= 0.30.0", only: :test},
  42. {:phoenix_live_dashboard, "~> 0.5"},
  43. {:esbuild, "~> 0.2", runtime: Mix.env() == :dev},
  44. {:swoosh, "~> 1.3"},
  45. {:telemetry_metrics, "~> 0.6"},
  46. {:telemetry_poller, "~> 1.0"},
  47. {:gettext, "~> 0.18"},
  48. {:jason, "~> 1.2"},
  49. {:plug_cowboy, "~> 2.5"}
  50. ]
  51. end
  52. # Aliases are shortcuts or tasks specific to the current project.
  53. # For example, to install project dependencies and perform other setup tasks, run:
  54. #
  55. # $ mix setup
  56. #
  57. # See the documentation for `Mix` for more info on aliases.
  58. defp aliases do
  59. [
  60. setup: ["deps.get", "ecto.setup"],
  61. "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
  62. "ecto.reset": ["ecto.drop", "ecto.setup"],
  63. test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
  64. version: ["run -e \"Mix.Project.config[:version] |> IO.puts\""],
  65. "assets.deploy": ["esbuild default --minify", "phx.digest"]
  66. ]
  67. end
  68. defp from_file(file \\ "VERSION") do
  69. with {:ok, described} <- File.read(file),
  70. {:ok, version} <- described |> String.trim() |> to_semver_string() do
  71. version
  72. end
  73. end
  74. defp to_semver_string(described) when is_binary(described) do
  75. with {:ok, _} <- described |> Version.parse(), do: {:ok, described}
  76. end
  77. defp export_sha1(rel) when is_struct(rel, Mix.Release) do
  78. with {sha1, 0} <- System.cmd("git", ["rev-parse", "HEAD"]),
  79. :ok <- rel |> write_in_rel_path("git-sha1", sha1),
  80. do: rel
  81. end
  82. defp export_docker_image_tag(rel) when is_struct(rel, Mix.Release) do
  83. with image_tag when not is_nil(image_tag) <- System.get_env("DOCKER_IMAGE_TAG"),
  84. :ok <- rel |> write_in_rel_path("docker-image-tag", "#{image_tag}\n") do
  85. rel
  86. else
  87. nil -> rel
  88. end
  89. end
  90. defp write_in_rel_path(%{version_path: path}, file_path, content) do
  91. path |> Path.join(file_path) |> File.write(content)
  92. end
  93. end