Skip to content

Commit

Permalink
fix(ci): fallback to local values for BUILD_REF when not built in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Jan 9, 2023
1 parent d7b7ccc commit b0e8b9c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(NODABLE_CORE_INSTALL_DESTINATION libs) # relative to CMAKE_INSTALL_PREFIX
# include *.cmake scripts
include( cmake/log.cmake )
include( cmake/compiler-config.cmake )
include( cmake/set-build-ref-variable.cmake )

#include other CMakeLists.txt
add_subdirectory(libs) # libraries (SDL, lodepng, Dear ImGui, etc.)
Expand Down
43 changes: 43 additions & 0 deletions cmake/set-build-ref-variable.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
include_guard(GLOBAL)
nodable_log_title_header()

# Get the git short hash
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the git hash
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the git last tag hash
execute_process(
COMMAND git rev-list --tags --max-count=1
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_LAST_TAG_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the git last tag
execute_process(
COMMAND git describe --tags ${GIT_LAST_TAG_HASH}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_LAST_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# define the version number
if(GITHUB_REF_NAME)
set(BUILD_REF "${GITHUB_REF_NAME} ${GITHUB_SHA}")
elseif(GIT_LAST_TAG_HASH EQUAL GIT_HASH)
set(BUILD_REF "${GIT_LAST_TAG} ${GIT_HASH} (local build)")
else()
set(BUILD_REF "v${PROJECT_VERSION}.x (local build)")
endif()
4 changes: 2 additions & 2 deletions src/app/include/nodable/app/build_info.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
namespace ndbl::BuildInfo
{
static const char* assets_dir = "@NODABLE_APP_ASSETS_DIR@";
static const char* version = "@PROJECT_NAME@ @GITHUB_REF_NAME@ - @GITHUB_SHA@";
static const char* version_extended = "@PROJECT_NAME@ @GITHUB_REF_NAME@ - @GITHUB_SHA@ - Built " __DATE__ " at " __TIME__;
static const char* version = "@PROJECT_NAME@ @BUILD_REF@";
static const char* version_extended = "@PROJECT_NAME@ @BUILD_REF@ - Built " __DATE__ " at " __TIME__;
}

0 comments on commit b0e8b9c

Please sign in to comment.