ghcr_runtime.yml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. # Workflow that builds, tests and then pushes the runtime docker images to the ghcr.io repository
  2. name: Build, Test and Publish Runtime Image
  3. # Only run one workflow of the same group at a time.
  4. # There can be at most one running and one pending job in a concurrency group at any time.
  5. concurrency:
  6. group: ${{ github.workflow }}-${{ github.ref }}
  7. cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
  8. # Always run on "main"
  9. # Always run on tags
  10. # Always run on PRs
  11. # Can also be triggered manually
  12. on:
  13. push:
  14. branches:
  15. - main
  16. tags:
  17. - '*'
  18. pull_request:
  19. workflow_dispatch:
  20. inputs:
  21. reason:
  22. description: 'Reason for manual trigger'
  23. required: true
  24. default: ''
  25. jobs:
  26. # Builds the runtime Docker images
  27. ghcr_build_runtime:
  28. name: Build Image
  29. runs-on: ubuntu-latest
  30. permissions:
  31. contents: read
  32. packages: write
  33. strategy:
  34. matrix:
  35. base_image:
  36. - image: 'nikolaik/python-nodejs:python3.11-nodejs22'
  37. tag: nikolaik
  38. steps:
  39. - name: Checkout
  40. uses: actions/checkout@v4
  41. - name: Free Disk Space (Ubuntu)
  42. uses: jlumbroso/free-disk-space@main
  43. with:
  44. # this might remove tools that are actually needed,
  45. # if set to "true" but frees about 6 GB
  46. tool-cache: true
  47. # all of these default to true, but feel free to set to
  48. # "false" if necessary for your workflow
  49. android: true
  50. dotnet: true
  51. haskell: true
  52. large-packages: true
  53. docker-images: false
  54. swap-storage: true
  55. - name: Set up QEMU
  56. uses: docker/setup-qemu-action@v3
  57. - name: Login to GHCR
  58. uses: docker/login-action@v3
  59. with:
  60. registry: ghcr.io
  61. username: ${{ github.repository_owner }}
  62. password: ${{ secrets.GITHUB_TOKEN }}
  63. - name: Set up Docker Buildx
  64. id: buildx
  65. uses: docker/setup-buildx-action@v3
  66. - name: Set up Python
  67. uses: actions/setup-python@v5
  68. with:
  69. python-version: '3.11'
  70. - name: Cache Poetry dependencies
  71. uses: actions/cache@v4
  72. with:
  73. path: |
  74. ~/.cache/pypoetry
  75. ~/.virtualenvs
  76. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  77. restore-keys: |
  78. ${{ runner.os }}-poetry-
  79. - name: Install poetry via pipx
  80. run: pipx install poetry
  81. - name: Install Python dependencies using Poetry
  82. run: make install-python-dependencies
  83. - name: Create source distribution and Dockerfile
  84. run: poetry run python3 openhands/runtime/utils/runtime_build.py --base_image ${{ matrix.base_image.image }} --build_folder containers/runtime --force_rebuild
  85. - name: Build and push runtime image ${{ matrix.base_image.image }}
  86. if: github.event.pull_request.head.repo.fork != true
  87. run: |
  88. ./containers/build.sh runtime ${{ github.repository_owner }} --push ${{ matrix.base_image.tag }}
  89. # Forked repos can't push to GHCR, so we need to upload the image as an artifact
  90. - name: Build runtime image ${{ matrix.base_image.image }} for fork
  91. if: github.event.pull_request.head.repo.fork
  92. uses: docker/build-push-action@v6
  93. with:
  94. tags: ghcr.io/all-hands-ai/runtime:${{ github.sha }}-${{ matrix.base_image.tag }}
  95. outputs: type=docker,dest=/tmp/runtime-${{ matrix.base_image.tag }}.tar
  96. context: containers/runtime
  97. - name: Upload runtime image for fork
  98. if: github.event.pull_request.head.repo.fork
  99. uses: actions/upload-artifact@v4
  100. with:
  101. name: runtime-${{ matrix.base_image.tag }}
  102. path: /tmp/runtime-${{ matrix.base_image.tag }}.tar
  103. # Run unit tests with the EventStream runtime Docker images
  104. test_runtime:
  105. name: Test Runtime
  106. needs: [ghcr_build_runtime]
  107. runs-on: ubuntu-latest
  108. strategy:
  109. fail-fast: false
  110. matrix:
  111. base_image: ['nikolaik']
  112. steps:
  113. - uses: actions/checkout@v4
  114. - name: Free Disk Space (Ubuntu)
  115. uses: jlumbroso/free-disk-space@main
  116. with:
  117. tool-cache: true
  118. android: true
  119. dotnet: true
  120. haskell: true
  121. large-packages: true
  122. swap-storage: true
  123. # Forked repos can't push to GHCR, so we need to download the image as an artifact
  124. - name: Download runtime image for fork
  125. if: github.event.pull_request.head.repo.fork
  126. uses: actions/download-artifact@v4
  127. with:
  128. name: runtime-${{ matrix.base_image }}
  129. path: /tmp
  130. - name: Load runtime image for fork
  131. if: github.event.pull_request.head.repo.fork
  132. run: |
  133. docker load --input /tmp/runtime-${{ matrix.base_image }}.tar
  134. - name: Cache Poetry dependencies
  135. uses: actions/cache@v4
  136. with:
  137. path: |
  138. ~/.cache/pypoetry
  139. ~/.virtualenvs
  140. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  141. restore-keys: |
  142. ${{ runner.os }}-poetry-
  143. - name: Set up Python
  144. uses: actions/setup-python@v5
  145. with:
  146. python-version: '3.11'
  147. - name: Install poetry via pipx
  148. run: pipx install poetry
  149. - name: Install Python dependencies using Poetry
  150. run: make install-python-dependencies
  151. - name: Run runtime tests
  152. run: |
  153. # We install pytest-xdist in order to run tests across CPUs. However, tests start to fail when we run
  154. # then across more than 2 CPUs for some reason
  155. poetry run pip install pytest-xdist
  156. # Install to be able to retry on failures for flaky tests
  157. poetry run pip install pytest-rerunfailures
  158. image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
  159. image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
  160. TEST_RUNTIME=eventstream \
  161. SANDBOX_USER_ID=$(id -u) \
  162. SANDBOX_BASE_CONTAINER_IMAGE=$image_name \
  163. TEST_IN_CI=true \
  164. poetry run pytest -n 2 --reruns 2 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime
  165. - name: Upload coverage to Codecov
  166. uses: codecov/codecov-action@v4
  167. env:
  168. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  169. # Run integration tests with the eventstream runtime Docker image
  170. runtime_integration_tests_on_linux:
  171. name: Runtime Integration Tests on Linux
  172. runs-on: ubuntu-latest
  173. needs: [ghcr_build_runtime]
  174. strategy:
  175. fail-fast: false
  176. matrix:
  177. base_image: ['nikolaik']
  178. steps:
  179. - uses: actions/checkout@v4
  180. # Forked repos can't push to GHCR, so we need to download the image as an artifact
  181. - name: Download runtime image for fork
  182. if: github.event.pull_request.head.repo.fork
  183. uses: actions/download-artifact@v4
  184. with:
  185. name: runtime-${{ matrix.base_image }}
  186. path: /tmp
  187. - name: Load runtime image for fork
  188. if: github.event.pull_request.head.repo.fork
  189. run: |
  190. docker load --input /tmp/runtime-${{ matrix.base_image }}.tar
  191. - name: Cache Poetry dependencies
  192. uses: actions/cache@v4
  193. with:
  194. path: |
  195. ~/.cache/pypoetry
  196. ~/.virtualenvs
  197. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  198. restore-keys: |
  199. ${{ runner.os }}-poetry-
  200. - name: Set up Python
  201. uses: actions/setup-python@v5
  202. with:
  203. python-version: '3.11'
  204. - name: Install poetry via pipx
  205. run: pipx install poetry
  206. - name: Install Python dependencies using Poetry
  207. run: make install-python-dependencies
  208. - name: Run integration tests
  209. run: |
  210. image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
  211. image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
  212. TEST_RUNTIME=eventstream \
  213. SANDBOX_USER_ID=$(id -u) \
  214. SANDBOX_BASE_CONTAINER_IMAGE=$image_name \
  215. TEST_IN_CI=true \
  216. TEST_ONLY=true \
  217. ./tests/integration/regenerate.sh
  218. - name: Upload coverage to Codecov
  219. uses: codecov/codecov-action@v4
  220. env:
  221. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  222. # The two following jobs (named identically) are to check whether all the runtime tests have passed as the
  223. # "All Runtime Tests Passed" is a required job for PRs to merge
  224. # Due to this bug: https://github.com/actions/runner/issues/2566, we want to create a job that runs when the
  225. # prerequisites have been cancelled or failed so merging is disallowed, otherwise Github considers "skipped" as "success"
  226. runtime_tests_check_success:
  227. name: All Runtime Tests Passed
  228. if: ${{ !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
  229. runs-on: ubuntu-latest
  230. needs: [test_runtime, runtime_integration_tests_on_linux]
  231. steps:
  232. - name: All tests passed
  233. run: echo "All runtime tests have passed successfully!"
  234. runtime_tests_check_fail:
  235. name: All Runtime Tests Passed
  236. if: ${{ cancelled() || contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
  237. runs-on: ubuntu-latest
  238. needs: [test_runtime, runtime_integration_tests_on_linux]
  239. steps:
  240. - name: Some tests failed
  241. run: |
  242. echo "Some runtime tests failed or were cancelled"
  243. exit 1