Skip to content

Commit

Permalink
Version Number Based on git tag info
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Mar 18, 2022
1 parent 4cbc302 commit e181367
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 37 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ jobs:


steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: |
git tag -d continuous
export BRANCH=`git branch --show-current`
git merge --squash $BRANCH
git log --oneline
git describe
- name: Cache Qt
id: cache-qt
Expand Down Expand Up @@ -174,7 +182,7 @@ jobs:
tar -zcvf build/${{ matrix.config.releasePackage}} ${{matrix.config.packageName}}
- name: Deploy Pages
if: runner.os == 'Linux' && github.ref == 'refs/heads/master' && matrix.config.QT_VERSION == '5.15.2'
if: runner.os == 'Linux' && github.ref == 'refs --prune --tags/heads/master' && matrix.config.QT_VERSION == '5.15.2'
uses: JamesIves/github-pages-deploy-action@4.1.4
with:
branch: gh-pages
Expand Down Expand Up @@ -211,8 +219,10 @@ jobs:
}

steps:
- uses: actions/checkout@v2.1.0

- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch
- uses: uraimo/run-on-arch-action@v2.1.1
name: Build artifact
id: build
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release Builder
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v*'

jobs:
main_build:
Expand Down Expand Up @@ -62,7 +62,10 @@ jobs:


steps:
- uses: actions/checkout@v2.1.0
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch

- name: Cache Qt
id: cache-qt
Expand Down Expand Up @@ -169,8 +172,9 @@ jobs:
}

steps:
- uses: actions/checkout@v2.1.0

- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: uraimo/run-on-arch-action@v2.1.1
name: Build artifact
id: build
Expand Down
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.21)
cmake_policy(SET CMP0074 NEW)

project(ff7tk VERSION 0.81.00 DESCRIPTION "Work with Final Fantasy 7 game data")
#Version will be written by tag v1.2.2-4
project(ff7tk VERSION 0.81.0.0 DESCRIPTION "Work with Final Fantasy 7 game data")

#Prevent In-sourcebuild
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
Expand Down Expand Up @@ -42,13 +43,23 @@ IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
FIND_PACKAGE(Git)
IF(GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
COMMAND ${GIT_EXECUTABLE} describe --match v*
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE "GIT_VERSION"
OUTPUT_VARIABLE GITREV
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
MESSAGE( STATUS "Git Commit: ${GIT_VERSION}" )
add_definitions( -DGIT_VERSION="${GIT_VERSION}")
Message(STATUS "GITREV ${GITREV}")
string(REGEX MATCH [0-9]+ MAJOR ${GITREV})
string(REGEX MATCH \\.[0-9]+ MINOR ${GITREV})
string(REPLACE "." "" MINOR ${MINOR})
string(REGEX MATCH [0-9]+\- PATCH ${GITREV})
string(REPLACE "-" "" PATCH ${PATCH})
string(REGEX MATCH \-[0-9]+\- TWEAK ${GITREV})
string(REPLACE "-" "" TWEAK ${TWEAK})
set(CMAKE_PROJECT_VERSION_MAJOR ${MAJOR})
set(CMAKE_PROJECT_VERSION_MINOR ${MINOR})
set(CMAKE_PROJECT_VERSION_PATCH ${PATCH})
set(CMAKE_PROJECT_VERSION_TWEAK ${TWEAK})
ENDIF(GIT_FOUND)
ELSE()
ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
Expand Down
2 changes: 1 addition & 1 deletion demos/ff7tkQmlGallery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char *argv[])
return FF7Item::qmlSingletonRegister(engine, jsEngine);
});

QString versionString = QStringLiteral("%1-%2").arg(ff7tk_version().append(ff7tk_revision()), ff7tk_qt_version());
QString versionString = QStringLiteral("%1").arg(ff7tk_version());
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("ff7tkVersion", versionString);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
Expand Down
2 changes: 1 addition & 1 deletion demos/ff7tkWidgetGallery/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(QStringLiteral("ff7tkWidgetGallery-%1-%2").arg(ff7tk_version().append(ff7tk_revision()), ff7tk_qt_version()));
setWindowTitle(QStringLiteral("ff7tkWidgetGallery-%1").arg(ff7tk_version()));
hideAllBoxes();
QScreen *screen = QGuiApplication::screens().at(0);
screen->logicalDotsPerInchX();
Expand Down
6 changes: 5 additions & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ For QMake you can use the pkgconfig provided by the system
`PKGCONFIG += ff7tk`

