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.

chore(ci): speed up E2E preparation and API coverage reporting (#42549)

Stephen Zhou3a88bc70a301
diff --git a/.github/actions/setup-core-e2e/action.yml b/.github/actions/setup-core-e2e/action.yml
new file mode 100644
index 00000000000..209b45902cc
--- /dev/null
+++ b/.github/actions/setup-core-e2e/action.yml
@@ -0,0 +1,29 @@
+name: Setup Core E2E Dependencies
+description: Install API dependencies alongside web dependencies and the selected browser
+
+inputs:
+ browser:
+ description: Browser to install (chromium or webkit)
+ required: true
+
+runs:
+ using: composite
+ steps:
+ - name: Setup web toolchain
+ uses: ./.github/actions/setup-web
+ with:
+ run-install: 'false'
+
+ - name: Setup UV and Python
+ uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
+ with:
+ enable-cache: true
+ python-version: '3.12'
+ cache-dependency-glob: api/uv.lock
+
+ - name: Install dependencies in parallel
+ shell: bash
+ env:
+ E2E_INSTALL_BROWSER: ${{ inputs.browser }}
+ E2E_SETUP_ACTION_PATH: ${{ github.action_path }}
+ run: bash "$E2E_SETUP_ACTION_PATH/install.sh"
diff --git a/.github/actions/setup-core-e2e/install.sh b/.github/actions/setup-core-e2e/install.sh
new file mode 100755
index 00000000000..42270d3f18d
--- /dev/null
+++ b/.github/actions/setup-core-e2e/install.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+case "${E2E_INSTALL_BROWSER:-}" in
+ chromium|webkit) ;;
+ *) echo "Expected chromium or webkit" >&2; exit 1 ;;
+esac
+
+# Keep both branches in this step so failures are collected before tests start.
+started=$SECONDS
+timing_dir=$(mktemp -d)
+trap 'rm -rf "$timing_dir"' EXIT
+
+(
+ api_started=$SECONDS
+ uv sync --project api --dev
+ echo "$((SECONDS - api_started))" > "$timing_dir/api"
+) &
+api_pid=$!
+
+(
+ web_started=$SECONDS
+ vp install --frozen-lockfile
+ echo "$((SECONDS - web_started))" > "$timing_dir/web"
+ browser_started=$SECONDS
+ cd e2e
+ vp run "e2e:install:ci:$E2E_INSTALL_BROWSER"
+ echo "$((SECONDS - browser_started))" > "$timing_dir/browser"
+) &
+web_pid=$!
+
+api_status=0
+web_status=0
+wait "$api_pid" || api_status=$?
+wait "$web_pid" || web_status=$?
+
+{
+ echo "### E2E dependency preparation ($E2E_INSTALL_BROWSER)"
+ echo ""
+ echo "Parallel install wall time: $((SECONDS - started))s"
+ echo ""
+ echo "| Phase | Seconds |"
+ echo "| --- | ---: |"
+ for phase in api web browser; do
+ if [[ -f "$timing_dir/$phase" ]]; then
+ echo "| $phase | $(cat "$timing_dir/$phase") |"
+ fi
+ done
+ echo ""
+ echo "API exit status: $api_status; Web/browser exit status: $web_status"
+} >> "${GITHUB_STEP_SUMMARY:-/dev/null}"
+
+if (( api_status != 0 || web_status != 0 )); then
+ echo "E2E dependency installation failed (API: $api_status, Web/browser: $web_status)" >&2
+ exit 1
+fi
diff --git a/.github/actions/setup-web/action.yml b/.github/actions/setup-web/action.yml
index 1b52e263710..1c67d924778 100644
--- a/.github/actions/setup-web/action.yml
+++ b/.github/actions/setup-web/action.yml
@@ -1,6 +1,11 @@
name: Setup Web Environment
description: Set up Node.js, Vite+, pnpm, and web dependencies
+inputs:
+ run-install:
+ description: Install web dependencies after setting up the toolchain
+ default: 'true'
+
runs:
using: composite
steps:
@@ -16,4 +21,4 @@ runs:
pnpm: false
npm: false
cache: true
- run-install: true
+ run-install: ${{ inputs.run-install }}
diff --git a/.github/workflows/api-tests.yml b/.github/workflows/api-tests.yml
index 15c245ff4e9..4cb4a806ede 100644
--- a/.github/workflows/api-tests.yml
+++ b/.github/workflows/api-tests.yml
@@ -168,18 +168,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- fetch-depth: 0
persist-credentials: false
- name: Setup UV and Python
uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
with:
- enable-cache: true
python-version: '3.12'
- cache-dependency-glob: api/uv.lock
-
- - name: Install dependencies
- run: uv sync --project api --dev
- name: Download coverage data
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -191,11 +185,14 @@ jobs:
- name: Combine coverage
run: |
set -euo pipefail
+ coverage_version=$(python3 -c 'import tomllib; print(next(p["version"] for p in tomllib.load(open("api/uv.lock", "rb"))["package"] if p["name"] == "coverage"))')
- echo "### API Coverage" >> "$GITHUB_STEP_SUMMARY"
- echo "" >> "$GITHUB_STEP_SUMMARY"
- echo "Merged backend coverage report generated for Codecov project status." >> "$GITHUB_STEP_SUMMARY"
- echo "" >> "$GITHUB_STEP_SUMMARY"
+ {
+ echo "### API Coverage"
+ echo ""
+ echo "Merged backend coverage report generated for Codecov project status."
+ echo ""
+ } >> "$GITHUB_STEP_SUMMARY"
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)
@@ -209,8 +206,8 @@ jobs:
fi
report_file="$(mktemp)"
- uv run --project api coverage combine "${unit_coverage[@]}" "${integration_coverage[@]}"
- uv run --project api coverage report --show-missing | tee "$report_file"
+ uvx --from "coverage==$coverage_version" coverage combine "${unit_coverage[@]}" "${integration_coverage[@]}"
+ uvx --from "coverage==$coverage_version" coverage report --show-missing | tee "$report_file"
echo "Summary: \`$(tail -n 1 "$report_file")\`" >> "$GITHUB_STEP_SUMMARY"
{
echo ""
@@ -221,7 +218,7 @@ jobs:
echo '```'
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
- uv run --project api coverage xml -o coverage.xml
+ uvx --from "coverage==$coverage_version" coverage xml -o coverage.xml
- name: Report coverage
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml
index 438af8c96b9..902d8f23b28 100644
--- a/.github/workflows/main-ci.yml
+++ b/.github/workflows/main-ci.yml
@@ -111,6 +111,7 @@ jobs:
- '.github/workflows/web-e2e.yml'
- '.github/workflows/main-ci.yml'
- '.github/actions/setup-web/**'
+ - '.github/actions/setup-core-e2e/**'
vdb:
- 'api/core/rag/datasource/**'
- 'api/tests/integration_tests/vdb/**'
diff --git a/.github/workflows/web-e2e.yml b/.github/workflows/web-e2e.yml
index 5465d0d1001..4820047950e 100644
--- a/.github/workflows/web-e2e.yml
+++ b/.github/workflows/web-e2e.yml
@@ -24,9 +24,26 @@ jobs:
with:
persist-credentials: false
+ - name: Compute build source hash
+ id: build-source
+ shell: bash
+ run: |
+ # Hash tracked build inputs, excluding generated files and backend-only changes.
+ source_hash=$(git ls-tree -r HEAD -- web packages e2e/scripts e2e/package.json e2e/test-env.ts package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc .github/actions/setup-web .github/workflows/web-e2e.yml | sha256sum | cut -d ' ' -f 1)
+ echo "hash=$source_hash" >> "$GITHUB_OUTPUT"
+
- name: Setup web dependencies
uses: ./.github/actions/setup-web
+ - name: Restore Next.js build cache
+ id: next-cache
+ uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ with:
+ path: web/.next/cache
+ key: e2e-next-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml') }}-${{ steps.build-source.outputs.hash }}
+ restore-keys: |
+ e2e-next-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml') }}-
+
- name: Run E2E support unit tests
working-directory: ./e2e
run: vp run test:unit
@@ -35,7 +52,15 @@ jobs:
working-directory: ./e2e
env:
E2E_FORCE_WEB_BUILD: '1'
- run: vp run e2e:web:build
+ CACHE_HIT: ${{ steps.next-cache.outputs.cache-hit || 'false' }}
+ run: |
+ started=$SECONDS
+ vp run e2e:web:build
+ {
+ echo "### E2E Web build"
+ echo "Build: $((SECONDS - started))s"
+ echo "Exact cache hit: $CACHE_HIT (false can include a compatible fallback)"
+ } >> "$GITHUB_STEP_SUMMARY"
- name: Package Web build
run: >-
@@ -54,6 +79,13 @@ jobs:
overwrite: true
retention-days: 7
+ - name: Save Next.js build cache
+ if: github.event_name != 'merge_group' && steps.next-cache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ with:
+ path: web/.next/cache
+ key: ${{ steps.next-cache.outputs.cache-primary-key }}
+
chromium-full:
name: Chromium Full (${{ matrix.shard }}/3)
if: ${{ !inputs.run-external-runtime }}
@@ -76,18 +108,11 @@ jobs:
with:
persist-credentials: false
- - name: Setup web dependencies
- uses: ./.github/actions/setup-web
-
- - name: Setup UV and Python
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
+ - name: Prepare Chromium E2E dependencies
+ timeout-minutes: 15
+ uses: ./.github/actions/setup-core-e2e
with:
- enable-cache: true
- python-version: '3.12'
- cache-dependency-glob: api/uv.lock
-
- - name: Install API dependencies
- run: uv sync --project api --dev
+ browser: chromium
- name: Download Web build
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -97,11 +122,6 @@ jobs:
- name: Extract Web build
run: tar -xf e2e-web-build.tar -C web
- - name: Install Chromium
- timeout-minutes: 15
- working-directory: ./e2e
- run: vp run e2e:install:ci:chromium
-
- name: Run Chromium full shard
working-directory: ./e2e
run: vp run e2e:full -- --shard ${{ matrix.shard }}/3
@@ -146,18 +166,11 @@ jobs:
with:
persist-credentials: false
- - name: Setup web dependencies
- uses: ./.github/actions/setup-web
-
- - name: Setup UV and Python
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
+ - name: Prepare WebKit E2E dependencies
+ timeout-minutes: 15
+ uses: ./.github/actions/setup-core-e2e
with:
- enable-cache: true
- python-version: '3.12'
- cache-dependency-glob: api/uv.lock
-
- - name: Install API dependencies
- run: uv sync --project api --dev
+ browser: webkit
- name: Download Web build
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -167,11 +180,6 @@ jobs:
- name: Extract Web build
run: tar -xf e2e-web-build.tar -C web
- - name: Install WebKit
- timeout-minutes: 15
- working-directory: ./e2e
- run: vp run e2e:install:ci:webkit
-
- name: Run WebKit browser smoke
working-directory: ./e2e
run: vp run e2e:full -- --tags '@browser-smoke'