build.yaml 11 KB

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