build.yaml 12 KB

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