action.yaml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. name: Run cmake-format
  2. description: Runs cmake-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-cmake-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. brew install --quiet zsh
  31. echo ::endgroup::
  32. - name: Run cmake-format 🎛️
  33. id: result
  34. shell: zsh --no-rcs --errexit --pipefail {0}
  35. working-directory: ${{ github.workspace }}
  36. env:
  37. GITHUB_EVENT_FORCED: ${{ github.event.forced }}
  38. GITHUB_REF_BEFORE: ${{ github.event.before }}
  39. run: |
  40. : Run cmake-format 🎛️
  41. if (( ${+RUNNER_DEBUG} )) setopt XTRACE
  42. local -a changes=($(git diff --name-only HEAD~1 HEAD))
  43. case ${GITHUB_EVENT_NAME} {
  44. pull_request) changes=($(git diff --name-only origin/${GITHUB_BASE_REF} HEAD)) ;;
  45. push) if [[ ${GITHUB_EVENT_FORCED} != true ]] changes=($(git diff --name-only ${GITHUB_REF_BEFORE} HEAD)) ;;
  46. *) ;;
  47. }
  48. if (( ${changes[(I)*.cmake|*CMakeLists.txt]} )) {
  49. echo ::group::Install cmakelang
  50. pip3 install cmakelang
  51. echo ::endgroup::
  52. echo ::group::Run cmake-format
  53. ./build-aux/run-cmake-format --fail-${{ inputs.failCondition }} --check
  54. echo ::endgroup::
  55. }