Skip to content

Commit

Permalink
Set version with git (#735)
Browse files Browse the repository at this point in the history
* Get app version using VERSION env or git script

* Update suse container and ci to set the version

* Apply better elixir conventions
  • Loading branch information
arbulu89 authored Aug 2, 2022
1 parent 8daf568 commit e9881db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hack/get_version_from_git.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 12 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
defmodule Trento.MixProject do
use Mix.Project

@version "1.1.0"

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: Mix.compilers(),
Expand Down Expand Up @@ -121,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
2 changes: 1 addition & 1 deletion packaging/suse/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e9881db

Please sign in to comment.