## ff7tk version info
include the file ff7tkAbout.h and use the function(s) ff7tk_version(), ff7tk_revision() or ff7tk_qt_version()
ff7tk Versions are based on its git info. Failing this the project version is updated on every release.
include the file ff7tkAbout.h and use the function(s)
- ff7tk_version() To get version info in to form of Major.minor.patch.tweak (Qt<QtMajorVersion>)
-- If patch or rev are empty they are excluded from the version number
-- tweak is Number of commits since the last tag
### ff7tk version compatibility
ff7tk verisons with the same major and minor version are compatible. Building your project with an incompatible version can lead to API issues for this reason its HIGHLY recommend any CI jobs use a Release or specific COMMIT HASH when pulling ff7tk.

Expand Down
9 changes: 8 additions & 1 deletion packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ set(CPACK_PACKAGE_VENDOR "sithlord48")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/sithlord48/ff7tk")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${CMAKE_PROJECT_DESCRIPTION})
if (NOT CPACK_PACKAGE_VERSION )
set(CPACK_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR.${CMAKE_PROJECT_VERSION_MINOR})
if(NOT CMAKE_PROJECT_VERSION_PATCH EQUAL 0)
set(CPACK_PACKAGE_VERSION_PATCH ".${CMAKE_PROJECT_VERSION_PATCH}")
ENDIF()
if(NOT CMAKE_PROJECT_VERSION_TWEAK EQUAL 0)
set(CPACK_PACKAGE_VERSION_TWEAK ".${CMAKE_PROJECT_VERSION_TWEAK}")
ENDIF()
endif()
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Qt${QT_DEFAULT_MAJOR_VERSION})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING.TXT")
Expand Down
1 change: 0 additions & 1 deletion packaging/cpackOptions.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set(BASE_SOURCE_DIR @CMAKE_SOURCE_DIR@)
set(ZLIB_LIB @ZLIB_TARGET@)
set(TARGET_FILES @TARGET_FILES@)
set(PLATFORMDEPLOYQT @PLATFORMDEPLOYQT@)
set(GIT_VERSION @GIT_VERSION@)

#Get Target Info from project
set(RUNTIME_DEPENDS_PATH @RUNTIME_DEPENDS_PATH@)
Expand Down
26 changes: 7 additions & 19 deletions src/data/ff7tkAbout.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,12 @@
* @return: Version of ff7tk
*/
QString ff7tk_version() {
return QStringLiteral("@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@");
}

/**
* @brief Get the checked out revision of the ff7tk in use
* @return: Revision of ff7tk if build from checked out Git repo
*/
QString ff7tk_revision() {
QString revision = QStringLiteral("@GIT_VERSION@");
if(!QString("@GIT_VERSION@").isEmpty())
revision.prepend(QStringLiteral("."));
return revision;
}

/**
* @brief Get the major version of Qt that was used to build ff7tk
* @return: Qt5 or Qt6 depending on what library was used to build ff7tk
*/
QString ff7tk_qt_version() {
return QStringLiteral("Qt@QT_DEFAULT_MAJOR_VERSION@");
QString version = QStringLiteral("@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@");
if(@CMAKE_PROJECT_VERSION_PATCH@ > 0)
version.append(QStringLiteral(".@CMAKE_PROJECT_VERSION_PATCH@"));
if(@CMAKE_PROJECT_VERSION_TWEAK@ > 0)
version.append QStringLiteral("-@CMAKE_PROJECT_VERSION_TWEAK@");
version.append(QStringLiteral(" (Qt@QT_DEFAULT_MAJOR_VERSION@)"));
return version;
}

0 comments on commit e181367

Please sign in to comment.