build.yaml 18 KB

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