# NOTE: This action requires write permissions to be set in your GitHub
#       repo/fork for it to be able to commit changes.
#
# This is currently enabled via:
#
#   settings > Actions > General > Workflow permissions
#
# which you will need to set to "Read and write permissions"
#
name: clang-format Commit Changes
on: 
  workflow_dispatch:
  push:

permissions:
  contents: read

jobs:
  formatting-check:
    name: Commit Format Changes
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, 'skip-ci')"
    permissions:
        contents: write # In order to allow EndBug/add-and-commit to commit changes
    steps:
    - uses: actions/checkout@v4.1.7

    - name: Fix C and Java formatting issues detected by clang-format
      uses: DoozyX/clang-format-lint-action@v0.20
      with:
        source: '.'
        extensions: 'c,h,cpp,hpp,java'
        clangFormatVersion: 17
        inplace: True
        style: file
        exclude: './config ./mfhdf/ncgen/ncgenyy.c ./mfhdf/ncgen/ncgentab.c ./mfhdf/ncgen/ncgentab.h'

    - uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4
      with:
          author_name: github-actions
          author_email: 41898282+github-actions[bot]@users.noreply.github.com
          message: 'Committing clang-format changes'
