build.yaml 18 KB

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