From 025eecd1fcad2eaf84e73deb923a7f54004981cc Mon Sep 17 00:00:00 2001 From: Gran Date: Mon, 8 Feb 2021 15:09:25 -0800 Subject: [PATCH] Add multiple workflows for coverage tests. (#7470) Add all SDKs to code coverage workflows. Limit report to only frameworks and exclude xctest etc. --- .github/workflows/test_coverage.yml | 202 +++++++++++++++++- .../code_coverage_file_list.json | 114 +++++++++- .../CoverageReportParser.swift | 11 +- 3 files changed, 320 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index 233dbe680b5..2bcf38a43d2 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -12,8 +12,18 @@ jobs: if: github.repository == 'Firebase/firebase-ios-sdk' && (github.event.action == 'opened' || github.event.action == 'synchronize') name: Check changed files outputs: + abtesting_run_job: ${{ steps.check_files.outputs.abtesting_run_job }} + auth_run_job: ${{ steps.check_files.outputs.auth_run_job }} database_run_job: ${{ steps.check_files.outputs.database_run_job }} + dynamiclinks_run_job: ${{ steps.check_files.outputs.dynamiclinks_run_job }} + firestore_run_job: ${{ steps.check_files.outputs.firestore_run_job }} functions_run_job: ${{ steps.check_files.outputs.functions_run_job }} + inappmessaging_run_job: ${{ steps.check_files.outputs.inappmessaging_run_job }} + instanceid_run_job: ${{ steps.check_files.outputs.instanceid_run_job }} + messaging_run_job: ${{ steps.check_files.outputs.messaging_run_job }} + performance_run_job: ${{ steps.check_files.outputs.performance_run_job }} + remoteconfig_run_job: ${{ steps.check_files.outputs.remoteconfig_run_job }} + storage_run_job: ${{ steps.check_files.outputs.storage_run_job }} base_commit: ${{ steps.check_files.outputs.base_commit }} runs-on: ubuntu-latest steps: @@ -66,8 +76,198 @@ jobs: name: codecoverage path: /Users/runner/*.xcresult + pod-lib-lint-abtesting: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.abtesting_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseABTesting "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-auth: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.auth_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseAuth "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-dynamiclinks: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.dynamiclinks_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseDynamicLinks "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-firestore: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.firestore_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseFirestore "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-inappmessaging: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.inappmessaging_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseInAppMessaging "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-instanceid: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.instanceid_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseInstanceID "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-messaging: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.messaging_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseMessaging "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-performance: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.performance_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebasePerformance "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-remoteconfig: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.remoteconfig_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseRemoteConfig "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + + pod-lib-lint-storage: + needs: check + # Don't run on private repo unless it is a PR. + if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.storage_run_job == 'true'|| github.event.pull_request.merged) + runs-on: macOS-latest + strategy: + matrix: + target: [ios] + steps: + - uses: actions/checkout@v2 + - name: Setup Bundler + run: scripts/setup_bundler.sh + - name: Build and test + run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseStorage "${{ matrix.target }}" + - uses: actions/upload-artifact@v2 + with: + name: codecoverage + path: /Users/runner/*.xcresult + create_report: - needs: [check, pod-lib-lint-functions, pod-lib-lint-database] + needs: [check, pod-lib-lint-abtesting, pod-lib-lint-auth, pod-lib-lint-database, pod-lib-lint-dynamiclinks, pod-lib-lint-firestore, pod-lib-lint-functions, pod-lib-lint-inappmessaging, pod-lib-lint-instanceid, pod-lib-lint-messaging, pod-lib-lint-performance, pod-lib-lint-remoteconfig, pod-lib-lint-storage] env: metrics_service_secret: ${{ secrets.GHASecretsGPGPassphrase1 }} if: always() diff --git a/scripts/code_coverage_report/code_coverage_file_list.json b/scripts/code_coverage_report/code_coverage_file_list.json index 2bfbb907590..9a2885c8997 100644 --- a/scripts/code_coverage_report/code_coverage_file_list.json +++ b/scripts/code_coverage_report/code_coverage_file_list.json @@ -1,11 +1,63 @@ [ + { + "sdk": "abtesting", + "filePatterns": [ + "FirebaseABTesting.*", + "Interop/Analytics/Public/[^/]+\\.h", + "\\.github/workflows/abtesting\\.yml", + "Gemfile" + ] + }, + { + "sdk": "auth", + "filePatterns": [ + "FirebaseAuth.*", + "Interop/Auth/Public/[^/]+\\.h", + "\\.github/workflows/auth\\.yml", + "Gemfile" + ] + }, { "sdk": "database", "filePatterns": [ "FirebaseDatabase.*", "\\.github/workflows/database\\.yml", "Example/Database/", - "Interop/Auth/Public/.*\\.h" + "Interop/Auth/Public/[^/]+\\.h", + "Gemfile" + ] + }, + { + "sdk": "dynamiclinks", + "filePatterns": [ + "FirebaseDynamicLinks.*", + "\\.github/workflows/dynamiclinks\\.yml", + "Interop/Analytics/Public/[^/]+\\.h", + "Gemfile" + ] + }, + { + "sdk": "firestore", + "filePatterns": [ + "Firestore/.*", + "Interop/Auth/Public/[^/]+\\.h", + "FirebaseCore/Sources/Private", + "FirebaseCore/Sources/Public", + "FirebaseFirestore\\.podspec", + "CMakeLists\\.txt", + "cmake/.*", + "scripts/binary_to_array\\.py", + "scripts/build\\.sh", + "scripts/install_prereqs\\.sh", + "scripts/localize_podfile\\.swift", + "scripts/pod_lib_lint\\.rb", + "scripts/run_firestore_emulator\\.sh", + "scripts/setup_[^/]+", + "scripts/sync_project\\.rb", + "scripts/test_quickstart\\.sh", + "scripts/xcresult_logs\\.py", + "\\.github/workflows/firestore\\.yml", + "Gemfile" ] }, { @@ -14,7 +66,65 @@ "Functions.*", "\\.github/workflows/functions\\.yml", "Interop/Auth/Public/.*\\.h", - "FirebaseMessaging/Sources/Interop/.*\\.h" + "FirebaseMessaging/Sources/Interop/[^/]+\\.h", + "Gemfile" + ] + }, + { + "sdk": "inappmessaging", + "filePatterns": [ + "FirebaseInAppMessaging.*", + "Interop/Analytics/Public/[^/]+\\.h", + "\\.github/workflows/inappmessaging\\.yml", + "Gemfile" + ] + }, + { + "sdk": "instanceid", + "filePatterns": [ + "FirebaseInstanceID.*", + "Firebase/InstanceID/.*", + "Example/InstanceID/.*", + "\\.github/workflows/instanceid\\.yml", + "Gemfile" + ] + }, + { + "sdk": "messaging", + "filePatterns": [ + "FirebaseMessaging/.*", + "Interop/Analytics/Public/[^/]+\\.h", + "FirebaseMessaging\\.podspec", + "\\.github/workflows/messaging\\.yml", + "Gemfile" + ] + }, + { + "sdk": "performance", + "filePatterns": [ + "FirebasePerformance/.*", + "FirebasePerformance\\.podspec", + "\\.github/workflows/performance\\.yml", + "Gemfile" + ] + }, + { + "sdk": "remoteconfig", + "filePatterns": [ + "FirebaseRemoteConfig.*", + "Interop/Analytics/Public/[^/]+\\.h", + "\\.github/workflows/remoteconfig\\.yml", + "Gemfile", + "scripts/generate_access_token\\.sh" + ] + }, + { + "sdk": "storage", + "filePatterns": [ + "FirebaseStorage.*", + "Interop/Auth/Public/[^/]+\\.h", + "\\.github/workflows/storage\\.yml", + "Gemfile" ] } ] diff --git a/scripts/code_coverage_report/generate_code_coverage_report/Sources/CoverageReportGenerator/CoverageReportParser.swift b/scripts/code_coverage_report/generate_code_coverage_report/Sources/CoverageReportGenerator/CoverageReportParser.swift index 073b79f9b4a..a627b6846ef 100644 --- a/scripts/code_coverage_report/generate_code_coverage_report/Sources/CoverageReportGenerator/CoverageReportParser.swift +++ b/scripts/code_coverage_report/generate_code_coverage_report/Sources/CoverageReportGenerator/CoverageReportParser.swift @@ -63,16 +63,22 @@ extension CoverageReportRequestData { // Get sdk name. resultBundle is like ${SDK}-${platform}. E.g. FirebaseDatabase-ios. // To display only sdk related tests and exclude non related testing, e.g. // FirebaseDatabase-ios-GoogleDataTransport.framework, + // FirebaseDatabase-ios-FirebaseCore-Unit-unit.xctest, // FirebaseDatabase-ios-FirebaseCore.framework, a regex pattern will be // used to exclude results that are not related in terms of the target names. let sdk_name = resultBundle.components(separatedBy: "-")[0] let range = NSRange(location: 0, length: target.name.utf16.count) + let target_pattern = ".*\(sdk_name).*framework" let sdk_related_coverage_file_pattern = try! NSRegularExpression( - pattern: ".*\(sdk_name).*", + pattern: target_pattern, options: NSRegularExpression.Options(rawValue: 0) ) + print("Target: \(target.name) is detected.") if sdk_related_coverage_file_pattern.firstMatch(in: target.name, range: range) != nil { + print( + "Target, \(target.name), fit the pattern, \(target_pattern), and will be involved in the report." + ) results .append(FileCoverage(sdk: resultBundle + "-" + target.name, type: "", value: target.lineCoverage)) @@ -80,9 +86,6 @@ extension CoverageReportRequestData { results .append(FileCoverage(sdk: resultBundle + "-" + target.name, type: file.name, value: file.lineCoverage)) - results - .append(FileCoverage(sdk: resultBundle + "-" + target.name, type: file.name, - value: file.lineCoverage)) } } }