Skip to content

Instantly share code, notes, and snippets.

@rwoeber
Forked from jeffweiss/mix.exs
Created January 16, 2016 15:56
Show Gist options
  • Select an option

  • Save rwoeber/e0ace9cb7214941edfe8 to your computer and use it in GitHub Desktop.

Select an option

Save rwoeber/e0ace9cb7214941edfe8 to your computer and use it in GitHub Desktop.

Revisions

  1. Jeff Weiss revised this gist Oct 6, 2015. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion post-checkout
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    #!/bin/bash
    # installed to .git/hooks/post-checkout
    `git describe > VERSION`
    `git describe --always --tags > VERSION`
    2 changes: 1 addition & 1 deletion post-commit
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    #!/bin/bash
    # installed to .git/hooks/post-commit
    `git describe > VERSION`
    `git describe --always --tags > VERSION`
  2. Jeff Weiss revised this gist Oct 5, 2015. 3 changed files with 32 additions and 15 deletions.
    41 changes: 26 additions & 15 deletions mix.exs
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ defmodule MyApp.Mixfile do
    version: get_version,
    elixir: "~> 1.0",
    elixirc_paths: elixirc_paths(Mix.env),
    compilers: [:phoenix] ++ Mix.compilers,
    compilers: Mix.compilers,
    build_embedded: Mix.env == :prod,
    start_permanent: Mix.env == :prod,
    deps: deps]
    @@ -17,21 +17,38 @@ defmodule MyApp.Mixfile do
    # Type `mix help compile.app` for more information
    def application do
    [mod: {MyApp, []},
    applications: [:phoenix, :phoenix_html, :cowboy, :logger, :con_cache, :conform]]
    applications: [:logger]]
    end

    defp get_version do
    System.cmd("git", ["describe", "--always", "--tags"])
    |> Tuple.to_list
    |> List.first
    |> String.strip
    |> String.split(git_version, "-")
    version_from_file
    |> handle_file_version
    |> String.split("-")
    |> case do
    [tag] -> tag
    [tag, _num_commits, commit] -> "#{tag}-#{commit}"
    end
    end

    defp version_from_file(file \\ "VERSION") do
    File.read(file)
    end

    defp handle_file_version({:ok, content}) do
    content
    end
    defp handle_file_version({:error, _}) do
    retrieve_version_from_git
    end
    defp retrieve_version_from_git do
    require Logger
    Logger.warn "Calling out to `git describe` for the version number. This is slow! You should think about a hook to set the VERSION file"
    System.cmd("git", ["describe", "--always", "--tags"])
    |> Tuple.to_list
    |> List.first
    |> String.strip
    end

    # Specifies which paths to compile per environment
    defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
    defp elixirc_paths(_), do: ["lib", "web"]
    @@ -40,13 +57,7 @@ defmodule MyApp.Mixfile do
    #
    # 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
    end
    3 changes: 3 additions & 0 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash
    # installed to .git/hooks/post-checkout
    `git describe > VERSION`
    3 changes: 3 additions & 0 deletions post-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash
    # installed to .git/hooks/post-commit
    `git describe > VERSION`
  3. Jeff Weiss revised this gist Oct 5, 2015. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions mix.exs
    Original file line number Diff line number Diff line change
    @@ -21,8 +21,12 @@ defmodule MyApp.Mixfile do
    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
    System.cmd("git", ["describe", "--always", "--tags"])
    |> Tuple.to_list
    |> List.first
    |> String.strip
    |> String.split(git_version, "-")
    |> case do
    [tag] -> tag
    [tag, _num_commits, commit] -> "#{tag}-#{commit}"
    end
  4. Jeff Weiss created this gist Oct 5, 2015.
    48 changes: 48 additions & 0 deletions mix.exs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    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