Skip to content

greenc-FNAL running CMake format check #805

greenc-FNAL running CMake format check

greenc-FNAL running CMake format check #805

name: CMake Format Check
run-name: "${{ github.actor }} running CMake format check"
permissions:
contents: read
pull-requests: read
on:
pull_request:
branches: [ main, develop ]
workflow_dispatch:
jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.detect_act.outputs.is_act }}
steps:
- name: Detect act environment
id: detect_act
uses: Framework-R-D/phlex/.github/actions/detect-act-env@main
detect-changes:
needs: pre-check
if: github.event_name != 'workflow_dispatch' && needs.pre-check.outputs.is_act != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
path: phlex-src
- name: Detect CMake formatting changes
id: filter
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
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: [pre-check, detect-changes]
if: >
github.event_name == 'workflow_dispatch' ||
needs.pre-check.outputs.is_act == 'true' ||
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes == 'true')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
path: phlex-src
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: '3.x'
- name: Install gersemi
run: pip install gersemi
- name: Check CMake formatting
run: |
echo "➡️ Checking CMake file formatting..."
if ! gersemi --check phlex-src; then
echo "::error::Found files with formatting issues."
echo "::error::Run 'gersemi -i <file>' locally or comment '@phlexbot format' on the PR to auto-fix."
exit 1
else
echo "✅ All CMake files are properly formatted."
fi
cmake-format-check-skipped:
needs: [pre-check, detect-changes]
if: >
github.event_name != 'workflow_dispatch' &&
needs.pre-check.outputs.is_act != 'true' &&
needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.has_changes != 'true'
runs-on: ubuntu-latest
steps:
- name: No relevant CMake changes detected
run: echo "::notice::No CMake-related changes detected; cmake-format check skipped."