ghcr_runtime.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. # Workflow that builds, tests and then pushes the runtime docker images to the ghcr.io repository
  2. name: Build, Test and Publish RT 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 as root
  104. test_runtime_root:
  105. name: RT Unit Tests (Root)
  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. # Forked repos can't push to GHCR, so we need to download the image as an artifact
  115. - name: Download runtime image for fork
  116. if: github.event.pull_request.head.repo.fork
  117. uses: actions/download-artifact@v4
  118. with:
  119. name: runtime-${{ matrix.base_image }}
  120. path: /tmp
  121. - name: Load runtime image for fork
  122. if: github.event.pull_request.head.repo.fork
  123. run: |
  124. docker load --input /tmp/runtime-${{ matrix.base_image }}.tar
  125. - name: Cache Poetry dependencies
  126. uses: actions/cache@v4
  127. with:
  128. path: |
  129. ~/.cache/pypoetry
  130. ~/.virtualenvs
  131. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  132. restore-keys: |
  133. ${{ runner.os }}-poetry-
  134. - name: Set up Python
  135. uses: actions/setup-python@v5
  136. with:
  137. python-version: '3.11'
  138. - name: Install poetry via pipx
  139. run: pipx install poetry
  140. - name: Install Python dependencies using Poetry
  141. run: make install-python-dependencies
  142. - name: Run runtime tests
  143. run: |
  144. # We install pytest-xdist in order to run tests across CPUs. However, tests start to fail when we run
  145. # then across more than 2 CPUs for some reason
  146. poetry run pip install pytest-xdist
  147. # Install to be able to retry on failures for flaky tests
  148. poetry run pip install pytest-rerunfailures
  149. image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
  150. image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
  151. SKIP_CONTAINER_LOGS=true \
  152. TEST_RUNTIME=eventstream \
  153. SANDBOX_USER_ID=$(id -u) \
  154. SANDBOX_BASE_CONTAINER_IMAGE=$image_name \
  155. TEST_IN_CI=true \
  156. RUN_AS_OPENHANDS=false \
  157. poetry run pytest -n 3 --reruns 1 --reruns-delay 3 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime
  158. - name: Upload coverage to Codecov
  159. uses: codecov/codecov-action@v4
  160. env:
  161. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  162. # Run unit tests with the EventStream runtime Docker images as openhands user
  163. test_runtime_oh:
  164. name: RT Unit Tests (openhands)
  165. runs-on: ubuntu-latest
  166. needs: [ghcr_build_runtime]
  167. strategy:
  168. matrix:
  169. base_image: ['nikolaik']
  170. steps:
  171. - uses: actions/checkout@v4
  172. # Forked repos can't push to GHCR, so we need to download the image as an artifact
  173. - name: Download runtime image for fork
  174. if: github.event.pull_request.head.repo.fork
  175. uses: actions/download-artifact@v4
  176. with:
  177. name: runtime-${{ matrix.base_image }}
  178. path: /tmp
  179. - name: Load runtime image for fork
  180. if: github.event.pull_request.head.repo.fork
  181. run: |
  182. docker load --input /tmp/runtime-${{ matrix.base_image }}.tar
  183. - name: Cache Poetry dependencies
  184. uses: actions/cache@v4
  185. with:
  186. path: |
  187. ~/.cache/pypoetry
  188. ~/.virtualenvs
  189. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  190. restore-keys: |
  191. ${{ runner.os }}-poetry-
  192. - name: Set up Python
  193. uses: actions/setup-python@v5
  194. with:
  195. python-version: '3.11'
  196. - name: Install poetry via pipx
  197. run: pipx install poetry
  198. - name: Install Python dependencies using Poetry
  199. run: make install-python-dependencies
  200. - name: Run runtime tests
  201. run: |
  202. # We install pytest-xdist in order to run tests across CPUs. However, tests start to fail when we run
  203. # then across more than 2 CPUs for some reason
  204. poetry run pip install pytest-xdist
  205. # Install to be able to retry on failures for flaky tests
  206. poetry run pip install pytest-rerunfailures
  207. image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
  208. image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
  209. SKIP_CONTAINER_LOGS=true \
  210. TEST_RUNTIME=eventstream \
  211. SANDBOX_USER_ID=$(id -u) \
  212. SANDBOX_BASE_CONTAINER_IMAGE=$image_name \
  213. TEST_IN_CI=true \
  214. RUN_AS_OPENHANDS=true \
  215. poetry run pytest -n 3 --reruns 1 --reruns-delay 3 --cov=agenthub --cov=openhands --cov-report=xml -s ./tests/runtime
  216. - name: Upload coverage to Codecov
  217. uses: codecov/codecov-action@v4
  218. env:
  219. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  220. # Run integration tests with the eventstream runtime Docker image
  221. runtime_integration_tests_on_linux:
  222. name: RT Integration Tests (Linux)
  223. runs-on: ubuntu-latest
  224. needs: [ghcr_build_runtime]
  225. strategy:
  226. fail-fast: false
  227. matrix:
  228. base_image: ['nikolaik']
  229. steps:
  230. - uses: actions/checkout@v4
  231. # Forked repos can't push to GHCR, so we need to download the image as an artifact
  232. - name: Download runtime image for fork
  233. if: github.event.pull_request.head.repo.fork
  234. uses: actions/download-artifact@v4
  235. with:
  236. name: runtime-${{ matrix.base_image }}
  237. path: /tmp
  238. - name: Load runtime image for fork
  239. if: github.event.pull_request.head.repo.fork
  240. run: |
  241. docker load --input /tmp/runtime-${{ matrix.base_image }}.tar
  242. - name: Cache Poetry dependencies
  243. uses: actions/cache@v4
  244. with:
  245. path: |
  246. ~/.cache/pypoetry
  247. ~/.virtualenvs
  248. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  249. restore-keys: |
  250. ${{ runner.os }}-poetry-
  251. - name: Set up Python
  252. uses: actions/setup-python@v5
  253. with:
  254. python-version: '3.11'
  255. - name: Install poetry via pipx
  256. run: pipx install poetry
  257. - name: Install Python dependencies using Poetry
  258. run: make install-python-dependencies
  259. - name: Run integration tests
  260. run: |
  261. image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }}
  262. image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]')
  263. TEST_RUNTIME=eventstream \
  264. SANDBOX_USER_ID=$(id -u) \
  265. SANDBOX_BASE_CONTAINER_IMAGE=$image_name \
  266. TEST_IN_CI=true \
  267. TEST_ONLY=true \
  268. ./tests/integration/regenerate.sh
  269. - name: Upload coverage to Codecov
  270. uses: codecov/codecov-action@v4
  271. env:
  272. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  273. # The two following jobs (named identically) are to check whether all the runtime tests have passed as the
  274. # "All Runtime Tests Passed" is a required job for PRs to merge
  275. # Due to this bug: https://github.com/actions/runner/issues/2566, we want to create a job that runs when the
  276. # prerequisites have been cancelled or failed so merging is disallowed, otherwise Github considers "skipped" as "success"
  277. runtime_tests_check_success:
  278. name: All Runtime Tests Passed
  279. if: ${{ !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
  280. runs-on: ubuntu-latest
  281. needs: [test_runtime_root, test_runtime_oh, runtime_integration_tests_on_linux]
  282. steps:
  283. - name: All tests passed
  284. run: echo "All runtime tests have passed successfully!"
  285. runtime_tests_check_fail:
  286. name: All Runtime Tests Passed
  287. if: ${{ cancelled() || contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
  288. runs-on: ubuntu-latest
  289. needs: [test_runtime_root, test_runtime_oh, runtime_integration_tests_on_linux]
  290. steps:
  291. - name: Some tests failed
  292. run: |
  293. echo "Some runtime tests failed or were cancelled"
  294. exit 1