From b4af22cebc0033c1d70ecd696c9e7fced35dc659 Mon Sep 17 00:00:00 2001 From: Jean Christophe Roques Date: Thu, 26 Sep 2024 15:41:54 +0200 Subject: [PATCH] add installer to CMakeLists.txt --- .github/scripts/windows-agent-compile.ps1 | 3 +- .github/workflows/windows-agent.yml | 35 +++++++------- agent/CMakeLists.txt | 3 ++ agent/installer/CMakeLists.txt | 46 +++++++++++++++++-- agent/installer/centreon-monitoring-agent.nsi | 5 +- agent/installer/version.nsi.in | 3 +- 6 files changed, 67 insertions(+), 28 deletions(-) diff --git a/.github/scripts/windows-agent-compile.ps1 b/.github/scripts/windows-agent-compile.ps1 index 5326996f56..ed44fd015c 100644 --- a/.github/scripts/windows-agent-compile.ps1 +++ b/.github/scripts/windows-agent-compile.ps1 @@ -72,7 +72,8 @@ else { cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=On -DWINDOWS=On -DBUILD_FROM_CACHE=On -S. -DVCPKG_CRT_LINKAGE=dynamic -DBUILD_SHARED_LIBS=OFF -Bbuild_windows -Write-Host "build agent and tests" + +Write-Host "------------- build agent and installer ---------------" cmake --build build_windows --config Release diff --git a/.github/workflows/windows-agent.yml b/.github/workflows/windows-agent.yml index 3c7f22eba4..2c6d59ca7f 100644 --- a/.github/workflows/windows-agent.yml +++ b/.github/workflows/windows-agent.yml @@ -6,6 +6,18 @@ concurrency: on: workflow_dispatch: + inputs: + installer_in_artifact: + description: 'Save installer and binary in artifacts' + required: true + default: false + type: boolean + unit_test: + description: 'run unit tests' + required: true + default: true + type: boolean + pull_request: paths: - agent/** @@ -52,36 +64,21 @@ jobs: shell: powershell - name: Common test + if: inputs.unit_test == true run: | cd build_windows tests/ut_common - name: Agent test + if: inputs.unit_test == true run: | cd build_windows tests/ut_agent - - name: Zip agent - run: | - $files_to_compress = "agent\conf\centagent.reg", "build_windows\agent\Release\centagent.exe" - Compress-Archive -Path $files_to_compress -DestinationPath centreon-monitoring-agent.zip - - - name: Save agent package in cache - uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - path: centreon-monitoring-agent.zip - key: ${{ github.run_id }}-${{ github.sha }}-CMA-${{ github.head_ref || github.ref_name }} - enableCrossOsArchive: ${{ true }} - - name: Upload package artifacts - if: | - github.event_name != 'workflow_dispatch' && - contains(fromJson('["stable"]'), needs.get-version.outputs.stability) && - ! cancelled() && - ! contains(needs.*.result, 'failure') && - ! contains(needs.*.result, 'cancelled') + if: inputs.installer_in_artifact == true uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 with: name: packages-centreon-monitoring-agent-windows - path: centreon-monitoring-agent.zip + path: agent\installer\centreon-monitoring-agent.exe retention-days: 1 diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index 4c825f8f20..fc9a0138a6 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -181,6 +181,9 @@ else() absl::any absl::log absl::base absl::bits Boost::program_options fmt::fmt) + + add_subdirectory(installer) + endif() diff --git a/agent/installer/CMakeLists.txt b/agent/installer/CMakeLists.txt index 637387d671..7f9cd76943 100644 --- a/agent/installer/CMakeLists.txt +++ b/agent/installer/CMakeLists.txt @@ -16,9 +16,49 @@ # For more information : contact@centreon.com # +project("Centreon agent Installer") + + # Set directories. -set(SRC_DIR "${PROJECT_SOURCE_DIR}/installer") +set(CENTAGENT_PATH_OUTPUT_DIR ${Centreon\ agent_BINARY_DIR}) + +if( ${CMAKE_GENERATOR} MATCHES "Visual Studio.*" ) + set(CENTAGENT_PATH "${Centreon\ agent_BINARY_DIR}/${CMAKE_BUILD_TYPE}/centagent.exe") +else() + set(CENTAGENT_PATH "${Centreon\ agent_BINARY_DIR}/centagent.exe") +endif() + +string(REPLACE "/" "\\" CENTAGENT_PATH "${CENTAGENT_PATH}") + +#uncomment if makensis is not in the path +set(MKNSIS "C:/Program Files (x86)/NSIS/Bin/makensis.exe") + +#set(MKNSIS "makensis.exe") # Configure files. -configure_file("${SRC_DIR}/version.nsi.in" - "${SRC_DIR}/version.nsi") +configure_file("${PROJECT_SOURCE_DIR}/version.nsi.in" "${PROJECT_SOURCE_DIR}/version.nsi") + +file(GLOB COMMON_INSTALLERS_FILES "${PROJECT_SOURCE_DIR}/version.nsi" "${PROJECT_SOURCE_DIR}/dlg_helper.nsi" "${PROJECT_SOURCE_DIR}/resources/*") + +message(NOTICE "---------------- Generate installer in ${PROJECT_SOURCE_DIR} ---------------") + +# modify binary called from the application manager +# embedded in installer +add_custom_command( + DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.nsi" ${COMMON_INSTALLERS_FILES} ${CENTREON_AGENT} + COMMENT "--------- Generating cma configuration modifier --------" + OUTPUT "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.exe" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMAND ${MKNSIS} "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.nsi") + + +#final installer +add_custom_command( + DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.nsi" "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent-modify.exe" ${COMMON_INSTALLERS_FILES} + COMMENT "--------- Generating cma configuration installer --------" + OUTPUT "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.exe" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + COMMAND ${MKNSIS} "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.nsi") + +add_custom_target("centreon-monitoring-agent-installer" ALL DEPENDS "${PROJECT_SOURCE_DIR}/centreon-monitoring-agent.exe") + diff --git a/agent/installer/centreon-monitoring-agent.nsi b/agent/installer/centreon-monitoring-agent.nsi index c2883a4bba..ea09507cde 100644 --- a/agent/installer/centreon-monitoring-agent.nsi +++ b/agent/installer/centreon-monitoring-agent.nsi @@ -174,11 +174,8 @@ Section "Centreon Monitoring Agent" CMAInstSection ; even if service is stopped, process can be stopping so we wait a little more Sleep 500 - ;file "..\..\build_windows\agent\Release\centagent.exe" - file "..\..\build_windows\agent\centagent.exe" + file ${CENTAGENT_PATH} file "centreon-monitoring-agent-modify.exe" - ;file "..\..\build_msdev\agent\centagent.exe" - ;file "..\..\build_msdev\agent\*.dll" writeUninstaller "$INSTDIR\uninstall.exe" diff --git a/agent/installer/version.nsi.in b/agent/installer/version.nsi.in index 0506e244bb..7ccd0fc052 100644 --- a/agent/installer/version.nsi.in +++ b/agent/installer/version.nsi.in @@ -18,4 +18,5 @@ !define VERSIONMAJOR ${COLLECT_MAJOR} !define VERSIONMINOR ${COLLECT_MINOR} -!define VERSIONBUILD ${COLLECT_PATCH} \ No newline at end of file +!define VERSIONBUILD ${COLLECT_PATCH} +!define CENTAGENT_PATH "${CENTAGENT_PATH}" \ No newline at end of file