build.yaml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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_ENV
  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_ENV
  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 }}_(${{ env.sha_short }}).bin"
  70. - name: Upload Firmware artifact (old OTA concept)
  71. uses: actions/upload-artifact@v3
  72. with:
  73. name: "firmware__(extract_before_upload)__${{ github.ref_name }}__(${{ env.sha_short }})"
  74. path: ./dist_old_ota/*
  75. - name: Upload Web interface artifact (old OTA concept)
  76. uses: actions/upload-artifact@v3
  77. with:
  78. name: "html__${{ github.ref_name }}__(${{ env.sha_short }})"
  79. path: ./sd-card/html/*
  80. #########################################################################################
  81. ## Pack for new OTA (v2)
  82. #########################################################################################
  83. pack-for-OTA-v2:
  84. # New OTA concept
  85. # update__version.zip file with following content:
  86. # - /firmware.bin
  87. # - (optional) /html/*
  88. # - (optional) /config/*.tfl
  89. runs-on: ubuntu-latest
  90. needs: build
  91. steps:
  92. - uses: actions/checkout@v3
  93. - name: Get generated files from cache
  94. uses: actions/cache@v3
  95. with:
  96. path: |
  97. ./code/.pio/build/esp32cam/firmware.bin
  98. ./code/.pio/build/esp32cam/partitions.bin
  99. ./code/.pio/build/esp32cam/bootloader.bin
  100. ./sd-card/html/version.txt
  101. key: ${{ github.run_number }}
  102. - name: Set Variables
  103. id: vars
  104. run: |
  105. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
  106. - name: Prepare update.zip artifact
  107. run: |
  108. mkdir -p ./dist
  109. cp "./code/.pio/build/esp32cam/firmware.bin" "dist/firmware.bin"
  110. - name: Add Web UI to dist
  111. run: cp -r ./sd-card/html ./dist/
  112. - name: Add CNN to dist
  113. run: |
  114. mkdir ./dist/config/
  115. cp ./sd-card/config/*.tfl ./dist/config/ 2>/dev/null || true
  116. cp ./sd-card/config/*.tflite ./dist/config/ 2>/dev/null || true
  117. - name: Upload dist as update.zip artifact (Firmware + Web UI + CNN)
  118. uses: actions/upload-artifact@v3
  119. with:
  120. name: "update__${{ github.ref_name }}_(${{ env.sha_short }})"
  121. path: ./dist/*
  122. - name: Store generated files in cache
  123. uses: actions/cache@v3
  124. with:
  125. path: |
  126. ./dist
  127. key: ${{ github.run_number }}-pack-for-OTA-v2
  128. #########################################################################################
  129. ## Pack for a fresh install (USB flashing) (initial_esp32_setup)
  130. #########################################################################################
  131. pack-for-fresh-install:
  132. # creates old style binaries for fresh installation (backward compatible to wiki)
  133. runs-on: ubuntu-latest
  134. needs: build
  135. steps:
  136. - uses: actions/checkout@v3
  137. - name: Get generated files from cache
  138. uses: actions/cache@v3
  139. with:
  140. path: |
  141. ./code/.pio/build/esp32cam/firmware.bin
  142. ./code/.pio/build/esp32cam/partitions.bin
  143. ./code/.pio/build/esp32cam/bootloader.bin
  144. ./sd-card/html/version.txt
  145. key: ${{ github.run_number }}
  146. - name: Set Variables
  147. id: vars
  148. run: |
  149. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
  150. - name: Prepare artifacts for release
  151. run: |
  152. mkdir -p firmware
  153. rm -rf firmware/*.zip
  154. mkdir -p release
  155. # copy builds to firmware folder
  156. cp -f "./code/.pio/build/esp32cam/firmware.bin" "firmware/firmware.bin"
  157. cp -f "./code/.pio/build/esp32cam/bootloader.bin" "firmware/bootloader.bin"
  158. cp -f "./code/.pio/build/esp32cam/partitions.bin" "firmware/partitions.bin"
  159. zip -r ./firmware/sd-card.zip sd-card
  160. cd ./firmware
  161. - name: Upload initial_esp32_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI)
  162. uses: actions/upload-artifact@v3
  163. with:
  164. name: "initial_esp32_setup__${{ github.ref_name }}_(${{ env.sha_short }})"
  165. path: ./firmware
  166. - name: Store generated files in cache
  167. uses: actions/cache@v3
  168. with:
  169. path: |
  170. ./firmware
  171. key: ${{ github.run_number }}-pack-for-fresh-install
  172. #########################################################################################
  173. ## Prepare and create release
  174. #########################################################################################
  175. release:
  176. runs-on: ubuntu-latest
  177. needs: [pack-for-OTA-v2, pack-for-fresh-install]
  178. if: startsWith(github.ref, 'refs/tags/')
  179. steps:
  180. - uses: actions/checkout@v3
  181. - name: Get generated files from cache
  182. uses: actions/cache@v3
  183. with:
  184. path: |
  185. ./code/.pio/build/esp32cam/firmware.bin
  186. ./code/.pio/build/esp32cam/partitions.bin
  187. ./code/.pio/build/esp32cam/bootloader.bin
  188. ./sd-card/html/version.txt
  189. key: ${{ github.run_number }}
  190. # import the changes from
  191. - name: Get generated files from cache
  192. uses: actions/cache@v3
  193. with:
  194. path: |
  195. ./dist
  196. key: ${{ github.run_number }}-pack-for-OTA-v2
  197. # import cached artifacts from pack-for-fresh-install
  198. - name: Get generated files from cache
  199. uses: actions/cache@v3
  200. with:
  201. path: |
  202. ./firmware
  203. key: ${{ github.run_number }}-pack-for-fresh-install
  204. - name: Set Variables
  205. id: vars
  206. run: |
  207. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
  208. - name: Prepare artifacts for release
  209. run: |
  210. mkdir -p release
  211. # create a update.zip like "update__rolling"
  212. cd ./dist
  213. zip -r ../release/update.zip .
  214. cd ../firmware
  215. zip -r ../release/initial_esp32_setup.zip .
  216. cd ../sd-card/html
  217. zip -r ../../firmware/html-from-11.3.1.zip .
  218. # extract the version used in next step
  219. - id: get_version
  220. if: startsWith(github.ref, 'refs/tags/')
  221. uses: battila7/get-version-action@v2
  222. # the changelog [unreleased] will now be changed to the release version
  223. - name: Update changelog
  224. uses: thomaseizinger/keep-a-changelog-new-release@v1
  225. if: startsWith(github.ref, 'refs/tags/')
  226. with:
  227. changelogPath: Changelog.md
  228. version: ${{ steps.get_version.outputs.version-without-v }}
  229. # the release notes will be extracted from changelog
  230. - name: Extract release notes
  231. id: extract-release-notes
  232. if: startsWith(github.ref, 'refs/tags/')
  233. uses: ffurrer2/extract-release-notes@v1
  234. with:
  235. changelog_file: Changelog.md
  236. # Releases should only be created on master by tagging the last commit.
  237. # all artifacts in firmware folder pushed to the release
  238. - name: Release
  239. uses: softprops/action-gh-release@v1
  240. if: startsWith(github.ref, 'refs/tags/')
  241. with:
  242. name: ${{ steps.get_version.outputs.version-without-v }}
  243. body: ${{ steps.extract-release-notes.outputs.release_notes }}
  244. files: |
  245. release/*
  246. firmware/firmware.bin
  247. firmware/html-from-11.3.1.zip
  248. # Commit&Push Changelog to master branch. Must be manually merged back to rolling
  249. - name: Commit changes and push changes
  250. if: startsWith(github.ref, 'refs/tags/')
  251. run: |
  252. git config user.name github-actions
  253. git config user.email github-actions@github.com
  254. git add Changelog.md
  255. git commit Changelog.md -m "Update Changelog.md for ${{github.event.inputs.versionIncrement}} release"
  256. git push origin HEAD:master