|
| 1 | +name: Integration Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ "main" ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + e2e-test: |
| 9 | + runs-on: macos-13-xl |
| 10 | + permissions: |
| 11 | + contents: write |
| 12 | + checks: write |
| 13 | + pull-requests: write |
| 14 | + id-token: write |
| 15 | + env: |
| 16 | + iam_role_to_assume: ${{ secrets.ROLE_ARN }} |
| 17 | + device_farm_project_arn: ${{ secrets.DEVICE_FARM_PROJECT_ARN }} |
| 18 | + device_farm_pool_arn: ${{ secrets.DEVICE_FARM_POOL_ARN }} |
| 19 | + device_farm_test_spec_arn: ${{ secrets.DEVICE_FARM_TEST_SPEC_ARN }} |
| 20 | + clickstream_app_id: ${{ secrets.CLICKSTREAM_APP_ID }} |
| 21 | + clickstream_endpoint: ${{ secrets.CLICKSTREAM_ENDPOINT }} |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + token: ${{ secrets.PROJECT_TOKEN }} |
| 26 | + - name: Modify SDK for integration test |
| 27 | + run: | |
| 28 | + sed -i '' -e "s#private(set) var bundleSequenceId: Int#private(set) var bundleSequenceId: Int\n var allEventJson: String = \"\"#g" Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift |
| 29 | + sed -i '' -e "s#toPrettierJsonString())\")#toPrettierJsonString())\")\n allEventJson.append(\"Saved event \\\(event.eventType):\\\(eventObject.toJsonString())\\\n\")\n UIPasteboard.general.string = allEventJson#g" Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift |
| 30 | + sed -i '' -e "s#batchEvent.eventCount) events\")#batchEvent.eventCount) events\")\n allEventJson.append(\"Send \\\(batchEvent.eventCount) events\\\n\")\n UIPasteboard.general.string = allEventJson#g" Sources/Clickstream/Dependency/Clickstream/Analytics/EventRecorder.swift |
| 31 | + git diff |
| 32 | + - name: Prepare sample iOS app |
| 33 | + run: | |
| 34 | + cd .. |
| 35 | + git clone https://github.com/aws-samples/clickstream-sdk-samples |
| 36 | + cd clickstream-sdk-samples/ios |
| 37 | + sed -i '' -e "s#\"appId\": \"your appId\"#\"appId\": \"${{ env.clickstream_app_id }}\"#g" ModerneShopping/amplifyconfiguration.json |
| 38 | + sed -i '' -e "s#\"endpoint\": \"your endpoint\"#\"endpoint\": \"${{ env.clickstream_endpoint }}\"#g" ModerneShopping/amplifyconfiguration.json |
| 39 | + sed -i '' -e "s#if index==0 || index==1 {}#if index==0 || index==1 {\n cart.addToCart(addedProduct: product, quantity: 1)\n }#g" ModerneShopping/Views/ProductViews/ProductList.swift |
| 40 | + sed -i '' -e "s#3A1001882A1DDF4300DF72CB /\* XCRemoteSwiftPackageReference \"clickstream-swift\" \*\/,#3A67FCB62B6F26C60098082A /\* XCLocalSwiftPackageReference \"../../clickstream-swift\" \*\/,#g" ModerneShopping.xcodeproj/project.pbxproj |
| 41 | + perl -0777 -pi -e 's#/\* Begin XCRemoteSwiftPackageReference section \*/\n(\t+)3A1001882A1DDF4300DF72CB /\* XCRemoteSwiftPackageReference \"clickstream-swift\" \*/ = {\n(\t+)isa = XCRemoteSwiftPackageReference;\n(\t+)repositoryURL = \"https://github.com/awslabs/clickstream-swift.git\";\n(\t+)requirement = {\n(\t+)branch = main;\n(\t+)kind = branch;\n(\t+)};\n(\t+)};#/\* Begin XCLocalSwiftPackageReference section \*/\n\t\t3A67FCB62B6F26C60098082A /\* XCLocalSwiftPackageReference \"../../clickstream-swift\" \*/ = {\n$2isa = XCLocalSwiftPackageReference;\n$3relativePath = \"../../clickstream-swift\";\n$1};\n/\* End XCLocalSwiftPackageReference section \*/\n\n/* Begin XCRemoteSwiftPackageReference section \*/#' ModerneShopping.xcodeproj/project.pbxproj |
| 42 | + perl -0777 -pi -e 's#isa = XCSwiftPackageProductDependency;\n(\t+)package = 3A1001882A1DDF4300DF72CB /\* XCRemoteSwiftPackageReference \"clickstream-swift\" \*/;#isa = XCSwiftPackageProductDependency;#' ModerneShopping.xcodeproj/project.pbxproj |
| 43 | + perl -0777 -pi -e 's#\n {\n "identity" : "clickstream-swift",\n "kind" : "remoteSourceControl",\n "location" : "https://github.com/awslabs/clickstream-swift.git",\n "state" : {\n "branch" : "main",\n "revision" : "2bd29626068a6dff158f41f9d81295a6eaa59be5"\n }\n },##' ModerneShopping.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved |
| 44 | + perl -0777 -pi -e 's#objectVersion = 54;#objectVersion = 60;#' ModerneShopping.xcodeproj/project.pbxproj |
| 45 | + git diff |
| 46 | + - name: Generate export options |
| 47 | + run: | |
| 48 | + echo '${{ vars.EXPORT_OPTIONS }}' >> ExportOptions.plist |
| 49 | + cat ExportOptions.plist |
| 50 | + ls |
| 51 | + - name: Install the Apple certificate and provisioning profile |
| 52 | + env: |
| 53 | + BUILD_CERTIFICATE_BASE64: ${{ secrets.P12_BASE64 }} |
| 54 | + P12_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }} |
| 55 | + BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.MOBILEPROVISION_BASE64 }} |
| 56 | + KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} |
| 57 | + run: | |
| 58 | + CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 |
| 59 | + PP_PATH=$RUNNER_TEMP/shoppingmacdev.mobileprovision |
| 60 | + KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db |
| 61 | + # import certificate and provisioning profile from secrets |
| 62 | + echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH |
| 63 | + echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH |
| 64 | + # create temporary keychain |
| 65 | + security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH |
| 66 | + security set-keychain-settings -lut 21600 $KEYCHAIN_PATH |
| 67 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH |
| 68 | + # import certificate to keychain |
| 69 | + security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH |
| 70 | + security list-keychain -d user -s $KEYCHAIN_PATH |
| 71 | + # apply provisioning profile |
| 72 | + mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles |
| 73 | + cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles |
| 74 | + - name: Build archive |
| 75 | + run: | |
| 76 | + sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer' |
| 77 | + xcode-select --print-path |
| 78 | + cd ../clickstream-sdk-samples/ios/ |
| 79 | + xcodebuild -resolvePackageDependencies |
| 80 | + echo "start build app" |
| 81 | + xcodebuild -scheme "ModerneShopping" \ |
| 82 | + -archivePath $RUNNER_TEMP/ModerneShopping.xcarchive \ |
| 83 | + -sdk iphoneos \ |
| 84 | + -configuration Release \ |
| 85 | + -destination generic/platform=iOS \ |
| 86 | + clean archive | xcpretty |
| 87 | + - name: Export ipa |
| 88 | + run: | |
| 89 | + EXPORT_OPTS_PATH=ExportOptions.plist |
| 90 | + xcodebuild -exportArchive -archivePath $RUNNER_TEMP/ModerneShopping.xcarchive -exportOptionsPlist $EXPORT_OPTS_PATH -exportPath output |
| 91 | + cd output |
| 92 | + ls |
| 93 | + - name: Build Device Farm test file |
| 94 | + run: | |
| 95 | + cd IntegrationTest |
| 96 | + pip install virtualenv |
| 97 | + virtualenv --help |
| 98 | + virtualenv workspace |
| 99 | + cd workspace |
| 100 | + source bin/activate |
| 101 | + pip install -r ../requirements.txt |
| 102 | + mkdir tests |
| 103 | + cp ../appium/shopping_test.py tests/ |
| 104 | + find tests/ |
| 105 | + py.test --collect-only tests/ |
| 106 | + cd tests/ |
| 107 | + find . -name '__pycache__' -type d -exec rm -r {} + |
| 108 | + find . -name '*.pyc' -exec rm -f {} + |
| 109 | + find . -name '*.pyo' -exec rm -f {} + |
| 110 | + find . -name '*~' -exec rm -f {} + |
| 111 | + cd .. |
| 112 | + pip freeze > requirements.txt |
| 113 | + zip -r test_bundle.zip tests/ requirements.txt |
| 114 | + ls |
| 115 | + cd .. |
| 116 | + - name: Configure AWS Credentials |
| 117 | + if: ${{ env.iam_role_to_assume != '' }} |
| 118 | + uses: aws-actions/configure-aws-credentials@v4 |
| 119 | + with: |
| 120 | + role-to-assume: ${{ env.iam_role_to_assume }} |
| 121 | + aws-region: us-west-2 |
| 122 | + - name: Execute device farm test |
| 123 | + run: | |
| 124 | + cd IntegrationTest |
| 125 | + pip install -r requirements.txt |
| 126 | + cd devicefarm |
| 127 | + cp ../../output/ModerneShopping.ipa ./ |
| 128 | + cp ../workspace/test_bundle.zip ./ |
| 129 | + ls |
| 130 | + python -u -c "from automate_device_farm import upload_and_test_ios; upload_and_test_ios('ModerneShopping.ipa', 'test_bundle.zip', '${{ env.device_farm_project_arn }}', '${{ env.device_farm_test_spec_arn }}', '${{ env.device_farm_pool_arn }}')" |
| 131 | + - name: Execute logcat test |
| 132 | + run: | |
| 133 | + cd IntegrationTest/devicefarm |
| 134 | + pytest logcat_test.py -s --junitxml=report/logcat_test_report.xml --html=report/logcat_test_report.html |
| 135 | + - name: Publish Test Report |
| 136 | + uses: mikepenz/action-junit-report@v4 |
| 137 | + if: success() || failure() |
| 138 | + with: |
| 139 | + report_paths: 'IntegrationTest/devicefarm/report/*.xml' |
| 140 | + require_tests: true |
| 141 | + detailed_summary: true |
| 142 | + include_passed: true |
| 143 | + fail_on_failure: true |
| 144 | + job_name: integration test |
| 145 | + - name: Upload test result |
| 146 | + uses: actions/upload-artifact@v4 |
| 147 | + if: success() || failure() |
| 148 | + with: |
| 149 | + name: test-result |
| 150 | + path: | |
| 151 | + IntegrationTest/devicefarm/report/ |
| 152 | + IntegrationTest/devicefarm/MyAndroidAppTest-*/** |
0 commit comments