sonarcloud: skip sharded scan steps when the plan job produces no shards

This commit is contained in:
Dylan M. Taylor
2026-10-25 18:39:10 -04:00
parent f043d79388
commit 4ce7b5eee8
2 changed files with 14 additions and 4 deletions
+4 -4
View File
@@ -236,23 +236,23 @@ jobs:
cargo llvm-cov --workspace --ignore-run-fail --lcov --output-path lcov.info
--ignore-filename-regex "$COVERAGE_IGNORE"
- name: Install LLVM tools
if: steps.token.outputs.available == 'true' && inputs.shards > 1
if: steps.token.outputs.available == 'true' && inputs.shards > 1 && hashFiles('Cargo.toml') != ''
run: rustup component add llvm-tools-preview
- name: Download shard profiles and archive
if: steps.token.outputs.available == 'true' && inputs.shards > 1
if: steps.token.outputs.available == 'true' && inputs.shards > 1 && hashFiles('Cargo.toml') != ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: profraw-*
path: profraw
merge-multiple: true
- name: Download test archive
if: steps.token.outputs.available == 'true' && inputs.shards > 1
if: steps.token.outputs.available == 'true' && inputs.shards > 1 && hashFiles('Cargo.toml') != ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: nextest-archive
path: archive
- name: Combine shard coverage
if: steps.token.outputs.available == 'true' && inputs.shards > 1
if: steps.token.outputs.available == 'true' && inputs.shards > 1 && hashFiles('Cargo.toml') != ''
shell: bash
run: |
set -euo pipefail
+10
View File
@@ -105,6 +105,16 @@ class SonarCloudTests(unittest.TestCase):
self.assertIn('--archive-file archive/nextest-archive.tar.zst', tests['run'])
self.assertEqual(workflow['jobs']['coverage']['needs'], ['plan', 'build'])
def test_sharded_scan_steps_only_run_when_the_plan_runs(self):
workflow = yaml.load(
(ROOT / '.github/workflows/sonarcloud.yml').read_text(), Loader=yaml.BaseLoader)
sharded = [step for step in workflow['jobs']['sonarcloud']['steps']
if 'inputs.shards > 1' in step.get('if', '')]
self.assertGreaterEqual(len(sharded), 4)
for step in sharded:
with self.subTest(step=step.get('name')):
self.assertIn("hashFiles('Cargo.toml') != ''", step['if'])
def test_scan_fails_when_a_prerequisite_job_failed(self):
workflow = yaml.load(
(ROOT / '.github/workflows/sonarcloud.yml').read_text(), Loader=yaml.BaseLoader)