run-unit-tests.yml 4.7 KB

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