From e181abf57765f7804ff84f09b32a2e16b8ef6e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 4 Jul 2022 19:14:52 +0200 Subject: [PATCH] set version from git tag. --- Dockerfile | 9 +++++---- build | 10 ++++++---- neko.go | 35 ++++++++++++++++------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0d509d1d..d64f563f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,8 +17,9 @@ RUN set -eux; \ apt-get clean -y; \ rm -rf /var/lib/apt/lists/* /var/cache/apt/* -ARG GIT_COMMIT=dev -ARG GIT_BRANCH=dev +ARG GIT_COMMIT +ARG GIT_BRANCH +ARG GIT_TAG # # build server @@ -49,8 +50,8 @@ RUN set -eux; \ # needed for profile upload preStop hook zip curl \ # - # file chooser handler, clipboard - xdotool xclip \ + # file chooser handler, clipboard, drop + xdotool xclip libgtk-3-0 \ # # gst gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ diff --git a/build b/build index 16fb5d7f..163cb38f 100755 --- a/build +++ b/build @@ -13,10 +13,11 @@ fi # # set git build variables if git exists -if git version > /dev/null && [ -z $GIT_COMMIT ] && [ -z $GIT_COMMIT ]; +if git version > /dev/null && [ -z $GIT_COMMIT ] && [ -z $GIT_BRANCH ] && [ -z $GIT_TAG ]; then GIT_COMMIT=`git rev-parse --short HEAD` GIT_BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` + GIT_TAG=`git tag --points-at $GIT_COMMIT | head -n 1` fi # @@ -29,9 +30,10 @@ go build \ -o bin/neko \ -ldflags " -s -w - -X 'demodesk/neko.buildDate=`date -u +'%Y-%m-%dT%H:%M:%SZ'`' - -X 'demodesk/neko.gitCommit=${GIT_COMMIT}' - -X 'demodesk/neko.gitBranch=${GIT_BRANCH}' + -X 'gitlab.com/demodesk/neko/server.buildDate=`date -u +'%Y-%m-%dT%H:%M:%SZ'`' + -X 'gitlab.com/demodesk/neko/server.gitCommit=${GIT_COMMIT}' + -X 'gitlab.com/demodesk/neko/server.gitBranch=${GIT_BRANCH}' + -X 'gitlab.com/demodesk/neko/server.gitTag=${GIT_TAG}' " \ cmd/neko/main.go; diff --git a/neko.go b/neko.go index 1770ccef..d25ee6a7 100644 --- a/neko.go +++ b/neko.go @@ -3,6 +3,7 @@ package neko import ( "fmt" "runtime" + "strings" ) const Header = `&34 @@ -11,7 +12,7 @@ const Header = `&34 / |/ / _ \/ //_/ __ \ ) ( ') / /| / __/ ,< / /_/ / ( / ) /_/ |_/\___/_/|_|\____/ \(__)| -&1&37 nurdism/m1k1o &33%s v%s&0 +&1&37 nurdism/m1k1o &33%s %s&0 ` var ( @@ -21,21 +22,14 @@ var ( gitCommit = "dev" // gitBranch = "dev" - - // Major version when you make incompatible API changes. - major = "dev" - // Minor version when you add functionality in a backwards-compatible manner. - minor = "dev" - // Patch version when you make backwards-compatible bug fixes. - patch = "dev" + // + gitTag = "dev" ) var Version = &version{ - Major: major, - Minor: minor, - Patch: patch, GitCommit: gitCommit, GitBranch: gitBranch, + GitTag: gitTag, BuildDate: buildDate, GoVersion: runtime.Version(), Compiler: runtime.Compiler, @@ -43,11 +37,9 @@ var Version = &version{ } type version struct { - Major string - Minor string - Patch string GitCommit string GitBranch string + GitTag string BuildDate string GoVersion string Compiler string @@ -55,18 +47,23 @@ type version struct { } func (i *version) String() string { - return fmt.Sprintf("%s.%s.%s %s", i.Major, i.Minor, i.Patch, i.GitCommit) + version := i.GitTag + if version == "" || version == "dev" { + version = i.GitBranch + } + + return fmt.Sprintf("%s@%s", version, i.GitCommit) } func (i *version) Details() string { - return fmt.Sprintf( - "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - fmt.Sprintf("Version %s.%s.%s", i.Major, i.Minor, i.Patch), + return "\n" + strings.Join([]string{ + fmt.Sprintf("Version %s", i.String()), fmt.Sprintf("GitCommit %s", i.GitCommit), fmt.Sprintf("GitBranch %s", i.GitBranch), + fmt.Sprintf("GitTag %s", i.GitTag), fmt.Sprintf("BuildDate %s", i.BuildDate), fmt.Sprintf("GoVersion %s", i.GoVersion), fmt.Sprintf("Compiler %s", i.Compiler), fmt.Sprintf("Platform %s", i.Platform), - ) + }, "\n") + "\n" }