Skip to content

Commit

Permalink
Split sdk and app test targets + workflow jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed May 31, 2024
1 parent d4b5a6a commit caece81
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 31 deletions.
11 changes: 8 additions & 3 deletions .github/actions/sdk-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inputs:
fastlane-session:
description: Fastlane session
required: true
fastlane-test-lane:
description: The fastlane test lane to run
required: false
default: test_sdk
match-keychain-name:
description: Match keychain name
required: true
Expand All @@ -29,8 +33,8 @@ inputs:
description: Source branch
required: true
sdk-name:
description: The name of the SDK, if not using the default Package.swift
default: sdk
description: The name of the SDK, if running SDK tests
required: false
package-swift:
description: The swift package file to use, if not default
required: false
Expand Down Expand Up @@ -64,7 +68,7 @@ runs:
- name: Build SPM App
shell: bash
run: |
bundle exec fastlane test_spm
bundle exec fastlane ${{ inputs.fastlane-lane }}
env:
MATCH_PASSWORD: ${{ inputs.match-password }}
MATCH_GIT_PRIVATE_KEY: ${{ inputs.ssh-private-key }}
Expand All @@ -75,6 +79,7 @@ runs:
SOURCE_BRANCH: ${{ inputs.source-branch }}
- name: Prepare coverage reports
shell: bash
if: ${{ inputs.sdk-name != '' }}
run: |
bash Scripts/xccov-to-sonarqube-generic.sh fastlane/test_output/PrimerSDKTests.xcresult/ > coverage.xml
sed "s#$PWD/##g" coverage.xml >sonar-coverage-${{ inputs.sdk-name }}.xml
Expand Down
70 changes: 49 additions & 21 deletions .github/workflows/build-test-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ concurrency:
cancel-in-progress: true

jobs:
unit-tests:
unit-tests-sdk:
runs-on: macos-13-large
timeout-minutes: 20
name: "Unit Tests"
name: "Unit Tests - SDK"
steps:
- name: Cancel previous jobs
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1
Expand All @@ -35,30 +35,58 @@ jobs:
fastlane-password: ${{ secrets.FASTLANE_PASSWORD }}
match-keychain-name: ${{ secrets.MATCH_KEYCHAIN_NAME }}
match-keychain-password: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
sdk-name: sdk

sonarcloud:
needs:
- unit-tests
name: SonarCloud
runs-on: macos-13
unit-tests-debug-app:
runs-on: macos-13-large
timeout-minutes: 20
name: "Unit Tests - SDK"
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Cancel previous jobs
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: actions/download-artifact@master
access_token: ${{ github.token }}
- name: Git - Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
name: coverage-file-sdk
- name: SonarCloud Scan
uses: ./.github/actions/sonar
ref: ${{ github.ref }}
- name: Run debug app tests
uses: ./.github/actions/sdk-tests
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
sonar-token: ${{ secrets.SONAR_TOKEN }}
sonar-host: https://sonarcloud.io.
pull-request-number: ${{ github.event.pull_request.number }}
branch: ${{ github.head_ref }}
base-branch: ${{ github.base_ref }}
pull-request-sha: ${{ github.event.pull_request.head.sha }}
coverage-file-name: sonar-coverage-sdk.xml
ssh-private-key: ${{ secrets.SSH_KEY }}
known-hosts: ${{ secrets.KNOWN_HOSTS }}
match-password: ${{ secrets.MATCH_PASSWORD }}
match-git-private-key: ${{ secrets.FASTLANE_PASSWORD }}
fastlane-session: ${{ secrets.FASTLANE_SESSION }}
fastlane-password: ${{ secrets.FASTLANE_PASSWORD }}
match-keychain-name: ${{ secrets.MATCH_KEYCHAIN_NAME }}
match-keychain-password: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}
fastlane-test-lane: test_debug_app

# sonarcloud:
# needs:
# - unit-tests-sdk
# - unit-tests-debug-app
# name: SonarCloud
# runs-on: macos-13
# steps:
# - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
# with:
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
# - uses: actions/download-artifact@master
# with:
# name: coverage-file-sdk
# - name: SonarCloud Scan
# uses: ./.github/actions/sonar
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
# sonar-token: ${{ secrets.SONAR_TOKEN }}
# sonar-host: https://sonarcloud.io.
# pull-request-number: ${{ github.event.pull_request.number }}
# branch: ${{ github.head_ref }}
# base-branch: ${{ github.base_ref }}
# pull-request-sha: ${{ github.event.pull_request.head.sha }}
# coverage-file-name: sonar-coverage-sdk.xml

