build.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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: dist
  143. key: ${{ github.run_number }}-pack-for-OTA-v2
  144. #########################################################################################
  145. ## Pack for a fresh install (USB flashing) (initial_esp32_setup)
  146. #########################################################################################
  147. pack-for-fresh-install:
  148. # creates old style binaries for fresh installation (backward compatible to wiki)
  149. runs-on: ubuntu-latest
  150. needs: build
  151. steps:
  152. - uses: actions/checkout@v3
  153. - name: Get generated files from cache
  154. uses: actions/cache@v3
  155. with:
  156. path: |
  157. ./code/.pio/build/esp32cam/firmware.bin
  158. ./code/.pio/build/esp32cam/partitions.bin
  159. ./code/.pio/build/esp32cam/bootloader.bin
  160. ./sd-card/html/version.txt
  161. key: ${{ github.run_number }}
  162. - name: Set Variables
  163. id: vars
  164. run: |
  165. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  166. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  167. - name: Prepare artifacts for release
  168. run: |
  169. mkdir -p firmware
  170. rm -rf firmware/*.zip
  171. mkdir -p release
  172. # copy builds to firmware folder
  173. cp -f "./code/.pio/build/esp32cam/firmware.bin" "firmware/firmware.bin"
  174. cp -f "./code/.pio/build/esp32cam/bootloader.bin" "firmware/bootloader.bin"
  175. cp -f "./code/.pio/build/esp32cam/partitions.bin" "firmware/partitions.bin"
  176. zip -r ./firmware/sd-card.zip sd-card
  177. cd ./firmware
  178. - name: Upload initial_esp32_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI)
  179. uses: actions/upload-artifact@v3
  180. with:
  181. name: "initial_esp32_setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  182. path: ./firmware
  183. - name: Store generated files in cache
  184. uses: actions/cache@v3
  185. with:
  186. path: firmware
  187. key: ${{ github.run_number }}-pack-for-fresh-install
  188. #########################################################################################
  189. ## Prepare and create release
  190. #########################################################################################
  191. release:
  192. runs-on: ubuntu-latest
  193. needs: [pack-for-OTA-v2, pack-for-fresh-install]
  194. if: startsWith(github.ref, 'refs/tags/')
  195. steps:
  196. - uses: actions/checkout@v3
  197. - name: Set Variables
  198. id: vars
  199. run: |
  200. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  201. - name: Get generated files from cache
  202. uses: actions/cache@v3
  203. with:
  204. path: |
  205. ./code/.pio/build/esp32cam/firmware.bin
  206. ./code/.pio/build/esp32cam/partitions.bin
  207. ./code/.pio/build/esp32cam/bootloader.bin
  208. ./sd-card/html/version.txt
  209. key: ${{ github.run_number }}
  210. # import the changes from
  211. - name: Get generated files from cache
  212. uses: actions/cache@v3
  213. with:
  214. path: dist
  215. key: ${{ github.run_number }}-pack-for-OTA-v2
  216. # import cached artifacts from pack-for-fresh-install
  217. - name: Get generated files from cache
  218. uses: actions/cache@v3
  219. with:
  220. path: firmware
  221. key: ${{ github.run_number }}-pack-for-fresh-install
  222. - name: Prepare artifacts for release
  223. run: |
  224. mkdir -p release
  225. mkdir -p dist
  226. # create a update.zip like "update__rolling"
  227. pwd
  228. ls ./dist
  229. cd ./dist
  230. zip -r ../release/update.zip .
  231. cd ../firmware
  232. zip -r ../release/initial_esp32_setup.zip .
  233. cd ../sd-card/html
  234. zip -r ../../firmware/html-from-11.3.1.zip .
  235. # extract the version used in next step
  236. - id: get_version
  237. if: startsWith(github.ref, 'refs/tags/')
  238. uses: battila7/get-version-action@v2
  239. # the changelog [unreleased] will now be changed to the release version
  240. - name: Update changelog
  241. uses: thomaseizinger/keep-a-changelog-new-release@v1
  242. if: startsWith(github.ref, 'refs/tags/')
  243. with:
  244. changelogPath: Changelog.md
  245. version: ${{ steps.get_version.outputs.version-without-v }}
  246. # the release notes will be extracted from changelog
  247. - name: Extract release notes
  248. id: extract-release-notes
  249. if: startsWith(github.ref, 'refs/tags/')
  250. uses: ffurrer2/extract-release-notes@v1
  251. with:
  252. changelog_file: Changelog.md
  253. # Releases should only be created on master by tagging the last commit.
  254. # all artifacts in firmware folder pushed to the release
  255. - name: Release
  256. uses: softprops/action-gh-release@v1
  257. if: startsWith(github.ref, 'refs/tags/')
  258. with:
  259. name: ${{ steps.get_version.outputs.version-without-v }}
  260. body: ${{ steps.extract-release-notes.outputs.release_notes }}
  261. files: |
  262. release/*
  263. firmware/firmware.bin
  264. firmware/html-from-11.3.1.zip
  265. # Commit&Push Changelog to master branch. Must be manually merged back to rolling
  266. - name: Commit changes and push changes
  267. if: startsWith(github.ref, 'refs/tags/')
  268. run: |
  269. git config user.name github-actions
  270. git config user.email github-actions@github.com
  271. git add Changelog.md
  272. git commit Changelog.md -m "Update Changelog.md for ${{github.event.inputs.versionIncrement}} release"
  273. git push origin HEAD:master