build.yaml 18 KB

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