run-unit-tests.yml 4.5 KB

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