build.yaml 11 KB

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