action.yaml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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: Install Dependencies 🛍️
  23. if: runner.os == 'Linux'
  24. shell: bash
  25. run: |
  26. : Install Dependencies 🛍️
  27. echo ::group::Install Dependencies
  28. eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
  29. echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
  30. echo "/home/linuxbrew/.linuxbrew/opt/clang-format@13/bin" >> $GITHUB_PATH
  31. brew install --quiet zsh
  32. echo ::endgroup::
  33. - name: Run clang-format 🐉
  34. id: result
  35. shell: zsh --no-rcs --errexit --pipefail {0}
  36. working-directory: ${{ inputs.workingDirectory }}
  37. env:
  38. GITHUB_EVENT_FORCED: ${{ github.event.forced }}
  39. GITHUB_REF_BEFORE: ${{ github.event.before }}
  40. run: |
  41. : Run clang-format 🐉
  42. if (( ${+RUNNER_DEBUG} )) setopt XTRACE
  43. local -a changes=($(git diff --name-only HEAD~1 HEAD))
  44. case ${GITHUB_EVENT_NAME} {
  45. pull_request) changes=($(git diff --name-only origin/${GITHUB_BASE_REF} HEAD)) ;;
  46. push) if [[ ${GITHUB_EVENT_FORCED} != true ]] changes=($(git diff --name-only ${GITHUB_REF_BEFORE} HEAD)) ;;
  47. *) ;;
  48. }
  49. if (( ${changes[(I)(*.c|*.h|*.cpp|*.hpp|*.m|*.mm)]} )) {
  50. echo ::group::Install clang-format-13
  51. brew install --quiet obsproject/tools/clang-format@13
  52. echo ::endgroup::
  53. echo ::group::Run clang-format-13
  54. ./build-aux/run-clang-format --fail-${{ inputs.failCondition }} --check
  55. echo ::endgroup::
  56. }