-
Notifications
You must be signed in to change notification settings - Fork 1
169 lines (167 loc) · 9.53 KB
/
integration_test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Integration Test
on:
pull_request:
branches: [ "*" ]
push:
branches: [ "*" ]
jobs:
e2e-test:
runs-on: macos-13-xl
permissions:
contents: write
checks: write
pull-requests: write
id-token: write
env:
iam_role_to_assume: ${{ secrets.ROLE_ARN }}
device_farm_project_arn: ${{ secrets.DEVICE_FARM_PROJECT_ARN }}
device_farm_pool_arn: ${{ secrets.DEVICE_FARM_POOL_ARN }}
device_farm_test_spec_arn: ${{ secrets.DEVICE_FARM_TEST_SPEC_ARN }}
clickstream_app_id: ${{ secrets.CLICKSTREAM_APP_ID }}
clickstream_endpoint: ${{ secrets.CLICKSTREAM_ENDPOINT }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PROJECT_TOKEN }}
- name: Modify SDK for integration test
run: |
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
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
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
git diff
# git config user.name "github-actions"
# git config user.email "[email protected]"
# branch=pastboard-$(openssl rand -hex 5)
# echo $branch
# echo "temp_branch=$branch" >> "$GITHUB_ENV"
# git checkout -b $branch
# git add .
# git commit -m "ci: integration test"
# git push --set-upstream origin $branch
- name: Prepare sample iOS app
run: |
cd ..
git clone https://github.com/aws-samples/clickstream-sdk-samples
cd clickstream-sdk-samples/ios
sed -i '' -e "s#\"appId\": \"your appId\"#\"appId\": \"${{ env.clickstream_app_id }}\"#g" ModerneShopping/amplifyconfiguration.json
sed -i '' -e "s#\"endpoint\": \"your endpoint\"#\"endpoint\": \"${{ env.clickstream_endpoint }}\"#g" ModerneShopping/amplifyconfiguration.json
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
sed -i '' -e "s#3A1001882A1DDF4300DF72CB /\* XCRemoteSwiftPackageReference \"clickstream-swift\" \*\/,#3A67FCB62B6F26C60098082A /\* XCLocalSwiftPackageReference \"../../clickstream-swift\" \*\/,#g" ModerneShopping.xcodeproj/project.pbxproj
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
perl -0777 -pi -e 's#isa = XCSwiftPackageProductDependency;\n(\t+)package = 3A1001882A1DDF4300DF72CB /\* XCRemoteSwiftPackageReference \"clickstream-swift\" \*/;#isa = XCSwiftPackageProductDependency;#' ModerneShopping.xcodeproj/project.pbxproj
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
perl -0777 -pi -e 's#objectVersion = 54;#objectVersion = 60;#' ModerneShopping.xcodeproj/project.pbxproj
perl -0777 -pi -e 's#3A10018A2A1DDF4300DF72CB#3A67FCB82B6F26C60098082A#g' ModerneShopping.xcodeproj/project.pbxproj
perl -0777 -pi -e 's#3A1001892A1DDF4300DF72CB#3A67FCB72B6F26C60098082A#g' ModerneShopping.xcodeproj/project.pbxproj
git diff
cd ../../
ls
- name: Generate export options
run: |
echo '${{ vars.EXPORT_OPTIONS }}' >> ExportOptions.plist
cat ExportOptions.plist
ls
- name: Install the Apple certificate and provisioning profile
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.P12_BASE64 }}
P12_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.MOBILEPROVISION_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
PP_PATH=$RUNNER_TEMP/shoppingmacdev.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH
# create temporary keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
# apply provisioning profile
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
- name: Build archive
run: |
cd ../clickstream-sdk-samples/ios/
xcodebuild -scheme "ModerneShopping" \
-archivePath $RUNNER_TEMP/ModerneShopping.xcarchive \
-sdk iphoneos \
-configuration Release \
-destination generic/platform=iOS \
clean archive
- name: Export ipa
run: |
EXPORT_OPTS_PATH=ExportOptions.plist
xcodebuild -exportArchive -archivePath $RUNNER_TEMP/ModerneShopping.xcarchive -exportOptionsPlist $EXPORT_OPTS_PATH -exportPath output
cd output
ls
# - name: Delete temp branch
# if: success() || failure()
# run: |
# echo $temp_branch
# git status
# git push origin --delete $temp_branch
# - name: Build Device Farm test file
# run: |
# cd IntegrationTest
# pip install virtualenv
# virtualenv --help
# virtualenv workspace
# cd workspace
# source bin/activate
# pip install -r ../requirements.txt
# mkdir tests
# cp ../appium/shopping_test.py tests/
# find tests/
# py.test --collect-only tests/
# cd tests/
# find . -name '__pycache__' -type d -exec rm -r {} +
# find . -name '*.pyc' -exec rm -f {} +
# find . -name '*.pyo' -exec rm -f {} +
# find . -name '*~' -exec rm -f {} +
# cd ..
# pip freeze > requirements.txt
# zip -r test_bundle.zip tests/ requirements.txt
# ls
# cd ..
# - name: Configure AWS Credentials
# if: ${{ env.iam_role_to_assume != '' }}
# uses: aws-actions/configure-aws-credentials@v4
# with:
# role-to-assume: ${{ env.iam_role_to_assume }}
# aws-region: us-west-2
# - name: Execute device farm test
# run: |
# cd IntegrationTest
# pip install -r requirements.txt
# cd devicefarm
# cp ../../output/ModerneShopping.ipa ./
# cp ../workspace/test_bundle.zip ./
# ls
# 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 }}')"
# - name: Execute logcat test
# run: |
# cd IntegrationTest/devicefarm
# pytest logcat_test.py -s --junitxml=report/logcat_test_report.xml --html=report/logcat_test_report.html
# - name: Publish Test Report
# uses: mikepenz/action-junit-report@v4
# if: success() || failure()
# with:
# report_paths: 'IntegrationTest/devicefarm/report/*.xml'
# require_tests: true
# detailed_summary: true
# include_passed: true
# fail_on_failure: true
# job_name: integration test
# - name: Upload test result
# uses: actions/upload-artifact@v4
# if: success() || failure()
# with:
# name: test-result
# path: |
# IntegrationTest/devicefarm/report/
# IntegrationTest/devicefarm/MyAndroidAppTest-*/**