Skip to content

doc: 修改构建知识库提示文案 #194

doc: 修改构建知识库提示文案

doc: 修改构建知识库提示文案 #194

Workflow file for this run

name: Essential tests
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
branches: [master]
jobs:
vitest:
name: Vitest - renderer main
runs-on: ubuntu-latest
steps:
- name: Display incoming configuration parameters
run: echo ${{ inputs.platform }} ${{ inputs.legacy }} ${{ inputs.version }} ${{ inputs.engine }} ${{ inputs.engineVersion }} ${{ inputs.devTool }}
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.11.0
cache: "yarn"
cache-dependency-path: |
yarn.lock
app/renderer/src/main/yarn.lock
app/renderer/engine-link-startup/yarn.lock
- name: Install dependencies (root)
# if: steps.node-mod-cache.outputs.cache-hit != 'true'
working-directory: .
run: yarn install --prefer-offline --network-concurrency 1
- name: Install dependencies (renderer main)
working-directory: app/renderer/src/main
run: yarn install --prefer-offline --network-concurrency 1
- name: Install dependencies (engine-link-startup)
working-directory: app/renderer/engine-link-startup
run: yarn install --prefer-offline --network-concurrency 1
- name: Skip install (node_modules cache hit)
# if: steps.node-mod-cache.outputs.cache-hit == 'true'
run: echo "node_modules cache restored; skipping yarn install"
- name: Verify installed packages (quick)
working-directory: .
run: |
echo "Yarn cache dir: $(yarn cache dir)"
ls -la node_modules | head -n 20 || true
- name: Debug - list candidate test files
working-directory: .
run: |
echo "pwd: $(pwd)"
echo "node: $(node -v) yarn: $(yarn -v)"
echo "Find test/spec files (up to depth 6):"
find . -maxdepth 6 -type f \( -name "*.test.*" -o -name "*.spec.*" \) -print || true
echo "Show renderer playground folder (if exists):"
ls -la app/renderer/src/main/src/components/playground/Vitest__Test__ || true
- name: Determine relevant test files
id: test_selection
working-directory: .
shell: bash
run: |
# Get files changed in the PR. Use multiple fallbacks because the runner
# may have a shallow checkout and referenced commits might not exist.
CHANGED=""
# If manually triggered with inputs.tests, prefer that and exit early
if [ -n "${{ github.event.inputs.tests }}" ]; then
echo "Using manual input tests: ${{ github.event.inputs.tests }}"
echo "tests=${{ github.event.inputs.tests }}" >> $GITHUB_OUTPUT
exit 0
fi
# 1) Try the standard range if both commits are present
if git rev-parse --verify "${{ github.event.before }}" >/dev/null 2>&1 && git rev-parse --verify "${{ github.sha }}" >/dev/null 2>&1; then
CHANGED=$(git diff --name-only "${{ github.event.before }}" "${{ github.sha }}" || true)
fi
# 2) If still empty, try fetching the base branch (for PRs) and compare
if [ -z "$CHANGED" ] && [ -n "${{ github.event.pull_request.base.ref }}" ]; then
echo "Standard range not available — fetching base branch ${{ github.event.pull_request.base.ref }}"
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.ref }}" || true
BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
CHANGED=$(git diff --name-only "$BASE_REF" "${{ github.sha }}" || true)
fi
# 3) Final fallback: use files from the last commit(s)
if [ -z "$CHANGED" ]; then
echo "Falling back to last commit changes"
CHANGED=$(git diff --name-only HEAD^ HEAD || git show --name-only --pretty= "" "${{ github.sha }}" || true)
fi
echo "Changed files:\n$CHANGED"
# Normalize changed paths to be relative to the repository root
CHANGED_REL=$(printf "%s\n" "$CHANGED" | sed 's|^\./||' | sort -u || true)
# remove empty lines
CHANGED_REL=$(printf "%s\n" "$CHANGED_REL" | sed '/^$/d' || true)
echo "Normalized changes:\n$CHANGED_REL"
# Prefer explicitly changed test files (paths under repo root)
TEST_FILES=$(printf "%s\n" "$CHANGED_REL" | grep -E '.*\.(test|spec)\.(ts|tsx|js|jsx)' || true)
if [ -n "$TEST_FILES" ]; then
TF=$(echo "$TEST_FILES" | tr '\n' ' ')
echo "Found test files: $TF"
echo "tests=$TF" >> $GITHUB_OUTPUT
exit 0
fi
# Otherwise, for each changed file/dir try to find nearby __tests__ folders
# and only run tests that actually exist. This avoids running tests when
# none were written for the changed code.
DIRS=$(printf "%s\n" "$CHANGED_REL" | xargs -I{} dirname {} 2>/dev/null | sort -u || true)
TEST_PATTERNS=()
if [ -n "$DIRS" ]; then
# enable globstar for ** expansion
shopt -s globstar nullglob || true
for d in $DIRS; do
# candidate test directories relative to changed dir
candidates=("$d/__tests__" "$d/src/__tests__")
# also consider mapping src/** -> src/__tests__
if [[ "$d" == *"/src"* ]]; then
base=${d%%/src*}
candidates+=("$base/src/__tests__")
fi
for c in "${candidates[@]}"; do
# look for test files under candidate
found=( $c/**/*.test.* $c/**/*.spec.* )
if [ ${#found[@]} -gt 0 ]; then
# add glob pattern for this candidate
TEST_PATTERNS+=("$c/**/*.test.*" "$c/**/*.spec.*")
fi
done
done
fi
if [ ${#TEST_PATTERNS[@]} -gt 0 ]; then
# dedupe and join
patterns=$(printf "%s\n" "${TEST_PATTERNS[@]}" | sort -u | tr '\n' ' ')
echo "Discovered test patterns: $patterns"
echo "tests=$patterns" >> $GITHUB_OUTPUT
exit 0
fi
echo "No relevant tests found to run"
echo "tests=none" >> $GITHUB_OUTPUT
- name: Run Vitest (root)
# run from repo root so root-level script `test:vitest` is available
working-directory: .
env:
CI: true
run: |
TESTS="${{ steps.test_selection.outputs.tests }}"
if [ "$TESTS" = "none" ]; then
echo "No relevant tests changed, skipping vitest"
exit 0
fi
echo "Running tests: $TESTS"
# enable glob expansion so ** patterns from TESTS are resolved in CI
shopt -s globstar nullglob
# expand patterns to actual files before passing to vitest
EXPANDED_TESTS=$(eval echo $TESTS)
echo "Expanded tests: $EXPANDED_TESTS"
yarn test:vitest $EXPANDED_TESTS --run --reporter verbose