Skip to content

Commit

Permalink
put back the version tuple thing
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Jul 27, 2023
1 parent 6183d56 commit 6e150a7
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions lib/lightning_web/live/components/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,42 @@ defmodule LightningWeb.Components.Common do

alias Phoenix.LiveView.JS

@spec version_tuple(any, any, any, any) ::
{any, <<_::64, _::_*8>>, :edge | :no_docker | :release | :warn}
def version_tuple(image, branch, commit, vsn) do
cond do
# If running in docker on edge, display commit SHA.
image == "edge" ->
{commit,
"Docker image tag found: '#{image}' unreleased build from #{commit} on #{branch}",
:edge}

# If running in docker and tag matches :vsn, display :vsn and standard message.
image == vsn ->
{vsn,
"Docker image tag found: '#{image}' tagged release build from #{commit}",
:release}

# If running in docker and tag doesn't match :vsn, display image tag.
image != nil and image != vsn and image != "edge" ->
{image,
"Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",
:warn}

# If running in docker and tag doesn't match :vsn, display commit.
image != nil and image != vsn ->
{commit,
"Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",
:warn}

true ->
{vsn, "Lightning #{vsn}", :no_docker}
end
end

def version_chip(assigns) do
image_info = Application.get_env(:lightning, :image_info)
image = image_info[:image_tag]
branch = image_info[:branch]
commit = image_info[:commit]
vsn = "v#{elem(:application.get_key(:lightning, :vsn), 1)}"

{display, message, type} = version_tuple(image, branch, commit, vsn)
{display, message, type} =
cond do
# If running in docker on edge, display commit SHA.
image == "edge" ->
{commit,
"Docker image tag found: '#{image}' unreleased build from #{commit} on #{branch}",
:edge}

# If running in docker and tag matches :vsn, display :vsn and standard message.
image == vsn ->
{vsn,
"Docker image tag found: '#{image}' tagged release build from #{commit}",
:release}

# If running in docker and tag doesn't match :vsn, display image tag.
image != nil and image != vsn and image != "edge" ->
{image,
"Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",
:warn}

# If running in docker and tag doesn't match :vsn, display commit.
image != nil and image != vsn ->
{commit,
"Detected image tag that does not match application version #{vsn}; image tag '#{image}' built from #{commit}",

Check warning on line 37 in lib/lightning_web/live/components/common.ex

View check run for this annotation

Codecov / codecov/patch

lib/lightning_web/live/components/common.ex#L37

Added line #L37 was not covered by tests
:warn}

true ->
{vsn, "Lightning #{vsn}", :no_docker}
end

icon_classes = "h-4 w-4 inline-block mr-1"

Expand Down

0 comments on commit 6e150a7

Please sign in to comment.