Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

ci: shard API unit tests across runners (#42374)

Stephen Zhoue58e5b087986
diff --git a/.github/workflows/api-tests.yml b/.github/workflows/api-tests.yml
index f579862eb8b..1e0d0b8f541 100644
--- a/.github/workflows/api-tests.yml
+++ b/.github/workflows/api-tests.yml
@@ -15,23 +15,30 @@ concurrency:
jobs:
api-unit:
- name: API Unit Tests
+ name: API Unit Tests (${{ matrix.python-version }}, shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }})
runs-on: depot-ubuntu-24.04
env:
- COVERAGE_FILE: coverage-unit
+ COVERAGE_FILE: coverage-unit-${{ matrix.python-version }}-${{ matrix.shardIndex }}
defaults:
run:
shell: bash
strategy:
+ fail-fast: false
matrix:
python-version:
- '3.12'
+ shardIndex:
+ - 1
+ - 2
+ - 3
+ - 4
+ shardTotal:
+ - 4
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- fetch-depth: 0
persist-credentials: false
- name: Setup UV and Python
@@ -53,6 +60,10 @@ jobs:
-p no:benchmark \
--timeout "${PYTEST_TIMEOUT:-20}" \
-n auto \
+ --shard-index "${{ matrix.shardIndex }}" \
+ --shard-total "${{ matrix.shardTotal }}" \
+ -o 'addopts=--cov=./api --cov-branch --import-mode=importlib' \
+ --cov-report= \
api/tests/unit_tests \
api/providers/vdb/*/tests/unit_tests \
api/providers/trace/*/tests/unit_tests \
@@ -60,14 +71,19 @@ jobs:
# Controller tests register Flask routes at import time, so keep them out of xdist.
uv run --project api pytest \
--timeout "${PYTEST_TIMEOUT:-20}" \
+ --shard-index "${{ matrix.shardIndex }}" \
+ --shard-total "${{ matrix.shardTotal }}" \
+ -o 'addopts=--cov=./api --cov-branch --import-mode=importlib' \
+ --cov-report= \
--cov-append \
api/tests/unit_tests/controllers
- name: Upload unit coverage data
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
- name: api-coverage-unit
- path: coverage-unit
+ name: api-coverage-unit-${{ matrix.python-version }}-${{ matrix.shardIndex }}
+ path: ${{ env.COVERAGE_FILE }}
+ if-no-files-found: error
retention-days: 1
api-integration:
@@ -98,7 +114,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- fetch-depth: 0
persist-credentials: false
- name: Setup UV and Python
@@ -122,6 +137,8 @@ jobs:
-n auto \
--shard-index "${{ matrix.shardIndex }}" \
--shard-total "${{ matrix.shardTotal }}" \
+ -o 'addopts=--cov=./api --cov-branch --import-mode=importlib' \
+ --cov-report= \
--timeout "${PYTEST_TIMEOUT:-180}" \
api/tests/integration_tests/workflow \
api/tests/integration_tests/tools \
@@ -181,16 +198,19 @@ jobs:
echo "Merged backend coverage report generated for Codecov project status." >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
- unit_coverage="$(find coverage-data -type f -name coverage-unit -print -quit)"
+ mapfile -t unit_coverage < <(find coverage-data -type f -name 'coverage-unit-*' -print | sort)
mapfile -t integration_coverage < <(find coverage-data -type f -name 'coverage-integration-*' -print | sort)
- : "${unit_coverage:?coverage-unit artifact not found}"
+ if [[ "${#unit_coverage[@]}" -ne 4 ]]; then
+ echo "expected 4 unit coverage artifacts, found ${#unit_coverage[@]}" >&2
+ exit 1
+ fi
if [[ "${#integration_coverage[@]}" -ne 4 ]]; then
echo "expected 4 integration coverage artifacts, found ${#integration_coverage[@]}" >&2
exit 1
fi
report_file="$(mktemp)"
- uv run --project api coverage combine "$unit_coverage" "${integration_coverage[@]}"
+ uv run --project api coverage combine "${unit_coverage[@]}" "${integration_coverage[@]}"
uv run --project api coverage report --show-missing | tee "$report_file"
echo "Summary: \`$(tail -n 1 "$report_file")\`" >> "$GITHUB_STEP_SUMMARY"
{