From e21ec058b2b67be24f7b1c5670e040b85a304bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Pra=C5=BAmo?= Date: Mon, 9 Feb 2026 00:08:24 +0100 Subject: [PATCH] Add hash versioning to CI --- .github/workflows/cmakeAndroid.yml | 8 +++++++- .github/workflows/cmakeLinux.yml | 25 ++++++++++++++++++++++- .github/workflows/cmakeMacOs.yml | 32 ++++++++++++++++++++++++++---- .github/workflows/cmakeWin64.yml | 25 ++++++++++++++++++++++- CMakeLists.txt | 31 +++++++++++++++++++++++++++++ src/config.h | 11 ++++++++-- 6 files changed, 123 insertions(+), 9 deletions(-) diff --git a/.github/workflows/cmakeAndroid.yml b/.github/workflows/cmakeAndroid.yml index 6d405751a..ef3900c5e 100644 --- a/.github/workflows/cmakeAndroid.yml +++ b/.github/workflows/cmakeAndroid.yml @@ -29,9 +29,15 @@ jobs: sudo apt-get update sudo apt-get install g++ libcurl4-gnutls-dev libfreetype6-dev libgif-dev libjpeg-dev libpixman-1-dev libpng-dev libsdl2-dev libsdl2-image-dev libtinyxml2-dev libx11-dev libxcursor-dev ninja-build zlib1g-dev libarchive-dev pip install cmake + SHORT_HASH=$(git rev-parse --short HEAD) + sed -i "s/\"local build\"/\"$SHORT_HASH\"/g" src/config.h mkdir build cd build - cmake -G Ninja -DGEN_ONLY=ON .. + if git describe --exact-match --tags 2>/dev/null; then + cmake -G Ninja -DGEN_ONLY=ON -DRELEASE_TAG=ON .. + else + cmake -G Ninja -DGEN_ONLY=ON .. + fi ninja cd .. - name: Setup Submodule diff --git a/.github/workflows/cmakeLinux.yml b/.github/workflows/cmakeLinux.yml index 3a3bd912b..e2058fc08 100644 --- a/.github/workflows/cmakeLinux.yml +++ b/.github/workflows/cmakeLinux.yml @@ -32,8 +32,31 @@ jobs: run: git submodule update --init --recursive - name: mkdir run: mkdir build + - name: check for git tag + id: check_tag + run: | + if git describe --exact-match --tags 2>/dev/null; then + echo "has_tag=true" >> $GITHUB_OUTPUT + else + echo "has_tag=false" >> $GITHUB_OUTPUT + fi + - name: Get short commit hash + id: commit + run: | + SHORT_HASH=$(git rev-parse --short HEAD) + echo "short_hash=$SHORT_HASH" >> $GITHUB_OUTPUT + - name: Update config.h with commit hash + run: | + sed -i 's/"local build"/"${{ steps.commit.outputs.short_hash }}"/g' src/config.h - name: cmake - run: cd build && cmake -G Ninja -DCMAKE_BUILD_TYPE=Release .. && ninja besprited + run: | + cd build + if [ "${{ steps.check_tag.outputs.has_tag }}" = "true" ]; then + cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DRELEASE_TAG=ON .. + else + cmake -G Ninja -DCMAKE_BUILD_TYPE=Release .. + fi + ninja besprited - name: appimage run: | cd build/bin diff --git a/.github/workflows/cmakeMacOs.yml b/.github/workflows/cmakeMacOs.yml index 82f7413a2..7dbe20dcc 100644 --- a/.github/workflows/cmakeMacOs.yml +++ b/.github/workflows/cmakeMacOs.yml @@ -41,12 +41,36 @@ jobs: - name: Download & Lint Info.plist run: | plutil desktop/Info.plist + - name: Check for git tag + id: check_tag + run: | + if git describe --exact-match --tags 2>/dev/null; then + echo "has_tag=true" >> $GITHUB_OUTPUT + else + echo "has_tag=false" >> $GITHUB_OUTPUT + fi + - name: Get short commit hash + id: commit + run: | + SHORT_HASH=$(git rev-parse --short HEAD) + echo "short_hash=$SHORT_HASH" >> $GITHUB_OUTPUT + - name: Update config.h with commit hash + run: | + sed -i '' 's/"local build"/"${{ steps.commit.outputs.short_hash }}"/g' src/config.h - name: Generate Makefiles run: | - cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ - -DUSE_V8_SANDBOX=ON \ - -DCMAKE_OSX_ARCHITECTURES=arm64 \ - -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk + if [ "${{ steps.check_tag.outputs.has_tag }}" = "true" ]; then + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DUSE_V8_SANDBOX=ON \ + -DRELEASE_TAG=ON \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk + else + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DUSE_V8_SANDBOX=ON \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk + fi - name: Build run: | cmake --build build/ --parallel 3 diff --git a/.github/workflows/cmakeWin64.yml b/.github/workflows/cmakeWin64.yml index 505823567..129ac179f 100644 --- a/.github/workflows/cmakeWin64.yml +++ b/.github/workflows/cmakeWin64.yml @@ -39,11 +39,34 @@ jobs: - uses: actions/checkout@v3 with: submodules: 'true' + - name: Check for git tag + id: check_tag + shell: bash + run: | + if git describe --exact-match --tags 2>/dev/null; then + echo "has_tag=true" >> $GITHUB_OUTPUT + else + echo "has_tag=false" >> $GITHUB_OUTPUT + fi + - name: Get short commit hash + id: commit + shell: bash + run: | + SHORT_HASH=$(git rev-parse --short HEAD) + echo "short_hash=$SHORT_HASH" >> $GITHUB_OUTPUT + - name: Update config.h with commit hash + shell: bash + run: | + sed -i 's/#define COMMIT "local build"/#define COMMIT "${{ steps.commit.outputs.short_hash }}"/g' src/config.h - shell: msys2 {0} run: | mkdir build cd build - cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_V8_SANDBOX=ON .. + if [ "${{ steps.check_tag.outputs.has_tag }}" = "true" ]; then + cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_V8_SANDBOX=ON -DRELEASE_TAG=ON .. + else + cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DUSE_V8_SANDBOX=ON .. + fi make -j 4 cd .. rm build/bin/gen.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eab987d5..46fdc0c61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,37 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Put libraries into "lib". set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) +###################################################################### +# Check if current commit has a git tag (for release builds) + +option(RELEASE_TAG "Mark as release build (set VERSION to stable)" off) + +if(NOT RELEASE_TAG) + # Try to detect if current commit has a tag + find_package(Git QUIET) + if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG + RESULT_VARIABLE GIT_TAG_RESULT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(GIT_TAG_RESULT EQUAL 0 AND GIT_TAG) + message(STATUS "Git tag found: ${GIT_TAG}") + set(RELEASE_TAG ON CACHE BOOL "Mark as release build (set VERSION to stable)" FORCE) + endif() + endif() +endif() + +if(RELEASE_TAG) + message(STATUS "Building as RELEASE version") + add_definitions(-DRELEASE_TAG) +else() + message(STATUS "Building as DEVELOPMENT version") +endif() + ###################################################################### # Common definitions to compile all sources (app code and third party) diff --git a/src/config.h b/src/config.h index c5d861466..ef1c2fd4e 100644 --- a/src/config.h +++ b/src/config.h @@ -24,13 +24,20 @@ // General information #define PACKAGE "Besprited" -#define VERSION "1.0-dev" +#define COMMIT "local build" +#ifndef RELEASE_TAG + #define VERSION "1.0-dev (" COMMIT ")" +#else + #define VERSION "1.0" +#endif #define PACKAGE_AND_VERSION PACKAGE " " VERSION #define WEBSITE "https://github.com/Veritaware/Besprited/" #define WEBSITE_DOWNLOAD WEBSITE "releases/" #define WEBSITE_CONTRIBUTORS WEBSITE "graphs/contributors/" -#define COPYRIGHT "Copyright (C) 2001-2016 David Capello, 2016-2025 LibreSprite contributors, 2026 Veritaware" +#define COPYRIGHT "Copyright © 2001-2016 David Capello, "\ + "2016-2026 LibreSprite contributors, "\ + "2026 Veritaware" #include "base/base.h" #include "base/debug.h"