Skip to content

greenc-FNAL running CMake format check #227

greenc-FNAL running CMake format check

greenc-FNAL running CMake format check #227

name: CMake Format Check
run-name: "${{ github.actor }} running CMake format check"
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
detect-cmake-format-changes:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
changed_files: ${{ steps.filter.outputs.matched_files }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: phlex-src
- name: Detect CMake formatting changes
id: filter
uses: ./phlex-src/.github/actions/detect-relevant-changes
with:
repo-path: phlex-src
base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
head-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
file-type: cmake
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No CMake-related changes detected; formatting check will be skipped."
else
echo "::group::CMake-related files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
cmake-format-check:
needs: detect-cmake-format-changes
if: ${{ needs.detect-cmake-format-changes.outputs.has_changes == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: phlex-src
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install cmake-format
run: pip install cmakelang
- name: Check CMake formatting
run: |
cd phlex-src
echo "Checking CMake file formatting..."
cmake_files=$(find . -type f \( -name "CMakeLists.txt" -o -name "CMakeLists.txt.in" -o -name "*.cmake" -o -name "*.cmake.in" \) ! -path "*/build/*" ! -path "*/_deps/*")
if [ -z "$cmake_files" ]; then
echo "No CMake files found to check"
exit 0
fi
format_errors=0
for file in $cmake_files; do
echo "Checking $file..."
if ! cmake-format --check "$file"; then
echo "❌ Format error in: $file"
format_errors=$((format_errors + 1))
fi
done
if [ $format_errors -gt 0 ]; then
echo ""
echo "::error::Found $format_errors file(s) with formatting issues"
echo "Run 'cmake-format -i <file>' locally or comment '@phlexbot format' on the PR to auto-fix"
exit 1
fi
echo "✓ All CMake files are properly formatted"
cmake-format-check-skipped:
needs: detect-cmake-format-changes
if: ${{ needs.detect-cmake-format-changes.outputs.has_changes != 'true' }}
runs-on: ubuntu-latest
steps:
- name: No relevant CMake changes detected
run: echo "No CMake-related changes detected; cmake-format check skipped."