test-parallel.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. name: Parallel Tests
  2. on:
  3. pull_request:
  4. branches: [dev, main, master]
  5. push:
  6. branches: [dev]
  7. env:
  8. PYTHONIOENCODING: utf-8
  9. PYTHONLEGACYWINDOWSSTDIO: utf-8
  10. USE_COLOR: False
  11. jobs:
  12. discover-tests:
  13. name: Discover test files
  14. runs-on: ubuntu-22.04
  15. outputs:
  16. test-files: ${{ steps.set-matrix.outputs.test-files }}
  17. steps:
  18. - uses: actions/checkout@v4
  19. with:
  20. submodules: true
  21. fetch-depth: 1
  22. - name: Discover test files
  23. id: set-matrix
  24. run: |
  25. # Find all main test files
  26. main_tests=$(find tests -maxdepth 1 -name "test_*.py" -type f | sort)
  27. # Find all plugin test files
  28. plugin_tests=$(find archivebox/plugins -path "*/tests/test_*.py" -type f | sort)
  29. # Combine and format as JSON array
  30. all_tests=$(echo "$main_tests $plugin_tests" | tr ' ' '\n' | grep -v '^$')
  31. # Create JSON array with test file info
  32. json_array="["
  33. first=true
  34. for test_file in $all_tests; do
  35. if [ "$first" = true ]; then
  36. first=false
  37. else
  38. json_array+=","
  39. fi
  40. # Extract a display name for the test
  41. if [[ $test_file == tests/* ]]; then
  42. name="main/$(basename $test_file .py | sed 's/^test_//')"
  43. else
  44. plugin=$(echo $test_file | sed 's|archivebox/plugins/\([^/]*\)/.*|\1|')
  45. test_name=$(basename $test_file .py | sed 's/^test_//')
  46. name="plugin/$plugin/$test_name"
  47. fi
  48. json_array+="{\"path\":\"$test_file\",\"name\":\"$name\"}"
  49. done
  50. json_array+="]"
  51. echo "test-files=$json_array" >> $GITHUB_OUTPUT
  52. echo "Found $(echo $all_tests | wc -w) test files"
  53. echo "$json_array" | jq '.'
  54. run-tests:
  55. name: ${{ matrix.test.name }}
  56. runs-on: ubuntu-22.04
  57. needs: discover-tests
  58. strategy:
  59. fail-fast: false
  60. matrix:
  61. test: ${{ fromJson(needs.discover-tests.outputs.test-files) }}
  62. python: ["3.13"]
  63. steps:
  64. - uses: actions/checkout@v4
  65. with:
  66. submodules: true
  67. fetch-depth: 1
  68. - name: Set up Python ${{ matrix.python }}
  69. uses: actions/setup-python@v4
  70. with:
  71. python-version: ${{ matrix.python }}
  72. architecture: x64
  73. - name: Install uv
  74. uses: astral-sh/setup-uv@v4
  75. with:
  76. version: "latest"
  77. - name: Set up Node JS
  78. uses: actions/setup-node@v4
  79. with:
  80. node-version: 22
  81. - name: Cache uv
  82. uses: actions/cache@v3
  83. with:
  84. path: ~/.cache/uv
  85. key: ${{ runner.os }}-${{ matrix.python }}-uv-${{ hashFiles('pyproject.toml', 'uv.lock') }}
  86. restore-keys: |
  87. ${{ runner.os }}-${{ matrix.python }}-uv-
  88. - uses: awalsh128/cache-apt-pkgs-action@latest
  89. with:
  90. packages: git ripgrep build-essential python3-dev python3-setuptools libssl-dev libldap2-dev libsasl2-dev zlib1g-dev libatomic1 python3-minimal gnupg2 curl wget python3-ldap python3-msgpack python3-mutagen python3-regex python3-pycryptodome procps
  91. version: 1.1
  92. - name: Install dependencies with uv
  93. run: |
  94. uv sync --dev --all-extras
  95. - name: Run test - ${{ matrix.test.name }}
  96. run: |
  97. uv run pytest -xvs "${{ matrix.test.path }}" --basetemp=tests/out --ignore=archivebox/pkgs