build.yaml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. name: Build and Pack
  2. on: [push, pull_request]
  3. jobs:
  4. #########################################################################################
  5. ## Build Firmware
  6. #########################################################################################
  7. build:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - id: skip_check
  11. uses: fkirc/skip-duplicate-actions@v5
  12. with:
  13. concurrent_skipping: same_content_newer
  14. - uses: actions/checkout@v3
  15. with:
  16. submodules: recursive
  17. - name: Set Variables
  18. id: vars
  19. run: |
  20. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  21. - name: Cache PlatformIO
  22. uses: actions/cache@v3
  23. with:
  24. path: ~/.platformio
  25. key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
  26. - name: Set up Python
  27. uses: actions/setup-python@v4
  28. with:
  29. python-version: '3.10'
  30. - name: Install PlatformIO
  31. run: |
  32. python -m pip install --upgrade pip
  33. pip install --upgrade platformio
  34. - name: Build Firmware
  35. #run: echo "Testing... ${{ github.ref_name }}, ${{ steps.vars.outputs.sha_short }}" > ./sd-card/html/version.txt; mkdir -p ./code/.pio/build/esp32cam/; cd ./code/.pio/build/esp32cam/; echo "${{ steps.vars.outputs.sha_short }}" > firmware.bin; cp firmware.bin partitions.bin; cp firmware.bin bootloader.bin # Testing
  36. run: cd code; platformio run --environment esp32cam
  37. - name: Store generated files in cache
  38. uses: actions/cache@v3
  39. with:
  40. path: |
  41. ./code/.pio/build/esp32cam/firmware.bin
  42. ./code/.pio/build/esp32cam/partitions.bin
  43. ./code/.pio/build/esp32cam/bootloader.bin
  44. ./sd-card/html/version.txt
  45. key: ${{ github.run_number }}
  46. #########################################################################################
  47. ## Pack for new OTA
  48. #########################################################################################
  49. pack-for-OTA:
  50. # New OTA concept
  51. # update__version.zip file with following content:
  52. # - /firmware.bin
  53. # - (optional) /html/*
  54. # - (optional) /config/*.tfl
  55. runs-on: ubuntu-latest
  56. needs: build
  57. steps:
  58. - uses: actions/checkout@v3
  59. - name: Get generated files from cache
  60. uses: actions/cache@v3
  61. with:
  62. path: |
  63. ./code/.pio/build/esp32cam/firmware.bin
  64. ./code/.pio/build/esp32cam/partitions.bin
  65. ./code/.pio/build/esp32cam/bootloader.bin
  66. ./sd-card/html/version.txt
  67. key: ${{ github.run_number }}
  68. - name: Set Variables
  69. id: vars
  70. run: |
  71. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  72. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  73. - name: Prepare update.zip artifact
  74. run: |
  75. mkdir -p ./dist
  76. cp "./code/.pio/build/esp32cam/firmware.bin" "dist/firmware.bin"
  77. - name: Add Web UI to dist
  78. run: cp -r ./sd-card/html ./dist/
  79. - name: Add CNN to dist
  80. run: |
  81. mkdir ./dist/config/
  82. cp ./sd-card/config/*.tfl ./dist/config/ 2>/dev/null || true
  83. cp ./sd-card/config/*.tflite ./dist/config/ 2>/dev/null || true
  84. - name: Upload dist as update.zip artifact (Firmware + Web UI + CNN)
  85. uses: actions/upload-artifact@v3
  86. with:
  87. name: "update__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  88. path: ./dist/*
  89. - name: Store generated files in cache
  90. uses: actions/cache@v3
  91. with:
  92. path: dist
  93. key: ${{ github.run_number }}-pack-for-OTA
  94. #########################################################################################
  95. ## Pack for a fresh install (USB flashing) (initial_esp32_setup)
  96. #########################################################################################
  97. pack-for-fresh-install:
  98. # creates old style binaries for fresh installation (backward compatible to wiki)
  99. runs-on: ubuntu-latest
  100. needs: build
  101. steps:
  102. - uses: actions/checkout@v3
  103. - name: Get generated files from cache
  104. uses: actions/cache@v3
  105. with:
  106. path: |
  107. ./code/.pio/build/esp32cam/firmware.bin
  108. ./code/.pio/build/esp32cam/partitions.bin
  109. ./code/.pio/build/esp32cam/bootloader.bin
  110. ./sd-card/html/version.txt
  111. key: ${{ github.run_number }}
  112. - name: Set Variables
  113. id: vars
  114. run: |
  115. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  116. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  117. - name: Prepare artifacts for release
  118. run: |
  119. mkdir -p firmware
  120. rm -rf firmware/*.zip
  121. mkdir -p release
  122. # copy builds to firmware folder
  123. cp -f "./code/.pio/build/esp32cam/firmware.bin" "firmware/firmware.bin"
  124. cp -f "./code/.pio/build/esp32cam/bootloader.bin" "firmware/bootloader.bin"
  125. cp -f "./code/.pio/build/esp32cam/partitions.bin" "firmware/partitions.bin"
  126. zip -r ./firmware/sd-card.zip sd-card
  127. cd ./firmware
  128. - name: Upload initial_esp32_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI)
  129. uses: actions/upload-artifact@v3
  130. with:
  131. name: "initial_esp32_setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  132. path: ./firmware
  133. - name: Store generated files in cache
  134. uses: actions/cache@v3
  135. with:
  136. path: firmware
  137. key: ${{ github.run_number }}-pack-for-fresh-install
  138. #########################################################################################
  139. ## Prepare and create release
  140. #########################################################################################
  141. release:
  142. runs-on: ubuntu-latest
  143. needs: [pack-for-OTA, pack-for-fresh-install]
  144. if: startsWith(github.ref, 'refs/tags/')
  145. steps:
  146. - uses: actions/checkout@v3
  147. - name: Set Variables
  148. id: vars
  149. run: |
  150. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  151. # import the changes from
  152. - name: Get generated files from cache
  153. uses: actions/cache@v3
  154. with:
  155. path: dist
  156. key: ${{ github.run_number }}-pack-for-OTA
  157. # import cached artifacts from pack-for-fresh-install
  158. - name: Get generated files from cache
  159. uses: actions/cache@v3
  160. with:
  161. path: firmware
  162. key: ${{ github.run_number }}-pack-for-fresh-install
  163. - name: Prepare artifacts for release
  164. run: |
  165. mkdir -p release
  166. mkdir -p dist
  167. # create a update.zip like "update__rolling"
  168. pwd
  169. cd ./dist
  170. zip -r ../release/update.zip .
  171. cd ../firmware
  172. zip -r ../release/initial_esp32_setup.zip .
  173. # extract the version used in next step
  174. - id: get_version
  175. if: startsWith(github.ref, 'refs/tags/')
  176. uses: battila7/get-version-action@v2
  177. # the changelog [unreleased] will now be changed to the release version
  178. - name: Update changelog
  179. uses: thomaseizinger/keep-a-changelog-new-release@v1
  180. if: startsWith(github.ref, 'refs/tags/')
  181. with:
  182. changelogPath: Changelog.md
  183. version: ${{ steps.get_version.outputs.version-without-v }}
  184. # the release notes will be extracted from changelog
  185. - name: Extract release notes
  186. id: extract-release-notes
  187. if: startsWith(github.ref, 'refs/tags/')
  188. uses: ffurrer2/extract-release-notes@v1
  189. with:
  190. changelog_file: Changelog.md
  191. # Releases should only be created on master by tagging the last commit.
  192. # all artifacts in firmware folder pushed to the release
  193. - name: Release
  194. uses: softprops/action-gh-release@v1
  195. if: startsWith(github.ref, 'refs/tags/')
  196. with:
  197. name: ${{ steps.get_version.outputs.version-without-v }}
  198. body: ${{ steps.extract-release-notes.outputs.release_notes }}
  199. files: |
  200. release/*
  201. # Commit&Push Changelog to master branch. Must be manually merged back to rolling
  202. - name: Commit changes and push changes
  203. if: startsWith(github.ref, 'refs/tags/')
  204. run: |
  205. git config user.name github-actions
  206. git config user.email github-actions@github.com
  207. git add Changelog.md
  208. git commit Changelog.md -m "Update Changelog.md for ${{github.event.inputs.versionIncrement}} release"
  209. git push origin HEAD:master