build-and-upload-to-appetize:
needs:
Expand Down
4 changes: 4 additions & 0 deletions Debug App/Primer.io Debug App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0453CB3B2C0A08AD00C8C750 /* DebugAppTestPlan.xctestplan in Resources */ = {isa = PBXBuildFile; fileRef = 0453CB3A2C0A08AD00C8C750 /* DebugAppTestPlan.xctestplan */; };
0489E2BB2B68F71300FA0682 /* TapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0489E2BA2B68F71300FA0682 /* TapGestureRecognizer.swift */; };
04921D0D2BFB79DC004DFB4D /* MerchantHeadlessCheckoutNolPayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04921D0B2BFB79DC004DFB4D /* MerchantHeadlessCheckoutNolPayViewController.swift */; };
049A055E2B4BF057002CEEBA /* MerchantHeadlessVaultManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A055D2B4BF057002CEEBA /* MerchantHeadlessVaultManagerViewController.swift */; };
Expand Down Expand Up @@ -94,6 +95,7 @@
/* Begin PBXFileReference section */
00E3C8FE62D22147335F2455 /* MerchantResultViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MerchantResultViewController.swift; sourceTree = "<group>"; };
01C09DEAB07F42004B26A278 /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-PT"; path = "pt-PT.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
0453CB3A2C0A08AD00C8C750 /* DebugAppTestPlan.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DebugAppTestPlan.xctestplan; sourceTree = "<group>"; };
0489E2BA2B68F71300FA0682 /* TapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapGestureRecognizer.swift; sourceTree = "<group>"; };
04921D0B2BFB79DC004DFB4D /* MerchantHeadlessCheckoutNolPayViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MerchantHeadlessCheckoutNolPayViewController.swift; sourceTree = "<group>"; };
049A055D2B4BF057002CEEBA /* MerchantHeadlessVaultManagerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MerchantHeadlessVaultManagerViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -218,6 +220,7 @@
04F323602BD408C600F5927C /* Tests */ = {
isa = PBXGroup;
children = (
0453CB3A2C0A08AD00C8C750 /* DebugAppTestPlan.xctestplan */,
04C1906F2BEA5B75009A225A /* UnitTestsTestPlan.xctestplan */,
04F3235E2BD408C600F5927C /* Debug App Tests-Info.plist */,
04F3235D2BD408C600F5927C /* AppetizeConfigTests.swift */,
Expand Down Expand Up @@ -516,6 +519,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0453CB3B2C0A08AD00C8C750 /* DebugAppTestPlan.xctestplan in Resources */,
04F323622BD408C600F5927C /* Debug App Tests-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,35 @@
ReferencedContainer = "container:Primer.io Debug App.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "301F25EE1514F3AF2E4A7FBD"
BuildableName = "Debug App Tests.xctest"
BlueprintName = "Debug App Tests"
ReferencedContainer = "container:Primer.io Debug App.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BEB14ABCDF34E3D24759EAAB"
BuildableName = "Debug App.app"
BlueprintName = "Debug App"
BlueprintIdentifier = "301F25EE1514F3AF2E4A7FBD"
BuildableName = "Debug App Tests.xctest"
BlueprintName = "Debug App Tests"
ReferencedContainer = "container:Primer.io Debug App.xcodeproj">
</BuildableReference>
</TestableReference>
Expand Down
24 changes: 24 additions & 0 deletions Debug App/Tests/DebugAppTestPlan.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "8F18C1CB-7B2C-4E3F-8739-E715868A9ABA",
"name" : "Configuration 1",
"options" : {

}
}
],
"defaultOptions" : {
"testTimeoutsEnabled" : true
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:Primer.io Debug App.xcodeproj",
"identifier" : "301F25EE1514F3AF2E4A7FBD",
"name" : "Debug App Tests"
}
}
],
"version" : 1
}
21 changes: 19 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ platform :ios do

end

desc 'This action builds the app using the SPM integration'
lane :test_spm do |options|
desc 'This action tests the SDK using a SPM test target'
lane :test_sdk do |options|
common_pre_build_action

sim_version = options[:sim_version] || "17.2"
Expand All @@ -128,6 +128,23 @@ platform :ios do
)
end

desc 'This action tests the Debug App using a Xcode test target'
lane :test_debug_app do |options|
common_pre_build_action

sim_version = options[:sim_version] || "17.2"

run_tests(
workspace: "Primer.io Debug App.xcworkspace",
scheme: "Debug App",
sdk: "iphonesimulator#{sim_version}",
destination: "OS=#{sim_version},name=iPhone 14 Pro",
result_bundle: true,
code_coverage: true,
output_directory: Dir.pwd + "/test_output"
)
end

lane :build_cocoapods do |options|
common_pre_build_action

Expand Down

0 comments on commit caece81

Please sign in to comment.