diff --git a/.github/workflows/test_and_docs.yml b/.github/workflows/test_and_docs.yml index 3cdebe0084f..5c669616987 100644 --- a/.github/workflows/test_and_docs.yml +++ b/.github/workflows/test_and_docs.yml @@ -43,6 +43,15 @@ jobs: uses: eclipse-score/more-disk-space@v1.1 with: level: 4 + - name: Checkout repository (pull_request_target via workflow_call) + if: ${{ github.event_name == 'pull_request_target' }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ github.head_ref || github.event.pull_request.head.ref || github.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} + - name: Checkout repository + if: ${{ github.event_name != 'pull_request_target' }} + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Setup Bazel uses: bazel-contrib/setup-bazel@0.18.0 with: @@ -63,15 +72,6 @@ jobs: with: packages: graphviz cache: false - - name: Checkout repository (pull_request_target via workflow_call) - if: ${{ github.event_name == 'pull_request_target' }} - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - ref: ${{ github.head_ref || github.event.pull_request.head.ref || github.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} - - name: Checkout repository - if: ${{ github.event_name != 'pull_request_target' }} - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Build documentation - preflight # If we have doc errors, we dont wait of them 1h +... run: | bazel run \ @@ -82,7 +82,8 @@ jobs: rm -rf _build/ - name: Execute Unit Tests with Coverage Analysis run: | - python ./scripts/quality_runners.py + python ./scripts/quality_runners.py \ + ${{ github.event_name != 'push' && github.event_name != 'release' && '--trust-cache' || '' }} - name: Execute Feature Integration Tests run: | bazel test --config=linux-x86_64 //feature_integration_tests/test_cases:fit diff --git a/scripts/quality_runners.py b/scripts/quality_runners.py index 8c1215bd087..f81333da409 100644 --- a/scripts/quality_runners.py +++ b/scripts/quality_runners.py @@ -59,7 +59,7 @@ def configure_aslr_for_sanitizers() -> None: print(f"QR: Could not lower vm.mmap_rnd_bits (continuing anyway): {result.stderr.strip()}") -def run_unit_test_with_coverage(module: Module) -> dict[str, str | int]: +def run_unit_test_with_coverage(module: Module, trust_cache: bool = False) -> dict[str, str | int]: print_centered("QR: Running unit tests") call = ( @@ -72,7 +72,9 @@ def run_unit_test_with_coverage(module: Module) -> dict[str, str | int]: "--config=ferrocene-coverage", "--test_summary=testcase", "--test_output=errors", - "--nocache_test_results", + ] + + ([] if trust_cache else ["--nocache_test_results"]) + + [ f"--instrumentation_filter=@{module.name}", f"@{module.name}{module.metadata.code_root_path}", ] @@ -302,6 +304,13 @@ def parse_arguments() -> argparse.Namespace: default=[], help="List of modules to test", ) + parser.add_argument( + "--trust-cache", + action="store_true", + help="Allow Bazel to reuse cached test/coverage results for unchanged modules instead of always " + "re-executing them (--nocache_test_results). Intended for fast PR-iteration checks; authoritative " + "runs (e.g. on push to main) should NOT set this, so coverage numbers are always freshly measured.", + ) return parser.parse_args() @@ -325,7 +334,7 @@ def main() -> bool: continue print_centered(f"QR: Testing module: {module.name}") - unit_tests_summary[module.name] = run_unit_test_with_coverage(module=module) + unit_tests_summary[module.name] = run_unit_test_with_coverage(module=module, trust_cache=args.trust_cache) if "cpp" in module.metadata.langs: coverage_summary[f"{module.name}_cpp"] = run_cpp_coverage_extraction(