From baf58c12341b79d1df348f8b5e5f0e3d84edc0e6 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sat, 15 Jun 2019 12:02:21 +0800 Subject: [PATCH 1/4] version generation --- mix.exs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index a38ea590a..3e3a21e42 100644 --- a/mix.exs +++ b/mix.exs @@ -176,7 +176,9 @@ defp version(version) do ahead <- String.replace(describe, tag, "") do {String.replace_prefix(tag, "v", ""), if(ahead != "", do: String.trim(ahead))} else - _ -> {nil, nil} + _ -> + {commit_hash, 0} = System.cmd("git", ["rev-parse", "--short", "HEAD"]) + {nil, "-g" <> String.trim(commit_hash)} end if git_tag && version != git_tag do @@ -203,8 +205,18 @@ defp version(version) do string -> "+" <> string end).() - [version, git_pre_release, build] - |> Enum.filter(fn string -> string && string != "" end) - |> Enum.join() + branch_name = + with {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]), + true <- branch_name != "master" do + "-" <> String.trim(branch_name) + end + + full_version = + [version, git_pre_release, branch_name, build] + |> Enum.filter(fn string -> string && string != "" end) + |> Enum.join() + + Mix.shell().info("Project version: #{full_version}") + full_version end end From 501705438f3223363312cc955a8e7b06722a1265 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sat, 15 Jun 2019 16:24:49 +0800 Subject: [PATCH 2/4] little fix --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 3e3a21e42..f82ae5243 100644 --- a/mix.exs +++ b/mix.exs @@ -178,7 +178,7 @@ defp version(version) do else _ -> {commit_hash, 0} = System.cmd("git", ["rev-parse", "--short", "HEAD"]) - {nil, "-g" <> String.trim(commit_hash)} + {nil, "-0-g" <> String.trim(commit_hash)} end if git_tag && version != git_tag do From e02f22d7790865be3f4d0b3d709d707c020a9ab7 Mon Sep 17 00:00:00 2001 From: Alex S Date: Sat, 15 Jun 2019 16:36:13 +0800 Subject: [PATCH 3/4] bugfix --- mix.exs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index f82ae5243..a52debc91 100644 --- a/mix.exs +++ b/mix.exs @@ -208,7 +208,11 @@ defp version(version) do branch_name = with {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]), true <- branch_name != "master" do - "-" <> String.trim(branch_name) + branch_name = + String.trim(branch_name) + |> String.replace(~r/\W+/, "-") + + "-" <> branch_name end full_version = From 451593f45e517db5ef81af0d3ec94c206a5e3bcd Mon Sep 17 00:00:00 2001 From: Alex S Date: Sun, 16 Jun 2019 11:48:15 +0800 Subject: [PATCH 4/4] no print version to the shell --- mix.exs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mix.exs b/mix.exs index a52debc91..93f2d8476 100644 --- a/mix.exs +++ b/mix.exs @@ -215,12 +215,8 @@ defp version(version) do "-" <> branch_name end - full_version = - [version, git_pre_release, branch_name, build] - |> Enum.filter(fn string -> string && string != "" end) - |> Enum.join() - - Mix.shell().info("Project version: #{full_version}") - full_version + [version, git_pre_release, branch_name, build] + |> Enum.filter(fn string -> string && string != "" end) + |> Enum.join() end end