Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Change version retrieving #20

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/actions/configure/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
8 changes: 5 additions & 3 deletions .github/actions/set-environment-variables/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build-and-test-debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/build-test-and-publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,12 +52,12 @@ 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

- 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
20 changes: 6 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Project version parsing failed\n Got: ${PROJECT_VERSION}")
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)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<project version>
cmake --build --preset conan-release
```

Expand All @@ -31,7 +31,7 @@ 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=<project version>
cmake --build --preset conan-debug
```

Expand Down
1 change: 1 addition & 0 deletions ebpfdiscoverysrv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
1 change: 1 addition & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down