astyle.yml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. name: 🕴️ Style check
  3. on:
  4. push:
  5. branches:
  6. - master
  7. - release-**
  8. pull_request:
  9. branches:
  10. - master
  11. - release-**
  12. issue_comment:
  13. types: [created]
  14. jobs:
  15. astyle-check:
  16. runs-on: ubuntu-20.04
  17. steps:
  18. - uses: actions/github-script@v5
  19. if: ${{ github.event.issue.pull_request }}
  20. id: get-pr
  21. with:
  22. script: |
  23. const request = {
  24. owner: context.repo.owner,
  25. repo: context.repo.repo,
  26. pull_number: context.issue.number
  27. }
  28. core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
  29. try {
  30. const result = await github.rest.pulls.get(request)
  31. return result.data
  32. } catch (err) {
  33. core.setFailed(`Request failed with error ${err}`)
  34. }
  35. - uses: actions/checkout@v2
  36. if: ${{ github.event.issue.pull_request }}
  37. with:
  38. repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }}
  39. ref: ${{ fromJSON(steps.get-pr.outputs.result).head.sha }} # or .head.ref for branch name
  40. - uses: actions/checkout@v2
  41. if: ${{ !github.event.issue.pull_request }}
  42. - uses: khan/pull-request-comment-trigger@master
  43. id: indent-check
  44. if: ${{ github.event.issue.pull_request }}
  45. with:
  46. trigger: '@qfield-fairy style please'
  47. reaction: rocket
  48. env:
  49. GITHUB_TOKEN: '${{ secrets.FAIRY_TOKEN }}'
  50. - name: Check astyle
  51. id: astyle-check
  52. run: |
  53. sudo apt install -y astyle
  54. find src/ -name '*.cpp' -o -name '*.h' | xargs ./scripts/astyle.sh
  55. find test/ -name '*.cpp' -o -name '*.h' | xargs ./scripts/astyle.sh
  56. if [ ! -z "$(git status --porcelain)" ]; then
  57. echo "::error::Indentation errors found (astyle)"
  58. echo "::group::Indentation changes"
  59. git diff
  60. echo "::endgroup"
  61. echo '::set-output name=changed::true'
  62. fi
  63. - name: Comment
  64. uses: thollander/actions-comment-pull-request@main
  65. if: steps.indent-check.outputs.changed == 'true' && steps.indent-check.outputs.triggered != 'true'
  66. with:
  67. message: |
  68. Code formatting issues have been detected.
  69. Reply with `@qfield-fairy style please` to fix it up 🪄.
  70. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  71. - uses: EndBug/add-and-commit@v7.4.0
  72. if: steps.indent-check.outputs.triggered == 'true'
  73. with:
  74. author_name: Style Fairy
  75. author_email: fairy@qfield.org
  76. message: 'Committing astyle changes'
  77. branch: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }}
  78. env:
  79. GITHUB_TOKEN: ${{ secrets.FAIRY_TOKEN }}