py-unit-tests.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Workflow that runs python unit tests
  2. name: Run Python Unit Tests
  3. # The jobs in this workflow are required, so they must run at all times
  4. # * Always run on "main"
  5. # * Always run on PRs
  6. on:
  7. push:
  8. branches:
  9. - main
  10. pull_request:
  11. jobs:
  12. # Run python unit tests on macOS
  13. test-on-macos:
  14. name: Python Unit Tests on macOS
  15. runs-on: macos-12
  16. env:
  17. INSTALL_DOCKER: '1' # Set to '0' to skip Docker installation
  18. strategy:
  19. matrix:
  20. python-version: ['3.12']
  21. steps:
  22. - uses: actions/checkout@v4
  23. - name: Set up Python ${{ matrix.python-version }}
  24. uses: actions/setup-python@v5
  25. with:
  26. python-version: ${{ matrix.python-version }}
  27. - name: Cache Poetry dependencies
  28. uses: actions/cache@v4
  29. with:
  30. path: |
  31. ~/.cache/pypoetry
  32. ~/.virtualenvs
  33. key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
  34. restore-keys: |
  35. ${{ runner.os }}-poetry-
  36. - name: Install poetry via pipx
  37. run: pipx install poetry
  38. - name: Install Python dependencies using Poetry
  39. run: poetry install --without evaluation,llama-index
  40. - name: Install & Start Docker
  41. if: env.INSTALL_DOCKER == '1'
  42. run: |
  43. INSTANCE_NAME="colima-${GITHUB_RUN_ID}"
  44. # Uninstall colima to upgrade to the latest version
  45. if brew list colima &>/dev/null; then
  46. brew uninstall colima
  47. # unlinking colima dependency: go
  48. brew uninstall go@1.21
  49. fi
  50. rm -rf ~/.colima ~/.lima
  51. brew install --HEAD colima
  52. brew install docker
  53. start_colima() {
  54. # Find a free port in the range 10000-20000
  55. RANDOM_PORT=$((RANDOM % 10001 + 10000))
  56. # Original line:
  57. if ! colima start --network-address --arch x86_64 --cpu=1 --memory=1 --verbose --ssh-port $RANDOM_PORT; then
  58. echo "Failed to start Colima."
  59. return 1
  60. fi
  61. return 0
  62. }
  63. # Attempt to start Colima for 5 total attempts:
  64. ATTEMPT_LIMIT=5
  65. for ((i=1; i<=ATTEMPT_LIMIT; i++)); do
  66. if start_colima; then
  67. echo "Colima started successfully."
  68. break
  69. else
  70. colima stop -f
  71. sleep 10
  72. colima delete -f
  73. if [ $i -eq $ATTEMPT_LIMIT ]; then
  74. exit 1
  75. fi
  76. sleep 10
  77. fi
  78. done
  79. # For testcontainers to find the Colima socket
  80. # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running
  81. sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
  82. - name: Build Environment
  83. run: make build
  84. - name: Set up Docker Buildx
  85. id: buildx
  86. uses: docker/setup-buildx-action@v3
  87. - name: Run Tests
  88. run: poetry run pytest --forked --cov=openhands --cov-report=xml ./tests/unit --ignore=tests/unit/test_memory.py
  89. - name: Upload coverage to Codecov
  90. uses: codecov/codecov-action@v4
  91. env:
  92. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  93. # Run python unit tests on Linux
  94. test-on-linux:
  95. name: Python Unit Tests on Linux
  96. runs-on: ubuntu-latest
  97. env:
  98. INSTALL_DOCKER: '0' # Set to '0' to skip Docker installation
  99. strategy:
  100. matrix:
  101. python-version: ['3.12']
  102. steps:
  103. - uses: actions/checkout@v4
  104. - name: Set up Docker Buildx
  105. id: buildx
  106. uses: docker/setup-buildx-action@v3
  107. - name: Install poetry via pipx
  108. run: pipx install poetry
  109. - name: Set up Python
  110. uses: actions/setup-python@v5
  111. with:
  112. python-version: ${{ matrix.python-version }}
  113. cache: 'poetry'
  114. - name: Install Python dependencies using Poetry
  115. run: poetry install --without evaluation,llama-index
  116. - name: Build Environment
  117. run: make build
  118. - name: Run Tests
  119. run: poetry run pytest --forked --cov=openhands --cov-report=xml -svv ./tests/unit --ignore=tests/unit/test_memory.py
  120. - name: Upload coverage to Codecov
  121. uses: codecov/codecov-action@v4
  122. env:
  123. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}