run-unit-tests.yml 4.6 KB

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