lint_and_submodule_check.yml 3.0 KB

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