build.yaml 16 KB

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