|
| 1 | +name: Code Coverage (Dynamic E2E Tests - SEA & Thrift) |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: [pull_request, workflow_dispatch] |
| 7 | + |
| 8 | +jobs: |
| 9 | + discover-tests: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + test-files: ${{ steps.discover.outputs.test-files }} |
| 13 | + steps: |
| 14 | + - name: Check out repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + ref: ${{ github.event.pull_request.head.ref || github.ref_name }} |
| 19 | + repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} |
| 20 | + |
| 21 | + - name: Discover test files |
| 22 | + id: discover |
| 23 | + run: | |
| 24 | + # Find all test files in e2e directory and create JSON array |
| 25 | + TEST_FILES=$(find tests/e2e -name "test_*.py" -type f | sort | jq -R -s -c 'split("\n")[:-1]') |
| 26 | + echo "test-files=$TEST_FILES" >> $GITHUB_OUTPUT |
| 27 | + echo "Discovered test files: $TEST_FILES" |
| 28 | +
|
| 29 | + e2e-tests: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + environment: azure-prod |
| 32 | + needs: discover-tests |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + test_file: ${{ fromJson(needs.discover-tests.outputs.test-files) }} |
| 36 | + mode: ["thrift", "sea"] |
| 37 | + env: |
| 38 | + DATABRICKS_SERVER_HOSTNAME: ${{ secrets.DATABRICKS_HOST }} |
| 39 | + DATABRICKS_HTTP_PATH: ${{ secrets.TEST_PECO_WAREHOUSE_HTTP_PATH }} |
| 40 | + DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }} |
| 41 | + DATABRICKS_CATALOG: peco |
| 42 | + DATABRICKS_USER: ${{ secrets.TEST_PECO_SP_ID }} |
| 43 | + steps: |
| 44 | + - name: Check out repository |
| 45 | + uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + ref: ${{ github.event.pull_request.head.ref || github.ref_name }} |
| 49 | + repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} |
| 50 | + |
| 51 | + - name: Set up python |
| 52 | + id: setup-python |
| 53 | + uses: actions/setup-python@v5 |
| 54 | + with: |
| 55 | + python-version: "3.10" |
| 56 | + |
| 57 | + - name: Install Poetry |
| 58 | + uses: snok/install-poetry@v1 |
| 59 | + with: |
| 60 | + virtualenvs-create: true |
| 61 | + virtualenvs-in-project: true |
| 62 | + installer-parallel: true |
| 63 | + |
| 64 | + - name: Load cached venv |
| 65 | + id: cached-poetry-dependencies |
| 66 | + uses: actions/cache@v4 |
| 67 | + with: |
| 68 | + path: .venv |
| 69 | + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }} |
| 70 | + |
| 71 | + - name: Install dependencies |
| 72 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 73 | + run: poetry install --no-interaction --no-root |
| 74 | + |
| 75 | + - name: Install library |
| 76 | + run: poetry install --no-interaction --all-extras |
| 77 | + |
| 78 | + - name: Run ${{ matrix.mode }} tests for ${{ matrix.test_file }} |
| 79 | + run: | |
| 80 | + echo "Running ${{ matrix.mode }} tests for ${{ matrix.test_file }}" |
| 81 | + |
| 82 | + # Set test filter based on mode |
| 83 | + if [ "${{ matrix.mode }}" = "sea" ]; then |
| 84 | + TEST_FILTER="-k 'extra_params1 or extra_params2'" |
| 85 | + else |
| 86 | + TEST_FILTER="-k 'extra_params0 or not extra_params'" |
| 87 | + fi |
| 88 | + |
| 89 | + TEST_NAME=$(basename "${{ matrix.test_file }}" .py) |
| 90 | + COVERAGE_FILE="coverage-${TEST_NAME}-${{ matrix.mode }}.xml" |
| 91 | + |
| 92 | + poetry run pytest "${{ matrix.test_file }}" $TEST_FILTER \ |
| 93 | + --cov=src --cov-report=xml:$COVERAGE_FILE --cov-report=term \ |
| 94 | + -v |
| 95 | + continue-on-error: true |
| 96 | + |
| 97 | + - name: Upload coverage artifact |
| 98 | + uses: actions/upload-artifact@v4 |
| 99 | + with: |
| 100 | + name: coverage-$(basename "${{ matrix.test_file }}" .py)-${{ matrix.mode }} |
| 101 | + path: | |
| 102 | + .coverage |
| 103 | + coverage-*-${{ matrix.mode }}.xml |
| 104 | +
|
| 105 | + merge-coverage: |
| 106 | + runs-on: ubuntu-latest |
| 107 | + needs: [e2e-tests] |
| 108 | + steps: |
| 109 | + - name: Check out repository |
| 110 | + uses: actions/checkout@v4 |
| 111 | + |
| 112 | + - name: Set up python |
| 113 | + id: setup-python |
| 114 | + uses: actions/setup-python@v5 |
| 115 | + with: |
| 116 | + python-version: "3.10" |
| 117 | + |
| 118 | + - name: Install Poetry |
| 119 | + uses: snok/install-poetry@v1 |
| 120 | + with: |
| 121 | + virtualenvs-create: true |
| 122 | + virtualenvs-in-project: true |
| 123 | + installer-parallel: true |
| 124 | + |
| 125 | + - name: Load cached venv |
| 126 | + id: cached-poetry-dependencies |
| 127 | + uses: actions/cache@v4 |
| 128 | + with: |
| 129 | + path: .venv |
| 130 | + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }} |
| 131 | + |
| 132 | + - name: Install dependencies |
| 133 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 134 | + run: poetry install --no-interaction --no-root |
| 135 | + |
| 136 | + - name: Install library |
| 137 | + run: poetry install --no-interaction --all-extras |
| 138 | + |
| 139 | + - name: Download all coverage artifacts |
| 140 | + uses: actions/download-artifact@v4 |
| 141 | + with: |
| 142 | + path: coverage_files |
| 143 | + |
| 144 | + - name: Merge coverage |
| 145 | + run: | |
| 146 | + # Install xmllint if not available |
| 147 | + if ! command -v xmllint &> /dev/null; then |
| 148 | + sudo apt-get update && sudo apt-get install -y libxml2-utils |
| 149 | + fi |
| 150 | + |
| 151 | + # Copy all coverage files with unique names |
| 152 | + for artifact_dir in coverage_files/*/; do |
| 153 | + if [ -f "$artifact_dir/.coverage" ]; then |
| 154 | + artifact_name=$(basename "$artifact_dir") |
| 155 | + cp "$artifact_dir/.coverage" ".coverage.$artifact_name" |
| 156 | + fi |
| 157 | + done |
| 158 | + |
| 159 | + # Combine all coverage data |
| 160 | + poetry run coverage combine .coverage.* |
| 161 | + poetry run coverage xml |
| 162 | + poetry run coverage report |
| 163 | +
|
| 164 | + - name: Report coverage percentage |
| 165 | + run: | |
| 166 | + COVERAGE_FILE="coverage.xml" |
| 167 | + if [ ! -f "$COVERAGE_FILE" ]; then |
| 168 | + echo "ERROR: Coverage file not found at $COVERAGE_FILE" |
| 169 | + exit 1 |
| 170 | + fi |
| 171 | +
|
| 172 | + COVERED=$(xmllint --xpath "string(//coverage/@lines-covered)" "$COVERAGE_FILE") |
| 173 | + TOTAL=$(xmllint --xpath "string(//coverage/@lines-valid)" "$COVERAGE_FILE") |
| 174 | +
|
| 175 | + # Calculate percentage using Python for precision |
| 176 | + PERCENTAGE=$(python3 -c "covered=${COVERED}; total=${TOTAL}; print(round((covered/total)*100, 2))") |
| 177 | +
|
| 178 | + echo "📊 Combined Coverage: ${PERCENTAGE}%" |
0 commit comments