build.yaml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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@v4
  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: Update PIP cache on every commit
  22. uses: actions/cache@v4
  23. with:
  24. path: ~/.cache/pip
  25. key: pip-${{ github.run_id }}
  26. restore-keys: pip # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  27. - name: Update PlatformIO cache on every commit
  28. uses: actions/cache@v4
  29. with:
  30. path: ~/.platformio
  31. key: platformio-${{ github.run_id }}
  32. restore-keys: platformio # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  33. - name: Update Build cache on every commit
  34. uses: actions/cache@v4
  35. with:
  36. path: ./code/.pio/
  37. key: build-${{ github.run_id }}
  38. restore-keys: build # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  39. - name: Update generated-files cache on every commit
  40. uses: actions/cache@v4
  41. with:
  42. path: |
  43. ./code/.pio/build/esp32cam/firmware.bin
  44. ./code/.pio/build/esp32cam/partitions.bin
  45. ./code/.pio/build/esp32cam/bootloader.bin
  46. ./html/*
  47. ./demo/*
  48. key: generated-files-${{ github.run_id }}
  49. restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  50. - name: Set up Python
  51. uses: actions/setup-python@v5
  52. with:
  53. python-version: '3.10'
  54. - name: Install PlatformIO
  55. run: |
  56. python -m pip install --upgrade pip
  57. pip install --upgrade platformio
  58. - name: Build Firmware
  59. #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
  60. run: cd code; platformio run --environment esp32cam
  61. - name: Prepare Web UI (generate tooltip pages and update hashes in all files)
  62. run: |
  63. rm -rf ./html
  64. mkdir html
  65. cp -r ./sd-card/html/* ./html/
  66. python -m pip install markdown
  67. mkdir html/param-tooltips
  68. cd tools/parameter-tooltip-generator
  69. python generate-param-doc-tooltips.py
  70. cd ../..
  71. cp -r ./sd-card/html/* ./html/
  72. echo "Replacing variables..."
  73. cd html; find . -type f -exec sed -i 's/$COMMIT_HASH/${{ steps.vars.outputs.sha_short }}/g' {} \;
  74. - name: Prepare Demo mode files
  75. run: |
  76. rm -rf ./demo
  77. mkdir demo
  78. cp -r ./sd-card/demo/* ./demo/
  79. #########################################################################################
  80. ## Pack for Update
  81. #########################################################################################
  82. pack-for-update:
  83. # New OTA concept
  84. # update__version.zip file with following content:
  85. # - /firmware.bin
  86. # - (optional) /html/* (inkl. subfolders)
  87. # - (optional) /config/*.tfl
  88. # - (optional) /demo/*
  89. runs-on: ubuntu-latest
  90. needs: build
  91. steps:
  92. - uses: actions/checkout@v4
  93. - name: Update generated-files cache on every commit
  94. uses: actions/cache@v4
  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. ./html/*
  101. ./demo/*
  102. key: generated-files-${{ github.run_id }}
  103. restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  104. - name: Update update cache on every commit
  105. uses: actions/cache@v4
  106. with:
  107. path: update
  108. key: update-${{ github.run_id }}
  109. restore-keys: update # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  110. - name: Set Variables
  111. id: vars
  112. run: |
  113. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  114. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  115. - name: Prepare update__*.zip artifact
  116. run: |
  117. rm -rf ./update
  118. mkdir -p ./update
  119. cp "./code/.pio/build/esp32cam/firmware.bin" "update/firmware.bin"
  120. - name: Add Web UI to update
  121. run: cp -r ./html ./update/
  122. - name: Add Demo mode files to update
  123. run: cp -r ./demo ./update/
  124. - name: Add CNN to update
  125. run: |
  126. rm -rf ./update/config/
  127. mkdir -p ./update/config/
  128. cp ./sd-card/config/*.tfl ./update/config/ 2>/dev/null || true
  129. cp ./sd-card/config/*.tflite ./update/config/ 2>/dev/null || true
  130. - name: Upload update as update.zip artifact (Firmware + Web UI + CNN)
  131. uses: actions/upload-artifact@v4
  132. with:
  133. name: "AI-on-the-edge-device__update__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  134. path: ./update/*
  135. #########################################################################################
  136. ## Pack for Remote Setup
  137. #########################################################################################
  138. pack-for-remote_setup:
  139. # New Remote Setup concept
  140. # remote_setup__version.zip file with following content:
  141. # - /firmware.bin
  142. # - /html/* (inkl. subfolders)
  143. # - /demo/*
  144. # - /config/*
  145. runs-on: ubuntu-latest
  146. needs: build
  147. steps:
  148. - uses: actions/checkout@v4
  149. - name: Update generated-files cache on every commit
  150. uses: actions/cache@v4
  151. with:
  152. path: |
  153. ./code/.pio/build/esp32cam/firmware.bin
  154. ./code/.pio/build/esp32cam/partitions.bin
  155. ./code/.pio/build/esp32cam/bootloader.bin
  156. ./html/*
  157. ./demo/*
  158. key: generated-files-${{ github.run_id }}
  159. restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  160. - name: Update remote_setup cache on every commit
  161. uses: actions/cache@v4
  162. with:
  163. path: remote_setup
  164. key: remote_setup-${{ github.run_id }}
  165. restore-keys: remote_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  166. - name: Set Variables
  167. id: vars
  168. run: |
  169. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  170. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  171. - name: Prepare remote_setup__*.zip artifact
  172. run: |
  173. rm -rf ./remote_setup
  174. mkdir -p ./remote_setup
  175. - name: Add Web UI to remote_setup
  176. run: cp -r ./html ./remote_setup/
  177. - name: Add Demo mode files to update
  178. run: cp -r ./demo ./update/
  179. - name: Add whole config folder to remote_setup
  180. run: |
  181. rm -rf ./remote_setup/config/
  182. mkdir -p ./remote_setup/config/
  183. cp ./sd-card/config/* ./remote_setup/config/ 2>/dev/null || true
  184. - name: Upload remote_setup as remote_setup.zip artifact (Firmware + Web UI + Config)
  185. uses: actions/upload-artifact@v4
  186. with:
  187. name: "AI-on-the-edge-device__remote-setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  188. path: ./remote_setup/*
  189. #########################################################################################
  190. ## Pack for a fresh install (USB flashing) (manual_setup)
  191. #########################################################################################
  192. pack-for-manual_setup:
  193. # creates old style binaries for fresh installation (backward compatible to wiki)
  194. runs-on: ubuntu-latest
  195. needs: build
  196. steps:
  197. - uses: actions/checkout@v4
  198. - name: Update generated-files cache on every commit
  199. uses: actions/cache@v4
  200. with:
  201. path: |
  202. ./code/.pio/build/esp32cam/firmware.bin
  203. ./code/.pio/build/esp32cam/partitions.bin
  204. ./code/.pio/build/esp32cam/bootloader.bin
  205. ./html/*
  206. ./demo/*
  207. key: generated-files-${{ github.run_id }}
  208. restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  209. - name: Update manual_setup cache on every commit
  210. uses: actions/cache@v4
  211. with:
  212. path: manual_setup
  213. key: manual_setup-${{ github.run_id }}
  214. restore-keys: manual_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  215. - name: Set Variables
  216. id: vars
  217. run: |
  218. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  219. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  220. - name: Prepare manual_setup__*.zip artifact
  221. run: |
  222. rm -rf manual_setup
  223. mkdir -p manual_setup
  224. rm -rf manual_setup/*.zip
  225. rm -rf release
  226. mkdir -p release
  227. # copy builds to manual_setup folder
  228. cp -f "./code/.pio/build/esp32cam/firmware.bin" "manual_setup/firmware.bin"
  229. cp -f "./code/.pio/build/esp32cam/bootloader.bin" "manual_setup/bootloader.bin"
  230. cp -f "./code/.pio/build/esp32cam/partitions.bin" "manual_setup/partitions.bin"
  231. rm -rf ./sd-card/html
  232. rm -rf ./sd-card/demo
  233. cp -r ./html ./sd-card/ # Overwrite the Web UI with the preprocessed files
  234. cp -r ./demo ./sd-card/
  235. cd sd-card; zip -r ../manual_setup/sd-card.zip *; cd ..
  236. cd ./manual_setup
  237. - name: Upload manual_setup.zip artifact (Firmware + Bootloader + Partitions + Web UI)
  238. uses: actions/upload-artifact@v4
  239. with:
  240. name: "AI-on-the-edge-device__manual-setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
  241. path: ./manual_setup
  242. #########################################################################################
  243. ## Prepare and create release
  244. #########################################################################################
  245. prepare-release:
  246. runs-on: ubuntu-latest
  247. needs: [pack-for-update, pack-for-manual_setup, pack-for-remote_setup]
  248. if: startsWith(github.ref, 'refs/tags/')
  249. # Sets permissions of the GITHUB_TOKEN to allow updating the branches
  250. permissions:
  251. contents: write
  252. pages: write
  253. id-token: write
  254. steps:
  255. - uses: actions/checkout@v4
  256. - name: Update update cache on every commit
  257. uses: actions/cache@v4
  258. with:
  259. path: update
  260. key: update-${{ github.run_id }}
  261. restore-keys: update # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  262. - name: Update remote_setup cache on every commit
  263. uses: actions/cache@v4
  264. with:
  265. path: remote_setup
  266. key: remote_setup-${{ github.run_id }}
  267. restore-keys: remote_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  268. - name: Update manual_setup cache on every commit
  269. uses: actions/cache@v4
  270. with:
  271. path: manual_setup
  272. key: manual_setup-${{ github.run_id }}
  273. restore-keys: manual_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
  274. - name: Set Variables
  275. id: vars
  276. run: |
  277. echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  278. echo "branch=$(echo ${{ github.ref_name }} | tr / __)" >> $GITHUB_OUTPUT
  279. - name: Prepare artifacts for release
  280. run: |
  281. rm -rf release
  282. mkdir -p release
  283. # create AI-on-the-edge-device__update__*.zip like "AI-on-the-edge-device__update__v13.0.5.zip"
  284. cd ./update
  285. zip -r ../release/AI-on-the-edge-device__update__${{ steps.vars.outputs.branch }}.zip .
  286. # create AI-on-the-edge-device__manual-setup__*.zip like "AI-on-the-edge-device__manual-setup__v13.0.5.zip"
  287. cd ../manual_setup
  288. zip -r ../release/AI-on-the-edge-device__manual-setup__${{ steps.vars.outputs.branch }}.zip .
  289. # create AI-on-the-edge-device__remote-setup__*.zip like "AI-on-the-edge-device__remote-setup__v13.0.5.zip"
  290. cd ../remote_setup
  291. zip -r ../release/AI-on-the-edge-device__remote-setup__${{ steps.vars.outputs.branch }}.zip .
  292. # extract the version used in next step
  293. - id: get_version
  294. uses: drewg13/get-version-action@98dda2a47a257e202c2e6c2ed2e6072ec23f448e
  295. # # the changelog [unreleased] will now be changed to the release version
  296. # - name: Update changelog
  297. # uses: thomaseizinger/keep-a-changelog-new-release@v1
  298. # with:
  299. # changelogPath: Changelog.md
  300. # version: ${{ steps.get_version.outputs.version-without-v }}
  301. # # the release notes will be extracted from changelog
  302. # - name: Extract release notes
  303. # id: extract-release-notes
  304. # uses: ffurrer2/extract-release-notes@v1
  305. # with:
  306. # changelog_file: Changelog.md
  307. # Releases should only be created on master by tagging the last commit.
  308. # all artifacts in firmware folder pushed to the release
  309. - name: Release
  310. uses: softprops/action-gh-release@v2.0.8
  311. # Note:
  312. # If you get the error "Resource not accessible by integration",
  313. # The access rights are not sufficient, see
  314. # https://github.com/softprops/action-gh-release/issues/232#issuecomment-1131379440
  315. with:
  316. name: ${{ steps.get_version.outputs.version-without-v }}
  317. body: ${{ steps.extract-release-notes.outputs.release_notes }}
  318. files: |
  319. release/*
  320. # # Commit&Push Changelog to master branch. Must be manually merged back to rolling
  321. # - name: Commit changes and push changes
  322. # run: |
  323. # git config user.name github-actions
  324. # git config user.email github-actions@github.com
  325. # git add Changelog.md
  326. # git commit Changelog.md -m "Update Changelog.md for ${{github.event.inputs.versionIncrement}} release"
  327. # git push origin HEAD:master
  328. #########################################################################################
  329. ## Update the Web Installer on a release
  330. #########################################################################################
  331. # Make sure to also update update-webinstaller.yml!
  332. update-web-installer:
  333. if: github.event_name == 'release' && github.event.action == 'published' # Only run on release but not on prerelease
  334. needs: [prepare-release]
  335. environment:
  336. name: github-pages
  337. url: ${{ steps.deployment.outputs.page_url }}
  338. runs-on: ubuntu-latest
  339. # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
  340. permissions:
  341. contents: read
  342. pages: write
  343. id-token: write
  344. steps:
  345. - name: Checkout
  346. uses: actions/checkout@v4
  347. - name: Get version of last release
  348. id: last_release
  349. uses: mindojo/get-latest-release@0b8ef1434d7468d6bffcc8263baff5c777f72321
  350. with:
  351. myToken: ${{ github.token }}
  352. exclude_types: "draft|prerelease"
  353. view_top: 1
  354. - name: Add binary to Web Installer and update manifest
  355. run: |
  356. echo "Updating Web installer to use firmware from ${{ steps.last_release.outputs.tag_name }}..."
  357. rm -f docs/binary/firmware.bin
  358. wget ${{ github.server_url }}/${{ github.repository }}/releases/download/${{ steps.last_release.outputs.tag_name }}/AI-on-the-edge-device__update__${{ steps.last_release.outputs.tag_name }}.zip
  359. unzip AI-on-the-edge-device__update__${{ steps.last_release.outputs.tag_name }}.zip
  360. cp -f firmware.bin docs/binary/firmware.bin
  361. echo "Updating index and manifest file..."
  362. sed -i 's/$VERSION/${{ steps.last_release.outputs.tag_name }}/g' docs/index.html
  363. sed -i 's/$VERSION/${{ steps.last_release.outputs.tag_name }}/g' docs/manifest.json
  364. - name: Setup Pages
  365. uses: actions/configure-pages@v4
  366. - name: Upload artifact
  367. uses: actions/upload-pages-artifact@v2
  368. with:
  369. path: 'docs'
  370. - name: Deploy to GitHub Pages
  371. id: deployment
  372. uses: actions/deploy-pages@v3 # Note: v4 does not work!