build.yaml 11 KB

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