Skip to content

Commit e889540

Browse files
ci:Python script for executable logic
- Create python script - Integrate with GitHub Actions Signed-off-by: Shamitha Shashidhara <[email protected]>
1 parent ab0d433 commit e889540

21 files changed

+350
-321
lines changed

.bash_history

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
python3 .ci/format.py
2+
python3 .ci/format.py
3+
python3 .ci/format.py
4+
clear
5+
python3 .ci/format.py
6+
exit
7+
python3 .ci/build.py "posix" "gcc" "14"
8+
ln --symbolic cmake-build-posix-gcc cmake-build-posix
9+
python3 .ci/pytest.py

.ci/build.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import shutil
2+
from pathlib import Path
3+
import subprocess
4+
import sys
5+
import os
6+
7+
def get_full_command_path(command):
8+
if (cmd := shutil.which(command)) is None:
9+
print(f"ERROR: Compiler command {command} not found!")
10+
sys.exit(1)
11+
return cmd
12+
13+
def get_environment_variables(platform, compiler):
14+
env = dict(os.environ)
15+
if platform == "s32k148" and compiler == "gcc":
16+
env["CC"] = get_full_command_path("arm-none-eabi-gcc")
17+
env["CXX"] = get_full_command_path("arm-none-eabi-gcc")
18+
elif platform == "posix" and compiler == "clang":
19+
env["CC"] = get_full_command_path("clang")
20+
env["CXX"] = get_full_command_path("clang++")
21+
elif platform == "s32k148" and compiler == "clang":
22+
env["CC"] = get_full_command_path("/usr/bin/llvm-arm/bin/clang")
23+
env["CXX"] = get_full_command_path("/usr/bin/llvm-arm/bin/clang++")
24+
elif platform == "posix" and compiler == "gcc":
25+
env["CC"] = get_full_command_path("gcc")
26+
env["CXX"] = get_full_command_path("gcc")
27+
return env
28+
29+
def configure_and_build(platform, compiler, cpp_standard):
30+
build_dir = Path(f"cmake-build-{platform}-{compiler}")
31+
if build_dir.exists():
32+
shutil.rmtree(build_dir)
33+
34+
cmake_command = [
35+
"cmake",
36+
"-B", build_dir,
37+
"-S", "executables/referenceApp",
38+
f"-DCMAKE_CXX_STANDARD={cpp_standard}",
39+
f"-DBUILD_TARGET_PLATFORM={'POSIX' if platform == 'posix' else 'S32K148EVB'}",
40+
f"-DCMAKE_TOOLCHAIN_FILE={'../../admin/cmake/ArmNoneEabi-' + compiler + '.cmake' if platform == 's32k148' else ''}"
41+
]
42+
subprocess.run(cmake_command, check=True, env=get_environment_variables(platform, compiler))
43+
subprocess.run(["cmake", "--build", build_dir, "--target", "app.referenceApp", "-j"], check=True, env=get_environment_variables(platform, compiler))
44+
45+
def main():
46+
if len(sys.argv) != 4:
47+
print("ERROR: Usage: build.py <platform> <compiler> <cpp_standard>")
48+
sys.exit(1)
49+
50+
platform = sys.argv[1]
51+
compiler = sys.argv[2]
52+
cpp_standard = sys.argv[3]
53+
54+
configure_and_build(platform, compiler, cpp_standard)
55+
56+
if __name__ == "__main__":
57+
main()

.ci/build_matrix.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import subprocess
2+
3+
platforms = ["posix", "s32k148"]
4+
compilers = ["clang", "gcc"]
5+
cpp_standards = ["14", "17", "20", "23"]
6+
7+
def main():
8+
for platform in platforms:
9+
for compiler in compilers:
10+
for cpp_standard in cpp_standards:
11+
print(f"Running build for platform={platform}, compiler={compiler}, cpp_standard={cpp_standard}")
12+
subprocess.run(
13+
["python3", ".ci/build.py", platform, compiler, str(cpp_standard)],
14+
check=True
15+
)
16+
print("All combinations have been processed.")
17+
18+
if __name__ == "__main__":
19+
main()

