Skip to content

Commit

Permalink
Record git sha in packages during continuous builds (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored May 27, 2024
1 parent 850b12f commit 1e7d81c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
cmake -S . -B ./build
-DCMAKE_BUILD_TYPE:STRING=Release
-DJSONSCHEMA_TESTS:BOOL=ON
-DJSONSCHEMA_CONTINUOUS:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON
- run: cmake --build ./build --config Release --parallel 4
Expand Down
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(cmake/CompilerOptions.cmake)

# Options
option(JSONSCHEMA_TESTS "Build the JSON Schema CLI tests" OFF)
option(JSONSCHEMA_CONTINUOUS "Perform a continuous JSON Schema CLI release" ON)

find_package(JSONToolkit REQUIRED)
add_subdirectory(src)
Expand All @@ -24,9 +25,31 @@ if(JSONSCHEMA_TESTS)
endif()

# Packaging
find_program(GIT_BIN NAMES git)
if(GIT_BIN AND JSONSCHEMA_CONTINUOUS)
execute_process(COMMAND "${GIT_BIN}" rev-parse --git-dir
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GIT_DIR)
endif()
if(GIT_BIN AND EXISTS "${GIT_DIR}")
execute_process(
COMMAND "${GIT_BIN}" rev-parse --short=8 HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_GIT_SHA
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
else()
set(PROJECT_GIT_SHA "unknown")
endif()

set(CPACK_GENERATOR ZIP)
string(TOLOWER ${CMAKE_SYSTEM_NAME} LOWER_SYSTEM_NAME)
set(PLATFORM_SUFFIX "${LOWER_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${PLATFORM_SUFFIX}")
if(JSONSCHEMA_CONTINUOUS)
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${PROJECT_GIT_SHA}-${PLATFORM_SUFFIX}")
else()
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${PLATFORM_SUFFIX}")
endif()
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ configure: .always
-DCMAKE_BUILD_TYPE:STRING=$(PRESET) \
-DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON \
-DJSONSCHEMA_TESTS:BOOL=ON \
-DJSONSCHEMA_CONTINUOUS:BOOL=ON \
-DBUILD_SHARED_LIBS:BOOL=$(SHARED)

compile: .always
Expand Down

0 comments on commit 1e7d81c

Please sign in to comment.