amap_analyse.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. name: 'Analyze .map file with Amap'
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. - "release*"
  7. tags:
  8. - '*'
  9. pull_request:
  10. env:
  11. TARGETS: f7
  12. jobs:
  13. amap_analyse:
  14. if: ${{ !github.event.pull_request.head.repo.fork }}
  15. runs-on: [self-hosted,FlipperZeroMacShell]
  16. timeout-minutes: 15
  17. steps:
  18. - name: 'Wait Build workflow'
  19. uses: fountainhead/action-wait-for-check@v1.0.0
  20. id: wait-for-build
  21. with:
  22. token: ${{ secrets.GITHUB_TOKEN }}
  23. checkName: 'main'
  24. ref: ${{ github.event.pull_request.head.sha || github.sha }}
  25. intervalSeconds: 20
  26. - name: 'Check Build workflow status'
  27. if: steps.wait-for-build.outputs.conclusion == 'failure'
  28. run: |
  29. exit 1
  30. - name: 'Decontaminate previous build leftovers'
  31. run: |
  32. if [ -d .git ]; then
  33. git submodule status \
  34. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  35. fi
  36. - name: 'Checkout code'
  37. uses: actions/checkout@v2
  38. with:
  39. fetch-depth: 0
  40. ref: ${{ github.event.pull_request.head.sha }}
  41. - name: 'Escape pull request title'
  42. if: github.event_name == 'pull_request'
  43. run: |
  44. import json
  45. import os
  46. import shlex
  47. with open('${{ github.event_path }}') as fh:
  48. event = json.load(fh)
  49. escaped = shlex.quote(event['pull_request']['title'])
  50. with open(os.environ['GITHUB_ENV'], 'a') as fh:
  51. print(f'PULL_NAME={escaped}', file=fh)
  52. shell: python3 {0}
  53. - name: 'Generate prefixes by commit'
  54. id: names
  55. run: |
  56. REF="${{github.ref}}"
  57. COMMIT_HASH="$(git rev-parse HEAD)"
  58. SHA="$(git rev-parse --short HEAD)"
  59. COMMIT_MSG="${{github.event.head_commit.message}}"
  60. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  61. REF="${{github.head_ref}}"
  62. COMMIT_HASH="$(git log -1 --pretty=oneline | awk '{print $1}')"
  63. SHA="$(cut -c -8 <<< "$COMMIT_HASH")"
  64. COMMIT_MSG="$(git log -1 --pretty=format:"%s")"
  65. PULL_ID="${{github.event.pull_request.number}}"
  66. fi
  67. BRANCH_NAME=${REF#refs/*/}
  68. SUFFIX=${BRANCH_NAME//\//_}-$(date +'%d%m%Y')-${SHA}
  69. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  70. SUFFIX=${BRANCH_NAME//\//_}
  71. fi
  72. echo "::set-output name=commit-hash::${COMMIT_HASH}"
  73. echo "::set-output name=commit-msg::${COMMIT_MSG}"
  74. echo "::set-output name=pull-id::${PULL_ID}"
  75. echo "::set-output name=pull-name::${PULL_NAME}"
  76. echo "::set-output name=branch-name::${BRANCH_NAME}"
  77. echo "::set-output name=suffix::${SUFFIX}"
  78. - name: 'Make artifacts directory'
  79. run: |
  80. rm -rf artifacts
  81. mkdir artifacts
  82. - name: 'Download build artifacts'
  83. run: |
  84. echo "${{ secrets.RSYNC_DEPLOY_KEY }}" > deploy_key;
  85. chmod 600 ./deploy_key;
  86. rsync -avzP \
  87. -e 'ssh -p ${{ secrets.RSYNC_DEPLOY_PORT }} -i ./deploy_key' \
  88. ${{ secrets.RSYNC_DEPLOY_USER }}@${{ secrets.RSYNC_DEPLOY_HOST }}:"${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.branch-name}}/" artifacts/;
  89. rm ./deploy_key;
  90. - name: 'Make .map file analyze'
  91. run: |
  92. cd artifacts/
  93. /Applications/amap/Contents/MacOS/amap -f flipper-z-f7-firmware-${{steps.names.outputs.suffix}}.elf.map
  94. - name: 'Upload report to DB'
  95. run: |
  96. FBT_TOOLCHAIN_PATH=/opt source scripts/toolchain/fbtenv.sh
  97. get_size()
  98. {
  99. SECTION="$1";
  100. arm-none-eabi-size \
  101. -A artifacts/flipper-z-f7-firmware-${{steps.names.outputs.suffix}}.elf \
  102. | grep "^$SECTION" | awk '{print $2}'
  103. }
  104. export COMMIT_HASH="${{steps.names.outputs.commit-hash}}"
  105. export COMMIT_MSG="${{steps.names.outputs.commit-msg}}"
  106. export BRANCH_NAME="${{steps.names.outputs.branch-name}}"
  107. export BSS_SIZE="$(get_size ".bss")"
  108. export TEXT_SIZE="$(get_size ".text")"
  109. export RODATA_SIZE="$(get_size ".rodata")"
  110. export DATA_SIZE="$(get_size ".data")"
  111. export FREE_FLASH_SIZE="$(get_size ".free_flash")"
  112. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  113. export PULL_ID="${{steps.names.outputs.pull-id}}"
  114. fi
  115. python3 -m pip install mariadb
  116. python3 scripts/amap_mariadb_insert.py \
  117. ${{ secrets.AMAP_MARIADB_USER }} \
  118. ${{ secrets.AMAP_MARIADB_PASSWORD }} \
  119. ${{ secrets.AMAP_MARIADB_HOST }} \
  120. ${{ secrets.AMAP_MARIADB_PORT }} \
  121. ${{ secrets.AMAP_MARIADB_DATABASE }} \
  122. artifacts/flipper-z-f7-firmware-${{steps.names.outputs.suffix}}.elf.map.all