.ci/doxygen-docs.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import subprocess
2+
import os
3+
import shutil
4+
from pathlib import Path
5+
6+
def clean_build():
7+
build_dir = Path("doc/doxygenOut")
8+
if build_dir.exists():
9+
shutil.rmtree(build_dir)
10+
file_path_doc_coverage = Path("doc/doc-coverage.info")
11+
if os.path.exists(file_path_doc_coverage):
12+
os.remove(file_path_doc_coverage)
13+
file_path_warning = Path("doc/DoxygenWarningLog.txt")
14+
if os.path.exists(file_path_warning):
15+
os.remove(file_path_warning)
16+
17+
def run_doxygen():
18+
os.chdir("./doc")
19+
subprocess.run(["doxygen", "Doxyfile"], check=True)
20+
21+
def print_doxygen_warning_log():
22+
with open("DoxygenWarningLog.txt", "r") as file:
23+
print(file.read())
24+
25+
def run_coverxygen():
26+
subprocess.run(["python3", "-m", "coverxygen", "--format", "summary", "--xml-dir", "doxygenOut/xml/", "--src-dir", "..", "--output", "doc-coverage.info"], check=True)
27+
28+
def print_doc_coverage():
29+
with open("doc-coverage.info", "r") as file:
30+
print(file.read())
31+
32+
if __name__ == "__main__":
33+
clean_build()
34+
run_doxygen()
35+
print_doxygen_warning_log()
36+
run_coverxygen()
37+
print_doc_coverage()

.ci/format.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import subprocess
2+
3+
def check_code_format():
4+
subprocess.run(["treefmt"], check=True)
5+
subprocess.run(["git", "diff", "--exit-code"], check=True)
6+
7+
if __name__ == "__main__":
8+
check_code_format()

.ci/pytest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import subprocess
2+
import os
3+
4+
def run_pytest():
5+
os.chdir("./test/pyTest")
6+
subprocess.run(['pytest', '--target=posix'], check=True)
7+
8+
if __name__ == "__main__":
9+
run_pytest()

.ci/sphinx-docs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import subprocess
3+
import shutil
4+
from pathlib import Path
5+
6+
def build_sphinx_docs():
7+
build_dir = Path("doc/build")
8+
if build_dir.exists():
9+
shutil.rmtree(build_dir)
10+
os.chdir("./doc")
11+
subprocess.run(["make", "html", "OFFICIAL_BUILD=1"], check=True)
12+
13+
if __name__ == "__main__":
14+
build_sphinx_docs()

.ci/unit-test-build.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import subprocess
2+
from pathlib import Path
3+
import shutil
4+
5+
def configure_cmake(build_type):
6+
7+
unit_tests_build_dir = Path("cmake-build-unit-tests")
8+
if unit_tests_build_dir.exists():
9+
shutil.rmtree(unit_tests_build_dir)
10+
11+
subprocess.run([
12+
"cmake", "-B", "cmake-build-unit-tests", "-S", "executables/unitTest",
13+
"-DBUILD_UNIT_TESTS=ON",
14+
f"-DCMAKE_BUILD_TYPE={build_type}",
15+
"-DCMAKE_C_COMPILER_LAUNCHER=sccache",
16+
"-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
17+
], check=True)
18+
19+
def build_with_cmake():
20+
subprocess.run(["cmake", "--build", "cmake-build-unit-tests", "-j4"], check=True)
21+
22+
def run_tests():
23+
subprocess.run(["ctest", "--test-dir", "cmake-build-unit-tests", "-j4"], check=True)
24+
25+
if __name__ == "__main__":
26+
configure_cmake("Debug")
27+
build_with_cmake()
28+
run_tests()

.github/workflows/build.yml

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,30 @@ jobs:
66
run-command:
77
runs-on: ubuntu-latest
88
strategy:
9-
matrix:
9+
matrix:
1010
platform: [posix, s32k148]
1111
compiler: [clang, gcc]
1212
cpp-standard: [14, 17, 20, 23]
1313

