From 2782ab088337cb92fa5bfe26b08f94f75b636fc2 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 1 Aug 2022 15:23:43 +0200 Subject: [PATCH 1/3] Get app version using VERSION env or git script --- hack/get_version_from_git.sh | 3 +++ mix.exs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hack/get_version_from_git.sh b/hack/get_version_from_git.sh index 6fee3489dc..c811cd1de6 100755 --- a/hack/get_version_from_git.sh +++ b/hack/get_version_from_git.sh @@ -1,4 +1,7 @@ #!/bin/sh +set -e +set -o pipefail + TAG=$( git tag | grep -E "[0-9]\.[0-9]\.[0-9]" | sort -rn | head -n1 ) if [ -n "${TAG}" ]; then diff --git a/mix.exs b/mix.exs index f864030758..bc3b798163 100644 --- a/mix.exs +++ b/mix.exs @@ -1,11 +1,26 @@ defmodule Trento.MixProject do use Mix.Project + @version "1.1.0" + defp get_version do + case System.get_env("VERSION") do + nil -> get_version_from_git() + version -> version + end + end + + defp get_version_from_git do + case File.cwd!() |> Path.join("hack/get_version_from_git.sh") |> System.cmd([]) do + {version, 0} -> version |> String.trim("\n") + _ -> @version + end + end + def project do [ app: :trento, description: "Easing your life in administering SAP applications", - version: "1.1.0", + version: get_version(), elixir: "~> 1.13", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:gettext] ++ Mix.compilers(), From 13319a871ee6a17b5984ef24f24a9b93b4c14148 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 1 Aug 2022 15:24:08 +0200 Subject: [PATCH 2/3] Update suse container and ci to set the version --- .github/workflows/ci.yaml | 5 ++++- packaging/suse/Dockerfile | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 620b0291ca..8aeb3e4bff 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -484,7 +484,10 @@ jobs: - name: Set version run: | - VERSION=${{ steps.latest-tag.outputs.tag }} + git config --global --add safe.directory /__w/web/web + VERSION=$(./hack/get_version_from_git.sh) + # "+" character is not allowed in OBS dockerfile version strings + VERSION=${VERSION//[+]/-} sed -i 's~%%VERSION%%~'"${VERSION}"'~' packaging/suse/Dockerfile - name: Commit on OBS diff --git a/packaging/suse/Dockerfile b/packaging/suse/Dockerfile index e475481bb7..0820918de2 100644 --- a/packaging/suse/Dockerfile +++ b/packaging/suse/Dockerfile @@ -22,7 +22,7 @@ ENV MIX_ENV=prod ENV MIX_HOME=/usr/bin ENV FLAVOR="Premium" RUN mix phx.digest -RUN mix release +RUN VERSION=%%VERSION%% mix release FROM bci/bci-base:15.3 AS trento # Define labels according to https://en.opensuse.org/Building_derived_containers From 6500dcd784ea9d368709de663b74a7c001c14751 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 1 Aug 2022 17:37:44 +0200 Subject: [PATCH 3/3] Apply better elixir conventions --- mix.exs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/mix.exs b/mix.exs index bc3b798163..1860f7597e 100644 --- a/mix.exs +++ b/mix.exs @@ -2,19 +2,6 @@ defmodule Trento.MixProject do use Mix.Project @version "1.1.0" - defp get_version do - case System.get_env("VERSION") do - nil -> get_version_from_git() - version -> version - end - end - - defp get_version_from_git do - case File.cwd!() |> Path.join("hack/get_version_from_git.sh") |> System.cmd([]) do - {version, 0} -> version |> String.trim("\n") - _ -> @version - end - end def project do [ @@ -136,4 +123,13 @@ defmodule Trento.MixProject do ] ] end + + defp get_version, do: System.get_env("VERSION", get_version_from_git()) + + defp get_version_from_git do + case File.cwd!() |> Path.join("hack/get_version_from_git.sh") |> System.cmd([]) do + {version, 0} -> version |> String.trim("\n") + _ -> @version + end + end end