build.yml 17 KB

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