1414
steps:
1515
- name: Checkout repository
1616
uses: actions/checkout@v4
17+
1718
- name: Cache CMake files
1819
id: cache-cmake
19-
uses: actions/cache@v4
20+
uses: actions/cache@v3
2021
with:
2122
path: cmake-build-${{ matrix.platform }}-${{ matrix.compiler }}
2223
key: ${{ runner.os }}-cmake-${{ matrix.platform }}-${{ matrix.compiler }}-${{ matrix.cpp-standard }}-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.cmake', '**/*.txt', '**/*.c', '**/*.s') }}
2324
restore-keys: |
2425
${{ runner.os }}-cmake-${{ matrix.platform }}-${{ matrix.compiler }}-${{ matrix.cpp-standard }}-
2526
26-
- name: Set up CMake
27-
uses: jwlawson/actions-setup-cmake@v2
28-
with:
29-
cmake-version: '3.22.x'
30-
31-
- name: Install ARM GCC
32-
if: ${{ matrix.platform == 's32k148' && matrix.compiler == 'gcc' }}
33-
uses: carlosperate/arm-none-eabi-gcc-action@v1
34-
with:
35-
release: '10.3-2021.10'
36-
37-
- name: Install POSIX LLVM
38-
if: ${{ matrix.platform == 'posix' && matrix.compiler == 'clang' }}
39-
uses: KyleMayes/install-llvm-action@v2
40-
with:
41-
version: "17"
42-
env: true
43-
44-
- name: Install ARM LLVM
45-
if: ${{ matrix.platform == 's32k148' && matrix.compiler == 'clang' }}
46-
uses: stellar-aria/[email protected]
47-
with:
48-
release: "19.1.1"
49-
50-
- name: Set environment variables for ARM LLVM
51-
if: ${{ matrix.platform == 's32k148' && matrix.compiler == 'clang' }}
52-
run: |
53-
echo "CC=$(which clang)" >> "${GITHUB_ENV}"
54-
echo "CXX=$(which clang++)" >> "${GITHUB_ENV}"
55-
56-
- name: Configure CMake for ${{ matrix.platform }} with ${{ matrix.compiler }}
27+
- name: Build the docker image
5728
if: steps.cache-cmake.outputs.cache-hit != 'true'
5829
run: |
59-
rm -rf cmake-build-${{ matrix.platform }}-${{ matrix.compiler }}
60-
cmake \
61-
-B cmake-build-${{ matrix.platform }}-${{ matrix.compiler }} \
62-
-S executables/referenceApp \
63-
-DCMAKE_CXX_STANDARD=${{ matrix.cpp-standard }} \
64-
-DBUILD_TARGET_PLATFORM=${{ matrix.platform == 'posix' && 'POSIX' || 'S32K148EVB' }} \
65-
-DCMAKE_TOOLCHAIN_FILE=${{ matrix.platform == 's32k148' && format('../../admin/cmake/ArmNoneEabi-{0}.cmake', matrix.compiler) || '' }}
30+
docker build --build-arg user_id=$(id -u) -f docker/Dockerfile.dev -t dev .
6631
67-
- name: Build ${{ matrix.platform }} with ${{ matrix.compiler }}
32+
- name: Run the build.py inside the docker container
6833
if: steps.cache-cmake.outputs.cache-hit != 'true'
69-
run: cmake --build cmake-build-${{ matrix.platform }}-${{ matrix.compiler }} --target app.referenceApp -j
34+
run: |
35+
docker run --rm -v "$PWD:/home/jenkins" -w /home/jenkins --user $(id -u):4996 dev python3 .ci/build.py "${{ matrix.platform }}" "${{ matrix.compiler }}" "${{ matrix.cpp-standard }}"

.github/workflows/code-coverage.yml

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Code Coverage
22

3-
on: [workflow_call, pull_request]
3+
on: [workflow_call, push ,pull_request]
44

55
jobs:
66
build:
@@ -10,87 +10,64 @@ jobs:
1010

1111
env:
1212
BUILD_TYPE: Debug
13-
SCCACHE_GHA_ENABLED: "true"
1413

1514
steps:
1615
- name: Checkout code
1716
uses: actions/checkout@v4
1817

19-
- name: Install GCC 11.4.0 and LCOV
20-
run: |
21-
sudo apt-get update
22-
sudo apt-get install -y gcc-11 g++-11 lcov wget zip
23-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
24-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
25-
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-11 100
26-
27-
- name: Set up sccache
28-
uses: mozilla-actions/[email protected]
29-
with:
30-
version: "v0.10.0"
31-
32-
- name: Set up CMake
33-
uses: jwlawson/actions-setup-cmake@v2
34-
with:
35-
cmake-version: '3.22.x'
36-
3718
- name: Cache CMake files
3819
id: cache-build
3920
uses: actions/cache@v3
4021
with:
4122
path: cmake-build-unit-tests
4223
key: ${{ runner.os }}-cmake-build-unit-tests-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.cmake', '**/*.txt', '**/*.c', '**/*.s') }}
4324

