lint_and_submodule_check.yml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. name: 'Lint sources & check submodule integrity'
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. tags:
  7. - '*'
  8. pull_request:
  9. env:
  10. TARGETS: f7
  11. FBT_TOOLCHAIN_PATH: /runner/_work
  12. SET_GH_OUTPUT: 1
  13. jobs:
  14. lint_sources_check_submodules:
  15. runs-on: [self-hosted,FlipperZeroShell]
  16. steps:
  17. - name: 'Wipe workspace'
  18. run: find ./ -mount -maxdepth 1 -exec rm -rf {} \;
  19. - name: 'Checkout code'
  20. uses: actions/checkout@v3
  21. with:
  22. fetch-depth: 1
  23. ref: ${{ github.event.pull_request.head.sha }}
  24. - name: 'Check protobuf branch'
  25. run: |
  26. git submodule update --init
  27. SUB_PATH="assets/protobuf";
  28. SUB_BRANCH="dev";
  29. SUB_COMMITS_MIN=40;
  30. cd "$SUB_PATH";
  31. SUBMODULE_HASH="$(git rev-parse HEAD)";
  32. BRANCHES=$(git branch -r --contains "$SUBMODULE_HASH");
  33. COMMITS_IN_BRANCH="$(git rev-list --count dev)";
  34. if [ $COMMITS_IN_BRANCH -lt $SUB_COMMITS_MIN ]; then
  35. echo "name=fails::error" >> $GITHUB_OUTPUT;
  36. echo "::error::Error: Too few commits in $SUB_BRANCH of submodule $SUB_PATH: $COMMITS_IN_BRANCH(expected $SUB_COMMITS_MIN+)";
  37. exit 1;
  38. fi
  39. if ! grep -q "/$SUB_BRANCH" <<< "$BRANCHES"; then
  40. echo "name=fails::error" >> $GITHUB_OUTPUT;
  41. echo "::error::Error: Submodule $SUB_PATH is not on branch $SUB_BRANCH";
  42. exit 1;
  43. fi
  44. - name: 'Check Python code formatting'
  45. id: syntax_check_py
  46. run: |
  47. set +e;
  48. ./fbt -s lint_py 2>&1 | tee lint-py.log;
  49. if [ "${PIPESTATUS[0]}" -ne 0 ]; then
  50. # Save multiline output
  51. echo "errors=1" >> $GITHUB_OUTPUT;
  52. printf "Python Lint errors:\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY;
  53. echo "$(cat lint-py.log)" >> $GITHUB_STEP_SUMMARY;
  54. printf "\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY;
  55. exit 1;
  56. else
  57. echo "Python Lint: all good ✨" >> $GITHUB_STEP_SUMMARY;
  58. fi
  59. - name: 'Check C++ code formatting'
  60. id: syntax_check_cpp
  61. if: always()
  62. run: |
  63. set +e;
  64. ./fbt -s lint 2>&1 | tee lint-cpp.log;
  65. if [ "${PIPESTATUS[0]}" -ne 0 ]; then
  66. # Save multiline output
  67. echo "errors=1" >> $GITHUB_OUTPUT;
  68. printf "C Lint errors:\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY;
  69. echo "$(cat lint-cpp.log)" >> $GITHUB_STEP_SUMMARY;
  70. printf "\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY;
  71. exit 1;
  72. else
  73. echo "C Lint: all good ✨" >> $GITHUB_STEP_SUMMARY;
  74. fi
  75. - name: Report code formatting errors
  76. if: ( steps.syntax_check_py.outputs.errors || steps.syntax_check_cpp.outputs.errors ) && github.event.pull_request
  77. run: |
  78. echo "Code formatting errors found";
  79. echo "Please run './fbt format' or './fbt format_py' to fix them";
  80. exit 1;