build.yaml 13 KB

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