Skip to content

greenc-FNAL checking code format #672

greenc-FNAL checking code format

greenc-FNAL checking code format #672

name: Clang-Format Check
run-name: "${{ github.actor }} checking code format"
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 C++ 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: cpp
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No clang-format related changes detected; job will be skipped."
else
echo "::group::Clang-format relevant files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
clang-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
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
path: phlex-src
- name: Announce clang-format check
run: echo "➡️ Running clang-format check..."
- name: Run clang-format lint
id: lint
uses: DoozyX/clang-format-lint-action@bcb4eb2cb0d707ee4f3e5cc3b456eb075f12cf73 # v0.20
with:
source: "./phlex-src"
clangFormatVersion: 20
extensions: cpp,hpp,cpp.in,hpp.in
continue-on-error: true
- name: Evaluate clang-format result
if: always()
run: |
if [[ ${{ steps.lint.outcome }} == 'success' ]]; then
echo "✅ clang-format check passed."
else
echo "::error::clang-format check failed. Please review the output above for details."
exit 1
fi
clang-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
permissions:
contents: read
steps:
- name: No relevant C++ changes detected
run: echo "::notice::No clang-format relevant changes detected; check skipped."