-
-
Save rwoeber/e0ace9cb7214941edfe8 to your computer and use it in GitHub Desktop.
Retrieving application version number in mix.exs from git describe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule MyApp.Mixfile do | |
| use Mix.Project | |
| def project do | |
| [app: :my_app, | |
| version: get_version, | |
| elixir: "~> 1.0", | |
| elixirc_paths: elixirc_paths(Mix.env), | |
| compilers: [:phoenix] ++ Mix.compilers, | |
| build_embedded: Mix.env == :prod, | |
| start_permanent: Mix.env == :prod, | |
| deps: deps] | |
| end | |
| # Configuration for the OTP application | |
| # | |
| # Type `mix help compile.app` for more information | |
| def application do | |
| [mod: {MyApp, []}, | |
| applications: [:phoenix, :phoenix_html, :cowboy, :logger, :con_cache, :conform]] | |
| end | |
| defp get_version do | |
| git_version = System.cmd("git", ["describe", "--always", "--tags"]) |> Tuple.to_list |> List.first |> String.strip | |
| case String.split(git_version, "-") do | |
| [tag] -> tag | |
| [tag, _num_commits, commit] -> "#{tag}-#{commit}" | |
| end | |
| end | |
| # Specifies which paths to compile per environment | |
| defp elixirc_paths(:test), do: ["lib", "web", "test/support"] | |
| defp elixirc_paths(_), do: ["lib", "web"] | |
| # Specifies your project dependencies | |
| # | |
| # Type `mix help deps` for examples and options | |
| defp deps do | |
| [{:phoenix, "~> 0.13.1"}, | |
| {:phoenix_html, "~> 1.0"}, | |
| {:phoenix_live_reload, "~> 0.4", only: :dev}, | |
| {:cowboy, "~> 1.0"}, | |
| {:exrm, "~> 0.19.0"}, | |
| {:conform, "~> 0.16.0"}, | |
| {:con_cache, "~> 0.8.0"}, | |
| ] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment