Skip to content

fixed cmake format and lint hook bug #9

fixed cmake format and lint hook bug

fixed cmake format and lint hook bug #9

name: Formatting and Linting
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
setup-build-lint:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
sudo apt update
sudo apt-get install -y check clang-format clang-tidy cmake
- name: Set up workspace
run: |
# Create workspace structure
mkdir -p ws/src ws/build ws/install
- name: Checkout code
uses: actions/checkout@v4
with:
path: ws/src/temp
- name: Set up build
working-directory: ws
run: |
# Extract package name from CMakeLists.txt project() definition
PACKAGE_NAME=$(grep -m1 -Po 'project\(\K[^\)]+' src/temp/CMakeLists.txt)
echo PACKAGE_NAME=$PACKAGE_NAME >> $GITHUB_ENV
# create a directory for the package in src
mkdir -p src/$PACKAGE_NAME
# Move all files and directories in src to the package-specific directory
mv src/temp/{.[!.],}* src/$PACKAGE_NAME
# Remove the temporary directory
rm -rf src/temp
# Create build directory for the package
mkdir -p build/$PACKAGE_NAME
# Navigate to the package-specific build directory
cd build/$PACKAGE_NAME
# Configure with specified flags and set install prefix to install
cmake ../../src/$PACKAGE_NAME \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_TESTS=ON \
-DCMAKE_INSTALL_PREFIX=../../install
# Install to the specified install directory
make install
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit cmakelang[YAML]
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-${{ runner.os }}-
- name: Run pre-commit checks
working-directory: ws
run: |
# cd to the package-specific directory
cd src/$PACKAGE_NAME
pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks
# Run pre-commit checks
pre-commit run --show-diff-on-failure --color=always --all-files