Skip to content

Commit

Permalink
ci: build shared library in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Zncl2222 committed Jun 8, 2024
1 parent 0be19a0 commit dabb912
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 29 deletions.
35 changes: 17 additions & 18 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ jobs:
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y valgrind

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: make test && make memcheck
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y valgrind

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: make test && make memcheck

build_windows:
name: c-build-windows
Expand Down
46 changes: 41 additions & 5 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@ on:
types: [opened, synchronize, reopened]

jobs:
build_shared_library:
strategy:
matrix:
runs-on: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Build DLL & Set file name windows
if: matrix.runs-on == 'windows-latest'
shell: pwsh
run: |
.\cmake_build.bat -s
echo "filename=uc_sgsim.dll" >> $env:GITHUB_ENV
- name: Build Shared Library & Set file name ubuntu
if: matrix.runs-on == 'ubuntu-latest'
run: |
sh ./cmake_build.sh -s
echo "filename=uc_sgsim.so" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.runs-on }}-shared-library
path: ./uc_sgsim/c_core/${{ env.filename }}

python_test:
name: py-unittest
runs-on: ubuntu-latest

needs: build_shared_library
strategy:
max-parallel: 5
matrix:
Expand All @@ -31,18 +54,25 @@ jobs:
if [ -f requirements.txt ];
then pip install -r requirements.txt;
fi
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- run: |
mv ./uc_sgsim.so ./uc_sgsim/c_core
- name: Run tests to generate coverage statistics
run: |
pytest -n auto --cov --cov-report xml:py_coverage.xml
- uses: actions/upload-artifact@v4
if: matrix.python-version == '3.11'
with:
name: python-coverage
path: ./py_coverage.xml

python_test_windows:
name: py-unittest-windows
runs-on: windows-latest

needs: build_shared_library
strategy:
max-parallel: 5
matrix:
Expand All @@ -62,6 +92,12 @@ jobs:
pip install --upgrade pip
pip install -r requirements.txt
}
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- run: |
mv ./uc_sgsim.dll ./uc_sgsim/c_core
- name: Run tests to generate coverage statistics
run: |
pytest -n auto --cov --cov-report xml:py_coverage.xml
Expand All @@ -83,7 +119,7 @@ jobs:
run: |
pip install gcovr==5.0 # 5.1 is not supported
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: Run build-wrapper
run: |
mkdir build
Expand Down Expand Up @@ -145,7 +181,7 @@ jobs:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Run sonar-scanner
uses: SonarSource/sonarcloud-github-action
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.projectKey=zncl2222_Stochastic_UC_SGSIM_py
Expand Down Expand Up @@ -175,7 +211,7 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Run build-wrapper
Expand Down
4 changes: 2 additions & 2 deletions cmake_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ cd cbuild

IF /I "%1"=="-s" (
cmake -DIS_EXECUTE=OFF -G "MinGW Makefiles" ..
make
%~dp0cbuild/c_example.exe
) ELSE (
cmake -DIS_EXECUTE=ON -G "MinGW Makefiles" ..
)

make
%~dp0cbuild/c_example.exe
cd ..

exit /b 0
8 changes: 4 additions & 4 deletions cmake_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ cd cmake_build
if [ "$is_execute" = true ]; then
echo "Compile the code into an executable file !"
cmake -DIS_EXECUTE=ON ..
make
make test
make memcheck
else
echo "Compile the code into a shared library (dynamic library) !"
cmake -DIS_EXECUTE=OFF ..
make
fi

make
make test
make memcheck
Binary file removed uc_sgsim/c_core/uc_sgsim.dll
Binary file not shown.
Binary file removed uc_sgsim/c_core/uc_sgsim.so
Binary file not shown.

0 comments on commit dabb912

Please sign in to comment.