From cde9c19f717b608506ac0d13c5ab839b98d95cd7 Mon Sep 17 00:00:00 2001 From: Jakub Date: Fri, 26 May 2023 15:07:35 +0200 Subject: [PATCH] feat(GODT-2655): display internal build time tag in log and GUI. --- Makefile | 6 ++- internal/app/app.go | 1 + internal/constants/constants.go | 5 ++- .../bridge-gui/bridge-gui/BuildConfig.h.in | 1 + .../bridge-gui/bridge-gui/QMLBackend.cpp | 11 ++++- .../bridge-gui/bridge-gui/QMLBackend.h | 3 ++ .../frontend/bridge-gui/bridge-gui/build.ps1 | 2 + .../frontend/bridge-gui/bridge-gui/build.sh | 2 + .../bridge-gui/bridge-gui/qml/HelpView.qml | 3 +- utils/get_revision.sh | 42 +++++++++++++++++++ 10 files changed, 71 insertions(+), 5 deletions(-) create mode 100755 utils/get_revision.sh diff --git a/Makefile b/Makefile index 52d0083f..b7a285d3 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,8 @@ SRC_ICO:=bridge.ico SRC_ICNS:=Bridge.icns SRC_SVG:=bridge.svg EXE_NAME:=proton-bridge -REVISION:=$(shell git rev-parse --short=10 HEAD) +REVISION:=$(shell ./utils/get_revision.sh) +TAG:=$(shell ./utils/get_revision.sh tag) BUILD_TIME:=$(shell date +%FT%T%z) MACOS_MIN_VERSION_ARM64=11.0 MACOS_MIN_VERSION_AMD64=10.15 @@ -27,7 +28,7 @@ BUILD_ENV?=dev BUILD_FLAGS:=-tags='${BUILD_TAGS}' BUILD_FLAGS_LAUNCHER:=${BUILD_FLAGS} -GO_LDFLAGS:=$(addprefix -X github.com/ProtonMail/proton-bridge/v3/internal/constants., Version=${APP_VERSION} Revision=${REVISION} BuildTime=${BUILD_TIME}) +GO_LDFLAGS:=$(addprefix -X github.com/ProtonMail/proton-bridge/v3/internal/constants., Version=${APP_VERSION} Revision=${REVISION} Tag=${TAG} BuildTime=${BUILD_TIME}) GO_LDFLAGS+=-X "github.com/ProtonMail/proton-bridge/v3/internal/constants.FullAppName=${APP_FULL_NAME}" ifneq "${DSN_SENTRY}" "" @@ -158,6 +159,7 @@ ${EXE_TARGET}: check-build-essentials ${EXE_NAME} BRIDGE_VENDOR="${APP_VENDOR}" \ BRIDGE_APP_VERSION=${APP_VERSION} \ BRIDGE_REVISION=${REVISION} \ + BRIDGE_TAG=${TAG} \ BRIDGE_DSN_SENTRY=${DSN_SENTRY} \ BRIDGE_BUILD_TIME=${BUILD_TIME} \ BRIDGE_GUI_BUILD_CONFIG=Release \ diff --git a/internal/app/app.go b/internal/app/app.go index 90ce7192..fb2e63cc 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -322,6 +322,7 @@ func withLogging(c *cli.Context, crashHandler *crash.Handler, locations *locatio WithField("appName", constants.FullAppName). WithField("version", constants.Version). WithField("revision", constants.Revision). + WithField("tag", constants.Tag). WithField("build", constants.BuildTime). WithField("runtime", runtime.GOOS). WithField("args", os.Args). diff --git a/internal/constants/constants.go b/internal/constants/constants.go index ac2942df..35bf0cee 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -33,9 +33,12 @@ var ( // Version of the build. Version = "0.0.0" - // Revision is current hash of the build. + // Revision is build time commit hash. Revision = "" + // Tag is build time git describe. + Tag = "" + // BuildTime stamp of the build. BuildTime = "" diff --git a/internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in b/internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in index cc05b229..be6335b4 100644 --- a/internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in +++ b/internal/frontend/bridge-gui/bridge-gui/BuildConfig.h.in @@ -23,6 +23,7 @@ #define PROJECT_VENDOR "@BRIDGE_VENDOR@" #define PROJECT_VER "@BRIDGE_APP_VERSION@" #define PROJECT_REVISION "@BRIDGE_REVISION@" +#define PROJECT_TAG "@BRIDGE_TAG@" #define PROJECT_BUILD_TIME "@BRIDGE_BUILD_TIME@" #define PROJECT_DSN_SENTRY "@BRIDGE_DSN_SENTRY@" #define PROJECT_BUILD_ENV "@BRIDGE_BUILD_ENV@" diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp index b10002a4..f6471239 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp @@ -286,7 +286,7 @@ QString QMLBackend::vendor() const { //**************************************************************************************************************************************************** -/// \return The value for the 'vendor' property. +/// \return The value for the 'version' property. //**************************************************************************************************************************************************** QString QMLBackend::version() const { HANDLE_EXCEPTION_RETURN_QSTRING( @@ -296,6 +296,15 @@ QString QMLBackend::version() const { ) } +//**************************************************************************************************************************************************** +/// \return The value for the 'tag' property. +//**************************************************************************************************************************************************** +QString QMLBackend::tag() const { + HANDLE_EXCEPTION_RETURN_QSTRING( + return QString(PROJECT_TAG); + ) +} + //**************************************************************************************************************************************************** /// \return The value for the 'hostname' property. diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h index 7ee7e4f1..c5b5c9c5 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h @@ -65,6 +65,7 @@ public: // Qt/QML properties. Note that the NOTIFY-er signal is required even fo Q_PROPERTY(QString appname READ appname NOTIFY appnameChanged) Q_PROPERTY(QString vendor READ vendor NOTIFY vendorChanged) Q_PROPERTY(QString version READ version NOTIFY versionChanged) + Q_PROPERTY(QString tag READ tag NOTIFY tagChanged) Q_PROPERTY(QString hostname READ hostname NOTIFY hostnameChanged) Q_PROPERTY(bool isAutostartOn READ isAutostartOn NOTIFY isAutostartOnChanged) Q_PROPERTY(bool isBetaEnabled READ isBetaEnabled NOTIFY isBetaEnabledChanged) @@ -98,6 +99,7 @@ public: // Qt/QML properties. Note that the NOTIFY-er signal is required even fo QString appname() const; ///< Getter for the 'appname' property. QString vendor() const; ///< Getter for the 'vendor' property. QString version() const; ///< Getter for the 'version' property. + QString tag() const; ///< Getter for the 'tag' property. QString hostname() const; ///< Getter for the 'hostname' property. bool isAutostartOn() const; ///< Getter for the 'isAutostartOn' property. bool isBetaEnabled() const; ///< Getter for the 'isBetaEnabled' property. @@ -144,6 +146,7 @@ signals: // Signal used by the Qt property system. Many of them are unused but r void appnameChanged(QString const &appname); ///© 2017-%3 %4
%5 %6
%7"). + text: qsTr("%1 v%2 (%3)
© 2017-%4 %5
%6 %7
%8"). arg(Backend.appname). arg(Backend.version). + arg(Backend.tag). arg(Backend.buildYear()). arg(Backend.vendor). arg(link(Backend.licensePath, qsTr("License"))). diff --git a/utils/get_revision.sh b/utils/get_revision.sh new file mode 100755 index 00000000..18f18f57 --- /dev/null +++ b/utils/get_revision.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Copyright (c) 2023 Proton AG +# +# This file is part of Proton Mail Bridge. +# +# Proton Mail Bridge is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Proton Mail Bridge is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Proton Mail Bridge. If not, see . + + +if ! which git &> /dev/null; then + echo "NOGIT" + exit +fi + +if ! git status &> /dev/null; then + echo "NOREPO" + exit +fi + +if [ "$1" == "tag" ]; then + if ! git describe --tags; then + echo "NOTAG" + fi + exit +fi + +if ! git rev-parse --short=10 HEAD; then + echo "NOREV" + exit +fi +