py-unit-tests-mac.yml 3.1 KB

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