build.yaml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 PIP
  22. uses: actions/cache@v3
  23. with:
  24. path: ~/.cache/pip
  25. key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
  26. restore-keys: |
  27. ${{ runner.os }}-pip-
  28. - name: Cache PlatformIO
  29. uses: actions/cache@v3
  30. with:
  31. path: ~/.platformio
  32. key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
  33. - name: Set up Python
  34. uses: actions/setup-python@v4
  35. with:
  36. python-version: '3.10'
  37. - name: Install PlatformIO
  38. run: |
  39. python -m pip install --upgrade pip
  40. pip install --upgrade platformio
  41. - name: Use Build Cache
  42. uses: actions/cache@v3
  43. with:
  44. path: ./code/.pio/
  45. key: ${{ runner.os }}-pio-${{ github.ref_name }}
  46. - name: Build Firmware
  47. #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
  48. run: cd code; platformio run --environment esp32cam
  49. - name: Set Hash in all Web UI files
  50. run: cd sd-card/html; find . -type f -exec sed -i 's/$COMMIT_HASH/${{ steps.vars.outputs.sha_short }}/g' {} \;
  51. - name: Store generated files in 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/*
  59. key: ${{ github.run_number }}
  60. #########################################################################################
  61. ## Pack for Update
  62. #########################################################################################
  63. pack-for-update:
  64. # New OTA concept
  65. # update__version.zip file with following content:
  66. # - /firmware.bin
  67. # - (optional) /html/*
  68. # - (optional) /config/*.tfl
  69. runs-on: ubuntu-latest
  70. needs: build
  71. steps:
  72. - uses: actions/checkout@v3
  73. - name: Get generated files from cache
  74. uses: actions/cache@v3
  75. with:
  76. path: |
  77. ./code/.pio/build/esp32cam/firmware.bin
  78. ./code/.pio/build/esp32cam/partitions.bin
  79. ./code/.pio/build/esp32cam/bootloader.bin
  80. ./sd-card/html/*
  81. key: ${{ github.run_number }}
  82. - name: Set Variables
  83. id: vars
  84. run: |
  85. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  86. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  87. - name: Prepare update__*.zip artifact
  88. run: |
  89. mkdir -p ./update
  90. cp "./code/.pio/build/esp32cam/firmware.bin" "update/firmware.bin"
  91. - name: Add Web UI to update
  92. run: cp -r ./sd-card/html ./update/
  93. - name: Add CNN to update
  94. run: |
  95. mkdir ./update/config/
  96. cp ./sd-card/config/*.tfl ./update/config/ 2>/dev/null || true
  97. cp ./sd-card/config/*.tflite ./update/config/ 2>/dev/null || true
  98. - name: Upload update as update.zip artifact (Firmware + Web UI + CNN)
  99. uses: actions/upload-artifact@v3
  100. with:
  101. name: "AI-on-the-edge-device__update__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  102. path: ./update/*
  103. - name: Store generated files in cache
  104. uses: actions/cache@v3
  105. with:
  106. path: update
  107. key: ${{ github.run_number }}-update
  108. #########################################################################################
  109. ## Pack for Remote Setup
  110. #########################################################################################
  111. pack-for-remote_setup:
  112. # New Remote Setup concept
  113. # remote_setup__version.zip file with following content:
  114. # - /firmware.bin
  115. # - /html/*
  116. # - /config/*
  117. runs-on: ubuntu-latest
  118. needs: build
  119. steps:
  120. - uses: actions/checkout@v3
  121. - name: Get generated files from cache
  122. uses: actions/cache@v3
  123. with:
  124. path: |
  125. ./code/.pio/build/esp32cam/firmware.bin
  126. ./code/.pio/build/esp32cam/partitions.bin
  127. ./code/.pio/build/esp32cam/bootloader.bin
  128. ./sd-card/html/*
  129. key: ${{ github.run_number }}
  130. - name: Set Variables
  131. id: vars
  132. run: |
  133. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  134. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  135. - name: Prepare remote_setup__*.zip artifact
  136. run: |
  137. mkdir -p ./remote_setup
  138. cp "./code/.pio/build/esp32cam/firmware.bin" "remote_setup/firmware.bin"
  139. - name: Add Web UI to remote_setup
  140. run: cp -r ./sd-card/html ./remote_setup/
  141. - name: Add whole config folder to remote_setup
  142. run: |
  143. mkdir ./remote_setup/config/
  144. cp ./sd-card/config/* ./remote_setup/config/ 2>/dev/null || true
  145. - name: Upload remote_setup as remote_setup.zip artifact (Firmware + Web UI + Config)
  146. uses: actions/upload-artifact@v3
  147. with:
  148. name: "AI-on-the-edge-device__remote-setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  149. path: ./remote_setup/*
  150. - name: Store generated files in cache
  151. uses: actions/cache@v3
  152. with:
  153. path: remote_setup
  154. key: ${{ github.run_number }}-remote_setup
  155. #########################################################################################
  156. ## Pack for a fresh install (USB flashing) (manual_setup)
  157. #########################################################################################
  158. pack-for-manual_setup:
  159. # creates old style binaries for fresh installation (backward compatible to wiki)
  160. runs-on: ubuntu-latest
  161. needs: build
  162. steps:
  163. - uses: actions/checkout@v3
  164. - name: Get generated files from cache
  165. uses: actions/cache@v3
  166. with:
  167. path: |
  168. ./code/.pio/build/esp32cam/firmware.bin
  169. ./code/.pio/build/esp32cam/partitions.bin
  170. ./code/.pio/build/esp32cam/bootloader.bin
  171. ./sd-card/html/*
  172. key: ${{ github.run_number }}
  173. - name: Set Variables
  174. id: vars
  175. run: |
  176. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  177. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  178. - name: Prepare manual_setup__*.zip artifact
  179. run: |
  180. mkdir -p manual_setup
  181. rm -rf manual_setup/*.zip
  182. mkdir -p release
  183. # copy builds to manual_setup folder
  184. cp -f "./code/.pio/build/esp32cam/firmware.bin" "manual_setup/firmware.bin"
  185. cp -f "./code/.pio/build/esp32cam/bootloader.bin" "manual_setup/bootloader.bin"
  186. cp -f "./code/.pio/build/esp32cam/partitions.bin" "manual_setup/partitions.bin"
  187. zip -r ./manual_setup/sd-card.zip sd-card
  188. cd ./manual_setup
  189. - name: Upload manual_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI)
  190. uses: actions/upload-artifact@v3
  191. with:
  192. name: "AI-on-the-edge-device__manual-setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  193. path: ./manual_setup
  194. - name: Store generated files in cache
  195. uses: actions/cache@v3
  196. with:
  197. path: manual_setup
  198. key: ${{ github.run_number }}-manual_setup
  199. #########################################################################################
  200. ## Prepare and create release
  201. #########################################################################################
  202. release:
  203. runs-on: ubuntu-latest
  204. needs: [pack-for-update, pack-for-manual_setup, pack-for-remote_setup]
  205. if: startsWith(github.ref, 'refs/tags/')
  206. steps:
  207. - uses: actions/checkout@v3
  208. # import update
  209. - name: Get generated update files from cache
  210. uses: actions/cache@v3
  211. with:
  212. path: update
  213. key: ${{ github.run_number }}-update
  214. # import remote_setup
  215. - name: Get generated files from cache
  216. uses: actions/cache@v3
  217. with:
  218. path: remote_setup
  219. key: ${{ github.run_number }}-remote_setup
  220. # import manual_setup
  221. - name: Get generated files from cache
  222. uses: actions/cache@v3
  223. with:
  224. path: manual_setup
  225. key: ${{ github.run_number }}-manual_setup
  226. - name: Set Variables
  227. id: vars
  228. run: |
  229. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  230. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  231. - name: Prepare artifacts for release
  232. run: |
  233. mkdir -p release
  234. # create AI-on-the-edge-device__update__*.zip like "AI-on-the-edge-device__update__v13.0.5.zip"
  235. cd ./update
  236. zip -r ../release/AI-on-the-edge-device__update__${{ steps.vars.outputs.branch }}.zip .
  237. # create AI-on-the-edge-device__manual-setup__*.zip like "AI-on-the-edge-device__manual-setup__v13.0.5.zip"
  238. cd ../manual_setup
  239. zip -r ../release/AI-on-the-edge-device__manual-setup__${{ steps.vars.outputs.branch }}.zip .
  240. # create AI-on-the-edge-device__remote-setup__*.zip like "AI-on-the-edge-device__remote-setup__v13.0.5.zip"
  241. cd ../manual_setup
  242. zip -r ../release/AI-on-the-edge-device__remote-setup__${{ steps.vars.outputs.branch }}.zip .
  243. # extract the version used in next step
  244. - id: get_version
  245. if: startsWith(github.ref, 'refs/tags/')
  246. uses: battila7/get-version-action@v2
  247. # the changelog [unreleased] will now be changed to the release version
  248. - name: Update changelog
  249. uses: thomaseizinger/keep-a-changelog-new-release@v1
  250. if: startsWith(github.ref, 'refs/tags/')
  251. with:
  252. changelogPath: Changelog.md
  253. version: ${{ steps.get_version.outputs.version-without-v }}
  254. # the release notes will be extracted from changelog
  255. - name: Extract release notes
  256. id: extract-release-notes
  257. if: startsWith(github.ref, 'refs/tags/')
  258. uses: ffurrer2/extract-release-notes@v1
  259. with:
  260. changelog_file: Changelog.md
  261. # Releases should only be created on master by tagging the last commit.
  262. # all artifacts in firmware folder pushed to the release
  263. - name: Release
  264. uses: softprops/action-gh-release@v1
  265. if: startsWith(github.ref, 'refs/tags/')
  266. with:
  267. name: ${{ steps.get_version.outputs.version-without-v }}
  268. body: ${{ steps.extract-release-notes.outputs.release_notes }}
  269. files: |
  270. release/*
  271. # Commit&Push Changelog to master branch. Must be manually merged back to rolling
  272. - name: Commit changes and push changes
  273. if: startsWith(github.ref, 'refs/tags/')
  274. run: |
  275. git config user.name github-actions
  276. git config user.email github-actions@github.com
  277. git add Changelog.md
  278. git commit Changelog.md -m "Update Changelog.md for ${{github.event.inputs.versionIncrement}} release"
  279. git push origin HEAD:master
  280. #########################################################################################
  281. ## Update the Web Installer on a release
  282. #########################################################################################
  283. update-web-installer:
  284. needs: [release]
  285. environment:
  286. name: github-pages
  287. url: ${{ steps.deployment.outputs.page_url }}
  288. runs-on: ubuntu-latest
  289. # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
  290. permissions:
  291. contents: read
  292. pages: write
  293. id-token: write
  294. steps:
  295. - name: Checkout
  296. uses: actions/checkout@v3
  297. # import update
  298. - name: Get generated update files from cache
  299. uses: actions/cache@v3
  300. with:
  301. path: update
  302. key: ${{ github.run_number }}-update
  303. - name: Set Variables
  304. id: vars
  305. run: |
  306. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  307. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  308. - name: Add binary to Web Installer and update manifest
  309. run: |
  310. rm -f docs/binary/firmware.bin
  311. cp -f update/firmware.bin docs/binary/firmware.bin
  312. cp -f docs/manifest_template.json docs/manifest.json
  313. sed -i 's/VERSION/${{ steps.vars.outputs.branch }}/g' docs/manifest.json
  314. - name: Setup Pages
  315. uses: actions/configure-pages@v2
  316. - name: Upload artifact
  317. uses: actions/upload-pages-artifact@v1
  318. with:
  319. path: 'docs'
  320. - name: Deploy to GitHub Pages
  321. id: deployment
  322. uses: actions/deploy-pages@v1