build.yaml 17 KB

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