Skip to content

greenc-FNAL checking C++ code format #1662

greenc-FNAL checking C++ code format

greenc-FNAL checking C++ code format #1662

name: Clang-Format Check
run-name: "${{ github.actor }} checking C++ code format"
permissions:
contents: read
pull-requests: read
"on":
pull_request:
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string
jobs:
setup:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.setup.outputs.is_act }}
ref: ${{ steps.setup.outputs.ref }}
repo: ${{ steps.setup.outputs.repo }}
base_sha: ${{ steps.setup.outputs.base_sha }}
pr_number: ${{ steps.setup.outputs.pr_number }}
checkout_path: ${{ steps.setup.outputs.checkout_path }}
has_changes: ${{ steps.setup.outputs.has_changes }}
steps:
- name: Workflow setup
id: setup
uses: Framework-R-D/phlex/.github/actions/workflow-setup@main
with:
file-type: cpp
clang-format-check:
needs: setup
if: >
always() && (github.event_name == 'workflow_dispatch' || needs.setup.outputs.has_changes == 'true')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.setup.outputs.ref }}
path: ${{ needs.setup.outputs.checkout_path }}
repository: ${{ needs.setup.outputs.repo }}
persist-credentials: false
- 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: "./${{ needs.setup.outputs.checkout_path }}"
clangFormatVersion: 20
extensions: cpp,hpp,cpp.in,hpp.in
continue-on-error: true
- name: Evaluate clang-format result
if: always() && steps.lint.outcome != 'skipped'
env:
REPO: ${{ needs.setup.outputs.repo }}
run: |
REPO_NAME="${REPO##*/}"
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."
echo "::error::Comment '@${REPO_NAME}bot format' on the PR to attempt auto-fix."
exit 1
fi