diff --git a/.github/actions/configure/action.yaml b/.github/actions/configure/action.yaml new file mode 100644 index 00000000..d3de40d8 --- /dev/null +++ b/.github/actions/configure/action.yaml @@ -0,0 +1,8 @@ +name: Configure + +runs: + using: composite + steps: + - name: Configure + shell: bash + run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} -DBUILD_TESTS=ON -DPROJECT_VERSION=${{ env.PROJECT_VERSION }} diff --git a/.github/actions/set-environment-variables/action.yaml b/.github/actions/set-environment-variables/action.yaml index 55c54a6d..08fdce4f 100644 --- a/.github/actions/set-environment-variables/action.yaml +++ b/.github/actions/set-environment-variables/action.yaml @@ -16,9 +16,11 @@ runs: printf "CAPITALISED_BUILD_TYPE=%s\n" "${buildType}" >> $GITHUB_ENV printf "LOWERCASE_BUILD_TYPE=%s\n" "${buildType,,}" >> $GITHUB_ENV - newestTag="$(git describe --tags --abbrev=0)" - artifactVersionWithTimestamp="${newestTag}"-"$(date +%Y%m%d_%H%M%S)" - printf "GITHUB_OCI_REGISTRY_ARTIFACT_VERSION=%s\n" "${artifactVersionWithTimestamp}" >> $GITHUB_ENV + newestTag="$(git describe --tags --abbrev=0 --always)" + printf "PROJECT_VERSION=%s\n" "${newestTag}" >> $GITHUB_ENV + + newestTagWithTimestamp="${newestTag}"-"$(date +%Y%m%d_%H%M%S)" + printf "ARTIFACT_VERSION=%s\n" "${newestTagWithTimestamp}" >> $GITHUB_ENV printf "RELEASE_PATH=%s\n" "${{ github.workspace }}/build/Release" >> $GITHUB_ENV diff --git a/.github/workflows/build-and-test-debug.yaml b/.github/workflows/build-and-test-debug.yaml index a09f5e18..5c0e8bc7 100644 --- a/.github/workflows/build-and-test-debug.yaml +++ b/.github/workflows/build-and-test-debug.yaml @@ -31,8 +31,7 @@ jobs: uses: ./.github/actions/install-requirements - name: Configure - shell: bash - run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} -DBUILD_TESTS=ON + uses: ./.github/actions/configure - name: Build uses: ./.github/actions/build diff --git a/.github/workflows/build-test-and-publish-release.yaml b/.github/workflows/build-test-and-publish-release.yaml index 2637ba23..19956914 100644 --- a/.github/workflows/build-test-and-publish-release.yaml +++ b/.github/workflows/build-test-and-publish-release.yaml @@ -26,8 +26,7 @@ jobs: uses: ./.github/actions/install-requirements - name: Configure - shell: bash - run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} -DBUILD_TESTS=ON + uses: ./.github/actions/configure - name: Build uses: ./.github/actions/build @@ -53,7 +52,7 @@ jobs: - name: Zip artifact directory contents run: | cd ${{ env.ARTIFACT_PATH }} - zip -r ${{ env.GITHUB_OCI_REGISTRY_ARTIFACT_VERSION }}.zip . + zip -r ${{ env.ARTIFACT_VERSION }}.zip . - name: Login to GitHub OCI registry run: printf "%s" ${{ secrets.GITHUB_TOKEN }} | oras login ghcr.io -u ${{ github.actor }} --password-stdin @@ -61,4 +60,4 @@ jobs: - name: Publish zip to GitHub OCI registry run: | cd ${{ env.ARTIFACT_PATH }} - oras push ${{ env.GITHUB_OCI_REGISTRY_ADDRESS }}:${{ env.GITHUB_OCI_REGISTRY_ARTIFACT_VERSION }} ${{ env.GITHUB_OCI_REGISTRY_ARTIFACT_VERSION }}.zip + oras push ${{ env.GITHUB_OCI_REGISTRY_ADDRESS }}:${{ env.ARTIFACT_VERSION }} ${{ env.ARTIFACT_VERSION }}.zip diff --git a/CMakeLists.txt b/CMakeLists.txt index dbdd2422..fa1ac5e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,25 +35,17 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release") set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) endif() -find_package(Git REQUIRED) -execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 OUTPUT_VARIABLE ver -) +if("${PROJECT_VERSION}" STREQUAL "") + message(FATAL_ERROR "Project version has not been provided\n Please, provide project version using -DPROJECT_VERSION") +endif() -string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ ${ver}) +string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _ "${PROJECT_VERSION}") if(NOT CMAKE_MATCH_COUNT EQUAL 3) - message(FATAL_ERROR "Version parsing failed\n Got: ${ver}") + message(FATAL_ERROR "Incorrect project version number format: ${PROJECT_VERSION}. Please provide the project version number in the format major.minor.patch") endif() -set(EBPFDISCOVERY_VERSION_MAJOR ${CMAKE_MATCH_1}) -set(EBPFDISCOVERY_VERSION_MINOR ${CMAKE_MATCH_2}) -set(EBPFDISCOVERY_VERSION_PATCH ${CMAKE_MATCH_3}) -add_definitions(-DEBPFDISCOVERY_VERSION_MAJOR=${EBPFDISCOVERY_VERSION_MAJOR}) -add_definitions(-DEBPFDISCOVERY_VERSION_MINOR=${EBPFDISCOVERY_VERSION_MINOR}) -add_definitions(-DEBPFDISCOVERY_VERSION_PATCH=${EBPFDISCOVERY_VERSION_PATCH}) - project( - ${_project_name} VERSION "${EBPFDISCOVERY_VERSION_MAJOR}.${EBPFDISCOVERY_VERSION_MINOR}.${EBPFDISCOVERY_VERSION_PATCH}" LANGUAGES C CXX + ${_project_name} VERSION "${PROJECT_VERSION}" LANGUAGES C CXX ) set(BPF_C_FLAGS ${BPF_C_FLAGS} -DTARGET_BPF) diff --git a/README.md b/README.md index d27d87f0..8fa5370b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Build release: ``` conan install . --build=missing -s build_type=Release -cmake --preset conan-release -DBUILD_TESTS=OFF +cmake --preset conan-release -DBUILD_TESTS=OFF -DPROJECT_VERSION= cmake --build --preset conan-release ``` @@ -31,10 +31,12 @@ Build debug: ``` conan install . --build=missing -s build_type=Debug -cmake --preset conan-debug -DTHIRDPARTY_MAKE_JOBS_COUNT=$((`nproc` / 2)) -DBUILD_BPF_TESTS=On +cmake --preset conan-debug -DTHIRDPARTY_MAKE_JOBS_COUNT=$((`nproc` / 2)) -DBUILD_BPF_TESTS=ON -DPROJECT_VERSION= cmake --build --preset conan-debug ``` +`project version` must be provided in the format major.minor.patch e.g. 1.2.3 + ## Help & Support eBPF Discovery is an open source project. The features are fully supported by [Dynatrace](https://www.dynatrace.com). diff --git a/ebpfdiscoverysrv/CMakeLists.txt b/ebpfdiscoverysrv/CMakeLists.txt index 1c4a5b9b..37b5d55c 100644 --- a/ebpfdiscoverysrv/CMakeLists.txt +++ b/ebpfdiscoverysrv/CMakeLists.txt @@ -5,3 +5,4 @@ add_executable(${TARGET} ${SOURCES}) target_link_libraries(${TARGET} Boost::program_options) target_link_libraries(${TARGET} ebpfdiscovery) +target_compile_definitions(${TARGET} PUBLIC PROJECT_VERSION="${PROJECT_VERSION}") diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index cde77cc8..61e5e293 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -3,6 +3,7 @@ project(thirdparty) set(THIRDPARTY_MAKE_JOBS_COUNT "1" CACHE STRING "Number of jobs to use when compiling thirdparty submodules") include(ExternalProject) +find_package(Git REQUIRED) if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/bpftool/src/Makefile OR NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/bpftool/libbpf/src/Makefile) execute_process(