Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically determine current version from git tags #45

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
Expand Down Expand Up @@ -116,6 +117,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Determine Arch
run: |
if [ "${{ matrix.os }}" = "macos-13" ]; then
Expand All @@ -139,20 +141,20 @@ jobs:
export CFLAGS="-Wno-narrowing -O3"
./compile_libs.sh
cp libcld2.dylib ../../../lib/MacOS
- name: Fix Qt lib rpaths # see: https://github.com/orgs/Homebrew/discussions/2823#discussioncomment-2010340)
run: |
install_name_tool -id '@rpath/QtCore.framework/Versions/A/QtCore' $(brew --prefix)/lib/QtCore.framework/Versions/A/QtCore
install_name_tool -id '@rpath/QtGui.framework/Versions/A/QtGui' $(brew --prefix)/lib/QtGui.framework/Versions/A/QtGui
install_name_tool -id '@rpath/QtNetwork.framework/Versions/A/QtNetwork' $(brew --prefix)/lib/QtNetwork.framework/Versions/A/QtNetwork
install_name_tool -id '@rpath/QtWidgets.framework/Versions/A/QtWidgets' $(brew --prefix)/lib/QtWidgets.framework/Versions/A/QtWidgets
install_name_tool -id '@rpath/QtPdf.framework/Versions/A/QtPdf' $(brew --prefix)/lib/QtPdf.framework/Versions/A/QtPdf
install_name_tool -id '@rpath/QtSvg.framework/Versions/A/QtSvg' $(brew --prefix)/lib/QtSvg.framework/Versions/A/QtSvg
install_name_tool -id '@rpath/QtVirtualKeyboard.framework/Versions/A/QtVirtualKeyboard' $(brew --prefix)/lib/QtVirtualKeyboard.framework/Versions/A/QtVirtualKeyboard
install_name_tool -id '@rpath/QtQuick.framework/Versions/A/QtQuick' $(brew --prefix)/lib/QtQuick.framework/Versions/A/QtQuick
install_name_tool -id '@rpath/QtQmlModels.framework/Versions/A/QtQmlModels' $(brew --prefix)/lib/QtQmlModels.framework/Versions/A/QtQmlModels
install_name_tool -id '@rpath/QtQml.framework/Versions/A/QtQml' $(brew --prefix)/lib/QtQml.framework/Versions/A/QtQml
install_name_tool -id '@rpath/QtOpenGL.framework/Versions/A/QtOpenGL' $(brew --prefix)/lib/QtOpenGL.framework/Versions/A/QtOpenGL
install_name_tool -id '@rpath/QtMultimedia.framework/Versions/A/QtMultimedia' $(brew --prefix)/lib/QtMultimedia.framework/Versions/A/QtMultimedia
- name: Fix Qt lib rpaths # see: https://github.com/orgs/Homebrew/discussions/2823#discussioncomment-2010340)
run: |
install_name_tool -id '@rpath/QtCore.framework/Versions/A/QtCore' $(brew --prefix)/lib/QtCore.framework/Versions/A/QtCore
install_name_tool -id '@rpath/QtGui.framework/Versions/A/QtGui' $(brew --prefix)/lib/QtGui.framework/Versions/A/QtGui
install_name_tool -id '@rpath/QtNetwork.framework/Versions/A/QtNetwork' $(brew --prefix)/lib/QtNetwork.framework/Versions/A/QtNetwork
install_name_tool -id '@rpath/QtWidgets.framework/Versions/A/QtWidgets' $(brew --prefix)/lib/QtWidgets.framework/Versions/A/QtWidgets
install_name_tool -id '@rpath/QtPdf.framework/Versions/A/QtPdf' $(brew --prefix)/lib/QtPdf.framework/Versions/A/QtPdf
install_name_tool -id '@rpath/QtSvg.framework/Versions/A/QtSvg' $(brew --prefix)/lib/QtSvg.framework/Versions/A/QtSvg
install_name_tool -id '@rpath/QtVirtualKeyboard.framework/Versions/A/QtVirtualKeyboard' $(brew --prefix)/lib/QtVirtualKeyboard.framework/Versions/A/QtVirtualKeyboard
install_name_tool -id '@rpath/QtQuick.framework/Versions/A/QtQuick' $(brew --prefix)/lib/QtQuick.framework/Versions/A/QtQuick
install_name_tool -id '@rpath/QtQmlModels.framework/Versions/A/QtQmlModels' $(brew --prefix)/lib/QtQmlModels.framework/Versions/A/QtQmlModels
install_name_tool -id '@rpath/QtQml.framework/Versions/A/QtQml' $(brew --prefix)/lib/QtQml.framework/Versions/A/QtQml
install_name_tool -id '@rpath/QtOpenGL.framework/Versions/A/QtOpenGL' $(brew --prefix)/lib/QtOpenGL.framework/Versions/A/QtOpenGL
install_name_tool -id '@rpath/QtMultimedia.framework/Versions/A/QtMultimedia' $(brew --prefix)/lib/QtMultimedia.framework/Versions/A/QtMultimedia
bohning marked this conversation as resolved.
Show resolved Hide resolved
- name: Build plugins
run: |
cd src/plugins/audiotag/
Expand Down Expand Up @@ -202,6 +204,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*.stash
*.user
bin
src/version.h
src/tmp
src/*.autosave
src/ui
Expand Down
5 changes: 2 additions & 3 deletions src/QUAboutDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "QUAboutDialog.h"
#include "main.h"
#include "version.h"
#include <QTimer>
#include <QScrollBar>
#include <QFile>
Expand Down Expand Up @@ -107,10 +106,10 @@ QUAboutDialog::QUAboutDialog(QWidget *parent): QDialog(parent) {

credits->setHtml(creditsText);

QDateTime dateTime = QDateTime::fromString(QString(date_time), "dd.MM.yyyy HH:mm");
QDateTime dateTime = QDateTime::fromString(QString(xstr(DATE_TIME)), "dd.MM.yyyy HH:mm");

versionLbl->setText(QString(tr("Version: <b>%1</b><br>Date: %2"))
.arg(QString(revision), dateTime.toString("yyyy-MM-dd, HH:mm")));
.arg(QString(xstr(REVISION)), dateTime.toString("yyyy-MM-dd, HH:mm")));

resetText();
credits->document()->setDefaultStyleSheet("a {color: white}");
Expand Down
26 changes: 13 additions & 13 deletions src/QUMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QTemporaryFile>
#include <QJsonDocument>

#include "QUSongItem.h"
#include "QUDetailItem.h"
Expand Down Expand Up @@ -993,9 +994,10 @@ void QUMainWindow::aboutMediaInfo() {
}

void QUMainWindow::checkForUpdate(bool silent) {
int currentVersion = MAJOR_VERSION*100 + MINOR_VERSION*10 + PATCH_VERSION;
QString currentVersion = QString(xstr(VERSION));
int currentVersionNum = QString(currentVersion).remove('.').toInt();

QUrl url("https://github.com/UltraStar-Deluxe/UltraStar-Manager/blob/master/src/latest_version.xml");
QUrl url("https://api.github.com/repos/UltraStar-Deluxe/UltraStar-Manager/releases/latest");
DeinAlptraum marked this conversation as resolved.
Show resolved Hide resolved
QNetworkAccessManager *m_NetworkMngr = new QNetworkAccessManager(this);
QNetworkReply *reply = m_NetworkMngr->get(QNetworkRequest(url));

Expand Down Expand Up @@ -1027,20 +1029,18 @@ void QUMainWindow::checkForUpdate(bool silent) {
return;
}

tmp.write(reply->readAll());
tmp.seek(0);
bohning marked this conversation as resolved.
Show resolved Hide resolved
QString line = QString(tmp.readLine());
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
QString line = json["tag_name"].toString();
QString latestVersionString = line;
int latestVersion = line.remove('.').toInt();
int latestVersion = line.remove('.').remove('v').toInt();
delete reply;
tmp.remove();

if (currentVersion < latestVersion) {
if (currentVersionNum < latestVersion) {
QUMessageBox::information(this,
tr("Update check successful."),
QString(tr("UltraStar Manager %1.%2.%3 is <b>outdated</b>.<br><br>"
"Download the most recent UltraStar-Manager %4 <a href='https://github.com/UltraStar-Deluxe/UltraStar-Manager/releases'>here</a>."))
.arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(PATCH_VERSION)
QString(tr("UltraStar Manager %1 is <b>outdated</b>.<br><br>"
"Download the most recent UltraStar-Manager %2 <a href='https://github.com/UltraStar-Deluxe/UltraStar-Manager/releases'>here</a>."))
.arg(currentVersion)
.arg(latestVersionString),
BTN << ":/marks/accept.png" << "OK",
240);
Expand All @@ -1051,8 +1051,8 @@ void QUMainWindow::checkForUpdate(bool silent) {
QSettings settings;
int result = QUMessageBox::information(this,
tr("Update check successful."),
QString(tr("UltraStar Manager %1.%2.%3 is <b>up to date</b>!"))
.arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(PATCH_VERSION),
QString(tr("UltraStar Manager %1 is <b>up to date</b>!"))
.arg(currentVersion),
BTN << ":/marks/accept.png" << tr("OK. I will check again later.")
<< ":/marks/accept.png" << tr("OK. Check automatically on startup."),
240);
Expand Down
23 changes: 6 additions & 17 deletions src/UltraStar-Manager.pro
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ INCLUDEPATH += . \
remoteimages \
webinfo

DEFINES += REVISION=$$system(git describe --always --tags --match "[0-9].[0-9].[0-9]") \
VERSION=$$system(git describe --tags --abbrev=0 --match "[0-9].[0-9].[0-9]")

win32 {
INCLUDEPATH += ../include/cld2/public \
../include/taglib \
Expand All @@ -256,6 +259,8 @@ win32 {
-lzlib

RC_ICONS += UltraStar-Manager.ico

DEFINES += DATE_TIME=\"$$quote($$system(date /T) $$system(time /T))\"
}

macx {
Expand Down Expand Up @@ -291,26 +296,10 @@ unix:!macx {
QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN\''
}

QMAKE_EXTRA_TARGETS += revtarget
PRE_TARGETDEPS += version.h
revtarget.target = version.h

win32 {
revtarget.commands = "$$system(echo 'const char *revision = \"$$system(git describe --always)\";' > $$revtarget.target)"
revtarget.commands += "$$system(echo 'const char *date_time = \"$$system(date /T) $$system(time /T)\";' >> $$revtarget.target)"
}

unix {
revtarget.commands = @echo \
"const char *revision = \\\"`git describe --always`\\\"\\; \
const char *date_time = \\\"`date +'%d.%m.%Y %H:%M'`\\\"\\;" \
> $${PWD}/$$revtarget.target
DEFINES += DATE_TIME=\"$$quote($$system(date '+%d.%m.%Y\ %H:%M'))\"
}

revtarget.depends = $$SOURCES \
$$HEADERS \
$$FORMS

unix:!macx {
QMAKE_POST_LINK += $$sprintf($${QMAKE_MKDIR_CMD}, $$shell_path($${DESTDIR}/lib/)) $$escape_expand(\\n\\t)
}
Expand Down
1 change: 0 additions & 1 deletion src/latest_version.xml

This file was deleted.

5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ int main(int argc, char *argv[]) {
painter.drawText(
0, 0, 418, 130,
Qt::AlignRight | Qt::AlignBottom,
QString("%1.%2").arg(MAJOR_VERSION).arg(MINOR_VERSION)
);
QString(xstr(VERSION)));
DeinAlptraum marked this conversation as resolved.
Show resolved Hide resolved

painter.end();
QSplashScreen splash(canvas);
Expand Down Expand Up @@ -151,7 +150,7 @@ void initLanguage(QApplication &app, QTranslator &trContent, QTranslator &trQt,

monty->initMessages();

s.showMessage(QString(QObject::tr("%1.%2.%3 is loading...")).arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(PATCH_VERSION), Qt::AlignBottom | Qt::AlignRight, Qt::white);
s.showMessage(QString(QObject::tr("%1 is loading...")).arg(xstr(VERSION)), Qt::AlignBottom | Qt::AlignRight, Qt::white);

// message needs to be here because it can be translated only after installing the translator
if(!settingFound)
Expand Down
8 changes: 4 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef MAIN_H_
#define MAIN_H_

#define MAJOR_VERSION 0x0001
#define MINOR_VERSION 0x0009
#define PATCH_VERSION 0x0000

#define WIP_TEXT "" //" *work in progress* -> Please do not distribute."
//#define WIP_VERSION
//#define RC_VERSION

// Stringifiers needed to parse the VERSION preprocessor define as string
#define xstr(a) astr(a)
#define astr(a) #a

#endif /*MAIN_H_*/