Skip to content

Commit

Permalink
cmake: optional use git if found get branch and commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clementperon committed Feb 10, 2024
1 parent 7d806e8 commit 34b2a42
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

# Checkout is performed out of the container and doesn't match our user
- name: Fix checkout ownership
run: chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE"

- name: Install dependencies
run: |
apk update && apk add cppcheck python3-dev
python3 -m pip install cmake-format
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: pre-commit/[email protected]

Expand All @@ -39,7 +42,7 @@ jobs:
git diff --exit-code
linux:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
container: seladb/${{ matrix.image }}
strategy:
matrix:
Expand Down Expand Up @@ -72,6 +75,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

# Checkout is performed out of the container and doesn't match our user
- name: Fix checkout ownership
run: chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE"

- name: Setup Intel Compiler variables
if: contains(matrix.image, 'icpx')
run: |
Expand Down Expand Up @@ -125,7 +132,7 @@ jobs:
verbose: true

dpdk:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
container: seladb/${{ matrix.image }}
strategy:
matrix:
Expand Down Expand Up @@ -174,7 +181,7 @@ jobs:
run: cd build_examples/tutorials_bin && ./Tutorial-HelloWorld

pfring:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
container: seladb/ubuntu2004-pfring
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
container: seladb/ubuntu2204
permissions:
security-events: write
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:

jobs:
linux:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
container: seladb/${{ matrix.image }}
strategy:
matrix:
Expand All @@ -35,6 +35,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

# Checkout is performed out of the container and doesn't match our user
- name: Fix checkout ownership
run: chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE"

- name: Setup Intel Compiler variables
if: contains(matrix.image, 'icpx')
run: |
Expand Down
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,22 @@ if(PCAPPP_USE_DPDK)
endif()

# Git Commit and Branch
add_compile_definitions(GIT_COMMIT="${GIT_HASH}")
add_compile_definitions(GIT_BRANCH="${GIT_BRANCH}")
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PCAPPP_GIT_COMMIT)
string(STRIP "${PCAPPP_GIT_COMMIT}" PCAPPP_GIT_COMMIT)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PCAPPP_GIT_BRANCH)
string(STRIP "${PCAPPP_GIT_BRANCH}" PCAPPP_GIT_BRANCH)
message(STATUS "Building from commit:${PCAPPP_GIT_COMMIT} on branch:${PCAPPP_GIT_BRANCH}")
add_compile_definitions(GIT_COMMIT="${PCAPPP_GIT_COMMIT}")
add_compile_definitions(GIT_BRANCH="${PCAPPP_GIT_BRANCH}")
endif()

if(PCAPPP_USE_PF_RING)
find_package(PF_RING)
Expand Down

0 comments on commit 34b2a42

Please sign in to comment.