You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1 KiB

  1. name: PR Lint keyboards
  2. permissions:
  3. contents: read
  4. on:
  5. pull_request:
  6. paths:
  7. - 'keyboards/**'
  8. jobs:
  9. lint:
  10. runs-on: ubuntu-latest
  11. container: ghcr.io/qmk/qmk_cli
  12. steps:
  13. - name: Disable safe.directory check
  14. run : git config --global --add safe.directory '*'
  15. - uses: actions/checkout@v3
  16. with:
  17. fetch-depth: 0
  18. - name: Install dependencies
  19. run: pip3 install -r requirements-dev.txt
  20. - name: Get changed files
  21. id: file_changes
  22. uses: tj-actions/changed-files@v37
  23. - name: Print info
  24. run: |
  25. git rev-parse --short HEAD
  26. echo ${{ github.event.pull_request.base.sha }}
  27. echo '${{ steps.file_changes.outputs.all_changed_files}}'
  28. - name: Run qmk lint
  29. if: always()
  30. shell: 'bash {0}'
  31. run: |
  32. QMK_CHANGES=$(echo -e '${{ steps.file_changes.outputs.all_changed_files}}' | sed 's/ /\n/g')
  33. QMK_KEYBOARDS=$(qmk list-keyboards)
  34. exit_code=0
  35. for KB in $QMK_KEYBOARDS; do
  36. KEYBOARD_CHANGES=$(echo "$QMK_CHANGES" | grep -E '^(keyboards/'${KB}'/)')
  37. if [[ -z "$KEYBOARD_CHANGES" ]]; then
  38. # skip as no changes for this keyboard
  39. continue
  40. fi
  41. KEYMAP_ONLY=$(echo "$KEYBOARD_CHANGES" | grep -cv /keymaps/)
  42. if [[ $KEYMAP_ONLY -gt 0 ]]; then
  43. echo "linting ${KB}"
  44. qmk lint --keyboard ${KB} && qmk info -l --keyboard ${KB}
  45. exit_code=$(($exit_code + $?))
  46. fi
  47. done
  48. qmk format-text ${{ steps.file_changes.outputs.all_changed_files}} || true
  49. for file in ${{ steps.file_changes.outputs.all_changed_files}}; do
  50. if ! git diff --quiet $file; then
  51. echo "File '${file}' Requires Formatting"
  52. echo "::error file=${file}::Requires Formatting"
  53. exit_code=$(($exit_code + 1))
  54. fi
  55. done
  56. if [[ $exit_code -gt 255 ]]; then
  57. exit 255
  58. fi
  59. exit $exit_code
  60. - name: Verify at most one added keyboard
  61. if: always()
  62. shell: 'bash {0}'
  63. run: |
  64. git reset --hard
  65. git clean -xfd
  66. # Get the keyboard list and count for the target branch
  67. git checkout -f ${{ github.base_ref }}
  68. git pull --ff-only
  69. QMK_KEYBOARDS_BASE=$(qmk list-keyboards)
  70. QMK_KEYBOARDS_BASE_COUNT=$(qmk list-keyboards | wc -l)
  71. # Get the keyboard list and count for the PR
  72. git checkout -f ${{ github.head_ref }}
  73. git merge --no-commit --squash ${{ github.base_ref }}
  74. QMK_KEYBOARDS_PR=$(qmk list-keyboards)
  75. QMK_KEYBOARDS_PR_COUNT=$(qmk list-keyboards | wc -l)
  76. echo "::group::Keyboards changes in this PR"
  77. diff -d -U 0 <(echo "$QMK_KEYBOARDS_BASE") <(echo "$QMK_KEYBOARDS_PR") | grep -vE '^(---|\+\+\+|@@)' | sed -e 's@^-@Removed: @g' -e 's@^+@ Added: @g'
  78. echo "::endgroup::"
  79. if [[ $QMK_KEYBOARDS_PR_COUNT -gt $(($QMK_KEYBOARDS_BASE_COUNT + 1)) ]]; then
  80. echo "More than one keyboard added in this PR -- see the PR Checklist."
  81. echo "::error::More than one keyboard added in this PR -- see the PR Checklist."
  82. exit 1
  83. fi