From 4d3468af1f4b052a376c3a5641f6d71bcf28975f Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Tue, 6 Oct 2026 22:43:03 +0100 Subject: [PATCH] Enforce 85 percent line coverage for each Swift SDK target --- .ci/changed-file-filters.yml | 3 +++ .ci/coverage-thresholds.json | 8 +++++++- dev.yml | 5 ++++- e2e/bitrise.yml | 16 +++++++++------- scripts/test/coverage_thresholds_test.rb | 9 +++++++++ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.ci/changed-file-filters.yml b/.ci/changed-file-filters.yml index 62824dbe4..d959a585c 100644 --- a/.ci/changed-file-filters.yml +++ b/.ci/changed-file-filters.yml @@ -61,6 +61,9 @@ ciFilters: # decide which macOS jobs run, so a change to one has to rerun them all, while a Maestro # flow edit under e2e/ must not. iosCiConfig: + - '.ci/coverage-thresholds.json' + - 'scripts/check_coverage' + - 'scripts/lib/coverage_thresholds.rb' - 'scripts/report_coverage' - 'scripts/lib/coverage_report.rb' - 'e2e/bitrise.yml' diff --git a/.ci/coverage-thresholds.json b/.ci/coverage-thresholds.json index 13a6ed2d2..4f34bc479 100644 --- a/.ci/coverage-thresholds.json +++ b/.ci/coverage-thresholds.json @@ -1,3 +1,9 @@ { - "android": {"Lines": 85} + "android": { + "Lines": 85 + }, + "swift": { + "ShopifyCheckoutKit": 85, + "ShopifyAcceleratedCheckouts": 85 + } } diff --git a/dev.yml b/dev.yml index 68e67c064..860f63345 100644 --- a/dev.yml +++ b/dev.yml @@ -676,7 +676,10 @@ commands: subcommands: coverage: desc: Run Swift package tests and export Xcode coverage reports - run: cd platforms/swift && ./Scripts/test_coverage + run: | + set -e + platforms/swift/Scripts/test_coverage + ruby scripts/check_coverage swift .xcresults/coverage/coverage.json sample: desc: Run the sample app test target syntax: "[test_class_name]" diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml index 402863c5c..a1b3a0874 100644 --- a/e2e/bitrise.yml +++ b/e2e/bitrise.yml @@ -350,8 +350,9 @@ workflows: set -euo pipefail cd platforms/swift ./Scripts/test_coverage + ruby ../../scripts/check_coverage swift ../../.xcresults/coverage/coverage.json - deploy-to-bitrise-io@2: - is_always_run: false + is_always_run: true inputs: - deploy_path: "$BITRISE_SOURCE_DIR/.xcresults/coverage" - script@1: @@ -373,12 +374,16 @@ workflows: - script@1: title: Run Embedded Checkout Protocol Swift coverage + is_always_run: true inputs: - content: |- set -euo pipefail - ./protocol/scripts/test_swift_coverage + outcome=success + ./protocol/scripts/test_swift_coverage || outcome=failure + envman add --key PROTOCOL_SWIFT_TEST_OUTCOME --value "$outcome" + test "$outcome" = success - deploy-to-bitrise-io@2: - is_always_run: false + is_always_run: true inputs: - deploy_path: "$BITRISE_SOURCE_DIR/protocol/languages/swift/.build/coverage" - script@1: @@ -392,10 +397,7 @@ workflows: export COVERAGE_SHA="${BITRISE_GIT_COMMIT:-}" export COVERAGE_REPORT_URL="${BITRISE_BUILD_URL:-}" export COVERAGE_TOKEN="${OVERRIDE_GITHUB_TOKEN:-${GIT_HTTP_PASSWORD:-}}" - export COVERAGE_TEST_OUTCOME=success - if [ "${BITRISE_BUILD_STATUS:-0}" != "0" ]; then - export COVERAGE_TEST_OUTCOME=failure - fi + export COVERAGE_TEST_OUTCOME="${PROTOCOL_SWIFT_TEST_OUTCOME:-failure}" ruby scripts/report_coverage protocol-swift protocol/languages/swift/.build/coverage/coverage.json ci-ios-swift-samples: diff --git a/scripts/test/coverage_thresholds_test.rb b/scripts/test/coverage_thresholds_test.rb index a28490e2b..9276f4768 100644 --- a/scripts/test/coverage_thresholds_test.rb +++ b/scripts/test/coverage_thresholds_test.rb @@ -31,6 +31,15 @@ def test_every_configured_target_must_pass_independently assert_equal ["Second: 70.00% (70/100) is below 85%"], result end + def test_swift_targets_use_individual_thresholds_from_the_committed_configuration + configuration = JSON.parse(File.read(File.expand_path("../../.ci/coverage-thresholds.json", __dir__))) + checker = CoverageThresholds.new(configuration) + report = Report.new("swift", [["ShopifyCheckoutKit", 99, 100], ["ShopifyAcceleratedCheckouts", 84, 100]]) + assert_equal ["ShopifyAcceleratedCheckouts: 84.00% (84/100) is below 85%"], checker.failures(report) + report.rows[1][1] = 85 + assert_empty checker.failures(report) + end + def test_invalid_configuration_fails_closed assert_raises(KeyError) { threshold_failures([], {}) } [-1, 101, "85", Float::NAN].each do |minimum|