/
vshmidt
/
streamlit
Обзор
Документация
Войти
/
vshmidt
/
streamlit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
.github/workflows/playwright-changed-files.yml
226 строк
9 KB
Lukas Masuch
Fix playwright-changed-files workflow to handle no tests collected (#13813)
04 фев 2026, 19:37
Не верифицирован
04 фев 2026, 19:37
a82f528
Код
Авторство
О чём код?
name: Playwright E2E Tests - Changed Files on: pull_request: types: [opened, synchronize, reopened] paths-ignore: # Don't run CI if changes are only in documentation/spec folders: - "specs/**" - "agent-knowledge/**" - "wiki/**" workflow_call: inputs: ref: description: Git ref (branch, SHA) or PR merge ref to checkout required: false type: string default: "" base_ref: description: Base branch/SHA to compare against (e.g., develop, commit SHA, or parent in stack) required: false type: string default: "develop" iteration: description: Iteration number for matrix runs (used for unique concurrency groups) required: false type: string default: "" workflow_dispatch: inputs: ref: description: Git ref (branch, SHA) or PR merge ref to checkout required: false type: string default: "" base_ref: description: Base branch/SHA to compare against (e.g., develop, commit SHA, or parent in stack) required: false type: string default: "develop" iteration: description: Iteration number for matrix runs (used for unique concurrency groups) required: false type: string default: "" # Concurrency control: cancel duplicate runs on same branch # When called via workflow_call with iteration input, include it to allow parallel matrix runs concurrency: group: ${{ github.workflow }}-${{ github.ref }}${{ inputs.iteration && format('-{0}', inputs.iteration) || '' }}-playwright-changed-files cancel-in-progress: true jobs: playwright-e2e-tests-changed-files: runs-on: ubuntu-latest-8-cores timeout-minutes: 20 defaults: run: shell: bash steps: - name: Validate ref for workflow_call if: github.event_name == 'workflow_call' && inputs.ref == '' run: | echo "::error::ref input is required when calling this workflow via workflow_call" exit 1 - name: Checkout Streamlit code (ref input) if: inputs.ref != '' uses: actions/checkout@v6 with: ref: ${{ inputs.ref }} persist-credentials: false submodules: "recursive" fetch-depth: 0 - name: Checkout Streamlit code (PR head) if: inputs.ref == '' && github.event_name == 'pull_request' uses: actions/checkout@v6 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} persist-credentials: false submodules: "recursive" fetch-depth: 0 - name: Get changed files id: changed-files env: BASE_REF: ${{ inputs.base_ref || 'develop' }} run: | # Fetch base branch/SHA for comparison # If BASE_REF is not a SHA (not 40 hex chars), fetch it as a branch name if [[ ! "$BASE_REF" =~ ^[0-9a-fA-F]{40}$ ]]; then git fetch origin "${BASE_REF}:${BASE_REF}" 2>/dev/null || true fi # If it's a SHA, git already has it (we used fetch-depth: 0) # Get all changed files comparing against base git_output=$(git diff --name-only "${BASE_REF}...HEAD") # Filter files in e2e_playwright directory and find relevant test files # Includes both changed test files and test files for changed app scripts changed_files=() changed_files_count=0 processed_tests=() # Track already added test files to avoid duplicates while IFS= read -r file; do # Check if file is in e2e_playwright directory (including subdirectories) if [[ $file == e2e_playwright/* ]]; then # Skip if file is in custom_components directory if [[ $file == *custom_components* ]]; then continue fi # Check if file still exists (not deleted) if [[ ! -f "$file" ]]; then continue fi test_file="" # If it's a test file, add it directly if [[ $file == *_test.py ]]; then test_file="$file" # If it's a Python file (but not a test file), check for corresponding test elif [[ $file == *.py ]]; then # Construct the test file name by adding _test before .py base_name="${file%.py}" potential_test="${base_name}_test.py" # Check if the corresponding test file exists if [[ -f "$potential_test" ]]; then test_file="$potential_test" fi fi # Add the test file if we found one and haven't already added it if [[ -n "$test_file" ]]; then # Remove the e2e_playwright/ prefix from the file path relative_file="${test_file#e2e_playwright/}" # Check if we've already added this test # Only check for duplicates if the array is not empty if [[ ${#processed_tests[@]} -eq 0 ]] || [[ ! " ${processed_tests[@]} " =~ " ${relative_file} " ]]; then changed_files+=("$relative_file") processed_tests+=("$relative_file") changed_files_count=$((changed_files_count + 1)) fi fi fi done <<< "$git_output" # Join the array with spaces, properly handling filenames with spaces joined_files=$(printf "%s " "${changed_files[@]}") joined_files="${joined_files% }" # Remove trailing space # Set outputs similar to the original action echo "all_changed_files=${joined_files}" >> $GITHUB_OUTPUT echo "all_changed_files_count=${changed_files_count}" >> $GITHUB_OUTPUT - name: Check changed files id: check_changed_files env: CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} CHANGED_FILES_COUNT: ${{ steps.changed-files.outputs.all_changed_files_count }} run: | echo "Changed files count: ${CHANGED_FILES_COUNT}" echo "$CHANGED_FILES" if [[ "${CHANGED_FILES_COUNT}" -gt 5 || "${CHANGED_FILES_COUNT}" -lt 1 ]]; then # We limit the workflow to a max of 5 changed files, since otherwise it would # take too long and would not provide any benefit compared to the main playwright # workflow. echo "This workflow only supports between 1-5 changed files. Otherwise its skipping running the tests."; echo "run_tests=false" >> $GITHUB_OUTPUT else echo "run_tests=true" >> $GITHUB_OUTPUT fi - name: Use output run: | echo "The output value is: ${{ steps.check_changed_files.outputs.run_tests }}" - name: Set Python version vars uses: ./.github/actions/build_info - if: steps.check_changed_files.outputs.run_tests == 'true' name: Setup virtual env uses: ./.github/actions/make_init with: python_version: ${{ env.PYTHON_MAX_VERSION }} - if: steps.check_changed_files.outputs.run_tests == 'true' name: Install playwright uses: ./.github/actions/playwright_install - if: steps.check_changed_files.outputs.run_tests == 'true' name: Run make frontend-with-profiler run: make frontend-with-profiler - name: Get short SHA id: short_sha run: | if [[ "${{ github.event_name }}" == "pull_request" ]]; then echo "sha_short=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-6)" >> $GITHUB_OUTPUT else echo "sha_short=$(echo ${{ github.sha }} | cut -c1-6)" >> $GITHUB_OUTPUT fi - name: Run changed playwright tests if: steps.check_changed_files.outputs.run_tests == 'true' run: | cd e2e_playwright rm -rf ./test-results echo "Running changed test files: ${{ steps.changed-files.outputs.all_changed_files }}" uv run pytest ${{ steps.changed-files.outputs.all_changed_files }} --browser webkit --browser chromium --browser firefox --tracing retain-on-failure -n auto --reruns 0 --cov=streamlit --cov-report=html --cov-config=.coveragerc -m "not performance" || exit_code=$? # Exit code 5 means no tests were collected (e.g., all tests are performance tests) # which is acceptable for this workflow if [ "${exit_code:-0}" -eq 5 ]; then echo "No tests collected (all tests may be performance tests). This is OK." exit 0 elif [ "${exit_code:-0}" -ne 0 ]; then exit $exit_code fi - name: Upload failed test results uses: actions/upload-artifact@v6 if: always() with: name: playwright_test_results_${{ steps.short_sha.outputs.sha_short }}${{ inputs.iteration != '' && format('_iter{0}', inputs.iteration) || '' }} path: e2e_playwright/test-results - name: Upload coverage HTML report uses: actions/upload-artifact@v6 with: name: coverage_report_e2e${{ inputs.iteration != '' && format('_iter{0}', inputs.iteration) || '' }} path: e2e_playwright/htmlcov retention-days: 14