py-unit-tests.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.11']
  21. steps:
  22. - uses: actions/checkout@v4
  23. - name: Install poetry via pipx
  24. run: pipx install poetry
  25. - name: Set up Python ${{ matrix.python-version }}
  26. uses: actions/setup-python@v5
  27. with:
  28. python-version: ${{ matrix.python-version }}
  29. cache: 'poetry'
  30. - name: Install Python dependencies using Poetry
  31. run: poetry install --without evaluation,llama-index
  32. - name: Install & Start Docker
  33. if: env.INSTALL_DOCKER == '1'
  34. run: |
  35. INSTANCE_NAME="colima-${GITHUB_RUN_ID}"
  36. # Uninstall colima to upgrade to the latest version
  37. if brew list colima &>/dev/null; then
  38. brew uninstall colima
  39. # unlinking colima dependency: go
  40. brew uninstall go@1.21
  41. fi
  42. rm -rf ~/.colima ~/.lima
  43. brew install --HEAD colima
  44. brew install docker
  45. start_colima() {
  46. # Find a free port in the range 10000-20000
  47. RANDOM_PORT=$((RANDOM % 10001 + 10000))
  48. # Original line:
  49. if ! colima start --network-address --arch x86_64 --cpu=1 --memory=1 --verbose --ssh-port $RANDOM_PORT; then
  50. echo "Failed to start Colima."
  51. return 1
  52. fi
  53. return 0
  54. }
  55. # Attempt to start Colima for 5 total attempts:
  56. ATTEMPT_LIMIT=5
  57. for ((i=1; i<=ATTEMPT_LIMIT; i++)); do
  58. if start_colima; then
  59. echo "Colima started successfully."
  60. break
  61. else
  62. colima stop -f
  63. sleep 10
  64. colima delete -f
  65. if [ $i -eq $ATTEMPT_LIMIT ]; then
  66. exit 1
  67. fi
  68. sleep 10
  69. fi
  70. done
  71. # For testcontainers to find the Colima socket
  72. # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running
  73. sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
  74. - name: Build Environment
  75. run: make build
  76. - name: Run Tests
  77. run: poetry run pytest --forked --cov=agenthub --cov=openhands --cov-report=xml ./tests/unit
  78. - name: Upload coverage to Codecov
  79. uses: codecov/codecov-action@v4
  80. env:
  81. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  82. # Run python unit tests on Linux
  83. test-on-linux:
  84. name: Python Unit Tests on Linux
  85. runs-on: ubuntu-latest
  86. env:
  87. INSTALL_DOCKER: '0' # Set to '0' to skip Docker installation
  88. strategy:
  89. matrix:
  90. python-version: ['3.11']
  91. steps:
  92. - uses: actions/checkout@v4
  93. - name: Install poetry via pipx
  94. run: pipx install poetry
  95. - name: Set up Python
  96. uses: actions/setup-python@v5
  97. with:
  98. python-version: ${{ matrix.python-version }}
  99. cache: 'poetry'
  100. - name: Install Python dependencies using Poetry
  101. run: poetry install --without evaluation,llama-index
  102. - name: Build Environment
  103. run: make build
  104. - name: Run Tests
  105. run: poetry run pytest --forked --cov=agenthub --cov=openhands --cov-report=xml ./tests/unit
  106. - name: Upload coverage to Codecov
  107. uses: codecov/codecov-action@v4
  108. env:
  109. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}