Skip to content
Permalink
Browse files

Changing the way that app VERSION is loaded so it can work with stand…

…alone releases by setting it to app config.
  • Loading branch information
diegomanuel committed Nov 18, 2019
1 parent 4eb8eae commit 41e88c0e4cd910e50a8f8c277d6eb8050841b303
Showing with 16 additions and 18 deletions.
  1. +1 −0 config/config.exs
  2. +2 −16 lib/live_qchatex/application.ex
  3. +13 −2 mix.exs
@@ -10,6 +10,7 @@ use Mix.Config
# Configures the endpoint
config :live_qchatex, LiveQchatexWeb.Endpoint,
environment: Mix.env(),
version: Mix.Project.config()[:git_version],
repo: Mix.Project.config()[:source_url],
demo: Mix.Project.config()[:demo_url],
url: [host: "localhost"],
@@ -8,8 +8,7 @@ defmodule LiveQchatex.Application do
require Logger

def start(_type, _args) do
# Load application version
load_version()
Logger.info("Starting app version: #{inspect(version())}", ansi_color: :yellow)

# List all child processes to be supervised
children = [
@@ -45,22 +44,9 @@ defmodule LiveQchatex.Application do
def env, do: Application.get_env(:live_qchatex, LiveQchatexWeb.Endpoint)[:environment]
def env?(environment), do: env() == environment

def version, do: Application.get_env(:live_qchatex, :version)
def version, do: Application.get_env(:live_qchatex, LiveQchatexWeb.Endpoint)[:version]
def version(key), do: version()[key]

defp load_version() do
[vsn, hash, date] =
case File.read("VERSION") do
{:ok, data} -> data |> String.split("\n")
_ -> [nil, nil, nil]
end

version = %{vsn: vsn, hash: hash, date: date}
Logger.info("Loading app version: #{inspect(version)}", ansi_color: :yellow)

Application.put_env(:live_qchatex, :version, version)
end

defp cluster_topologies(:test), do: []

defp cluster_topologies(_),
15 mix.exs
@@ -9,6 +9,7 @@ defmodule LiveQchatex.MixProject do
[
app: :live_qchatex,
version: @version,
git_version: read_git_version(),
name: "LiveQchatex",
description:
"Very simple and quick chat engine that allows you to create and join chat rooms on-the-fly.",
@@ -81,7 +82,7 @@ defmodule LiveQchatex.MixProject do
defp aliases do
[
coverage: ["coveralls.html"],
"deps.get": ["deps.get", &update_version/1],
"deps.get": ["deps.get", &update_git_version/1],
"mnesia.reset": fn _ -> reset_mnesia(Mix.env()) end
]
end
@@ -93,7 +94,17 @@ defmodule LiveQchatex.MixProject do
Mix.shell().cmd("rm -rf .mnesia")
end

defp update_version(_) do
defp read_git_version() do
[vsn, hash, date] =
case File.read("VERSION") do
{:ok, data} -> data |> String.split("\n")
_ -> [@version, nil, nil]
end

%{vsn: vsn, hash: hash, date: date}
end

defp update_git_version(_) do
contents = [
@version,
get_commit_sha(),

0 comments on commit 41e88c0

Please sign in to comment.
You can’t perform that action at this time.