Files
4jcraft/.github/workflows/clang-format-all.yml
T
2026-03-13 15:09:54 -05:00

69 lines
1.9 KiB
YAML

name: Clang Format All
on:
workflow_dispatch:
inputs:
commit_changes:
description: Commit formatted changes back to the selected branch
required: true
default: false
type: boolean
permissions:
contents: write
jobs:
clang-format-all:
runs-on: ubuntu-24.04
concurrency:
group: clang-format-all-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format-19
- name: Format tracked C/C++ files
env:
CLANG_FORMAT_BIN: clang-format-19
run: |
bash ./.github/scripts/run-clang-format-all.sh apply
- name: Export patch
id: patch
run: |
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git diff --binary > clang-format-all.patch
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Upload patch artifact
if: steps.patch.outputs.changed == 'true'
uses: actions/upload-artifact@v4
with:
name: clang-format-all-${{ github.sha }}
path: clang-format-all.patch
retention-days: 7
- name: Commit formatted changes
if: steps.patch.outputs.changed == 'true' && github.event.inputs.commit_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Run clang-format over tracked sources"
git push origin HEAD:${GITHUB_REF_NAME}
- name: Report no-op run
if: steps.patch.outputs.changed == 'false'
run: echo "clang-format produced no changes."