44-
- name: Configure with cmake
45-
if: steps.cache-build.outputs.cache-hit != 'true'
46-
run: |
47-
rm -rf cmake-build-unit-tests
48-
cmake -B cmake-build-unit-tests -S executables/unitTest \
49-
-DBUILD_UNIT_TESTS=ON \
50-
-DCMAKE_BUILD_TYPE=${{ github.event.inputs.BUILD_TYPE }}\
51-
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
52-
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
53-
54-
- name: Build with cmake
55-
if: steps.cache-build.outputs.cache-hit != 'true'
56-
run: cmake --build cmake-build-unit-tests -j4
57-
58-
- name: Run tests
59-
if: steps.cache-build.outputs.cache-hit != 'true'
60-
run: ctest --test-dir cmake-build-unit-tests -j4
61-
62-
- name: Capture code coverage
63-
if: steps.cache-build.outputs.cache-hit != 'true'
64-
run: lcov --no-external --capture --directory . --output-file cmake-build-unit-tests/coverage_unfiltered.info
65-
66-
- name: Filter out 3rd party and mock files
67-
if: steps.cache-build.outputs.cache-hit != 'true'
68-
run: lcov --remove cmake-build-unit-tests/coverage_unfiltered.info '*libs/3rdparty/googletest/*' '*/mock/*' '*/gmock/*' '*/gtest/*' '*/test/*' --output-file cmake-build-unit-tests/coverage.info
69-
70-
- name: Generate HTML coverage report
71-
run: |
72-
chmod 744 cmake-build-unit-tests/coverage.info
73-
genhtml cmake-build-unit-tests/coverage.info --output-directory cmake-build-unit-tests/coverage --ignore-errors source
25+
- name: Cache CMake files
26+
id: sccache-build
27+
uses: actions/cache@v3
28+
with:
29+
path: /.sccache
30+
key: ${{ runner.os }}-sccache
7431

75-
- name: Zip coverage html
32+
- name: Build the docker image
7633
run: |
77-
mv cmake-build-unit-tests/coverage code_coverage
78-
zip -r code_coverage.zip code_coverage
34+
docker build --build-arg user_id=$(id -u) -f docker/Dockerfile.dev -t dev .
7935
80-
- name: Badges
36+
- name: Run the unit-test-build.py inside the docker container
8137
run: |
82-
LinePercentage=$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'lines' | awk '{print $2}') &&
83-
echo "Line Percentage: $LinePercentage" &&
84-
wget "https://img.shields.io/badge/coverage-${LinePercentage}25-brightgreen.svg" -O line_coverage_badge.svg &&
85-
86-
FunctionPercentage=$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'functions' | awk '{print $2}') &&
87-
echo "Function Percentage: $FunctionPercentage" &&
88-
wget "https://img.shields.io/badge/coverage-${FunctionPercentage}25-brightgreen.svg" -O function_coverage_badge.svg &&
38+
docker run --rm -v "$PWD:/home/jenkins" -v "/.sccache:/root/.cache/sccache" -w /home/jenkins --user 0 dev bash -c"
39+
python3 .ci/unit-test-build.py &&
40+
lcov --no-external --capture --directory . \
41+
--output-file cmake-build-unit-tests/coverage_unfiltered.info &&
42+
43+
# Filter out 3rd party and mock files
44+
lcov --remove cmake-build-unit-tests/coverage_unfiltered.info \
45+
'*libs/3rdparty/googletest/*' \
46+
'*/mock/*' \
47+
'*/gmock/*' \
48+
'*/gtest/*' \
49+
'*/test/*' \
50+
--output-file cmake-build-unit-tests/coverage.info &&
51+
52+
# Generate HTML coverage report
53+
genhtml cmake-build-unit-tests/coverage.info \
54+
--output-directory cmake-build-unit-tests/coverage &&
55+
56+
# Zip the coverage report
57+
mv cmake-build-unit-tests/coverage code_coverage &&
58+
zip -r code_coverage.zip code_coverage
8959
60+
LinePercentage=\$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'lines' | awk '{print \$2}') &&
61+
echo \"Line Percentage: \$LinePercentage\" # Debug print &&
62+
wget \"https://img.shields.io/badge/coverage-\${LinePercentage}25-brightgreen.svg\" -O line_coverage_badge.svg &&
63+
FunctionPercentage=\$(lcov --summary cmake-build-unit-tests/coverage.info | grep 'functions' | awk '{print \$2}') &&
64+
echo \"Function Percentage: \$FunctionPercentage\" # Debug print &&
65+
wget \"https://img.shields.io/badge/coverage-\${FunctionPercentage}25-brightgreen.svg\" -O function_coverage_badge.svg &&
9066
mkdir coverage_badges &&
9167
mv line_coverage_badge.svg coverage_badges/ &&
9268
mv function_coverage_badge.svg coverage_badges/ &&
9369
zip -r coverage_badges.zip coverage_badges
70+
"
9471
9572
- name: Upload code coverage artifact
9673
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)