action.yaml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. name: Run clang-format
  2. description: Runs clang-format and checks for any changes introduced by it
  3. inputs:
  4. failCondition:
  5. description: Controls whether failed checks also fail the workflow run
  6. required: false
  7. default: never
  8. workingDirectory:
  9. description: Working directory for checks
  10. required: false
  11. default: ${{ github.workspace }}
  12. runs:
  13. using: composite
  14. steps:
  15. - name: Check Runner Operating System 🏃‍♂️
  16. if: runner.os == 'Windows'
  17. shell: bash
  18. run: |
  19. : Check Runner Operating System 🏃‍♂️
  20. echo "::notice::run-clang-format action requires a macOS-based or Linux-based runner."
  21. exit 2
  22. - name: Check for Changed Files ✅
  23. uses: ./.github/actions/check-changes
  24. id: checks
  25. with:
  26. checkGlob: "'*.c' '*.h' '*.cpp' '*.hpp' '*.m' '*.mm'"
  27. diffFilter: 'ACM'
  28. - name: Install Dependencies 🛍️
  29. if: runner.os == 'Linux' && fromJSON(steps.checks.outputs.hasChangedFiles)
  30. shell: bash
  31. run: |
  32. : Install Dependencies 🛍️
  33. echo ::group::Install Dependencies
  34. eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
  35. echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
  36. echo "/home/linuxbrew/.linuxbrew/opt/clang-format@17/bin" >> $GITHUB_PATH
  37. brew install --quiet zsh
  38. echo ::endgroup::
  39. - name: Run clang-format 🐉
  40. if: fromJSON(steps.checks.outputs.hasChangedFiles)
  41. id: result
  42. shell: zsh --no-rcs --errexit --pipefail {0}
  43. working-directory: ${{ inputs.workingDirectory }}
  44. env:
  45. CHANGED_FILES: ${{ steps.checks.outputs.changedFiles }}
  46. run: |
  47. : Run clang-format 🐉
  48. if (( ${+RUNNER_DEBUG} )) setopt XTRACE
  49. print ::group::Install clang-format-17
  50. brew install --quiet obsproject/tools/clang-format@17
  51. print ::endgroup::
  52. print ::group::Run clang-format-17
  53. local -a changes=(${(s:,:)CHANGED_FILES//[\[\]\'\"]/})
  54. ./build-aux/run-clang-format --fail-${{ inputs.failCondition }} --check ${changes}
  55. print ::endgroup::