Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: support using shopping app for integration testing in device farm #48

Merged
merged 82 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
7cef6a0
feat: add integration tst
Jan 20, 2024
4b9cf48
fix: the sed command
Jan 20, 2024
1436e0a
fix new line
Jan 20, 2024
145706c
fix new line
Jan 20, 2024
78fafba
fix push set upstream
Jan 20, 2024
86fb3e1
fix: delete echo and cat
Jan 21, 2024
a774994
feat: add build device farm test file
Jan 21, 2024
777b34e
feat: add app modify
Jan 26, 2024
ffe612b
fix: checkout format
Jan 26, 2024
3e8721d
test prepare app
Jan 26, 2024
111c170
test branch name
Jan 26, 2024
77f7736
test branch name use romdom string
Jan 26, 2024
367c329
test branch name
Jan 26, 2024
7f6a07f
test branch name use rand hex
Jan 26, 2024
13a20b1
fix sed and branch delete
Jan 26, 2024
b071af2
fix branch delete
Jan 26, 2024
9d48135
fix branch delete
Jan 26, 2024
020d73a
feat: change pbxproj file
Jan 27, 2024
269b975
feat: test build ipa
Jan 27, 2024
f54438e
ci: add ios build-destination
Jan 27, 2024
40cbe05
ci: add device farm test
Jan 27, 2024
9579a77
feat: find ipa file
Jan 27, 2024
4c3841e
feat: find ipa file
Jan 27, 2024
9e418c6
feat: find ipa file
Jan 27, 2024
548aa8f
feat: find ipa file
Jan 27, 2024
e9b7bd6
delete output-path
Jan 29, 2024
a05c313
test find .ipa
Jan 29, 2024
f4f96e4
test Export ipa
Jan 29, 2024
339f5bf
test find ipa
Jan 29, 2024
c97a4ad
modify archivePath
Jan 29, 2024
946c167
test add export-options
Jan 29, 2024
726d89a
test new options
Jan 29, 2024
e86c6ce
test vars.EXPORT_OPTIONS
Jan 29, 2024
aa1b472
fix double quotation
Jan 29, 2024
9c14dd5
test find ipa
Jan 29, 2024
bf1d9a3
ci: test for new cert
Jan 30, 2024
8d5b925
ci: simplify change to ad-hoc string format
Jan 30, 2024
1dc0f06
fix: add build-destination
Jan 30, 2024
2b1426c
fix: add export ipa
Jan 30, 2024
23edb19
ci: test add targets
Jan 31, 2024
310e964
test for macos latest
Jan 31, 2024
e32a2f5
update cert and profile test
Jan 31, 2024
46563be
chang configuration to debug
zhu-xiaowei Jan 31, 2024
1ab1455
ci: test for new certificat
Feb 1, 2024
ad25a58
add export-options
Feb 1, 2024
5c14a63
ci: test for no pwd
Feb 1, 2024
8e0c41a
ci: test development cert
Feb 1, 2024
0f9deeb
ci: test for root folder
Feb 1, 2024
9cea84d
ci: build ipa manually
Feb 1, 2024
4579348
ci: correct build path
Feb 1, 2024
e8b0e7a
ci: test automatic signing
Feb 1, 2024
22bc2f8
ci: test allowProvisioningUpdates
Feb 1, 2024
854918d
ci: delete allowProvisioningUpdates and change the team id
Feb 1, 2024
32799f6
ci: test for added provision profile and p12
Feb 1, 2024
184b894
ci: change to Release
Feb 1, 2024
3948f39
ci: remove ios build action and test device farm
Feb 1, 2024
3d83e1c
fix: update upload_df_file method and and unique attribute
Feb 1, 2024
8243732
release: clickstream Swift 0.9.3
Feb 1, 2024
813ff81
fix: revert tag action and specify exact pytest version
Feb 1, 2024
a0e30d9
ci: test file modify
Feb 1, 2024
03d2525
ci: test sed
Feb 1, 2024
9b9afdd
ci: fix sed command
Feb 1, 2024
aa8008b
fix: sed command for escapes
Feb 1, 2024
1584d46
fix: update code for device farm test
Feb 1, 2024
7424d2f
fix: change log content
Feb 1, 2024
e3a246e
ci: modify for prepare pr
Feb 1, 2024
925040d
fix: add fail_on_failure false
Feb 1, 2024
8d3ec18
ci: skip the failed test case due to device farm find element unstabl…
Feb 1, 2024
d9194f0
fix: support add first event in log
Feb 1, 2024
5dcf64e
fix: dynamic calculate extra event count
Feb 2, 2024
7ef6349
fix: update device farm name prefix
Feb 2, 2024
26c835b
fix: the order of screen view events
Feb 2, 2024
7e07e3b
fix: test upload event number
Feb 2, 2024
bc240d9
fix: add_end test case
Feb 2, 2024
f0a15a3
fix: first open and add to cart event
Feb 2, 2024
48286d7
ci: change job name
Feb 2, 2024
296d39b
ci: update xcode build command add quite
zhu-xiaowei Feb 2, 2024
3f1dc6a
fix: delete quite parameter
zhu-xiaowei Feb 2, 2024
3cc04c8
ci: add set pipe fail command
zhu-xiaowei Feb 2, 2024
9da5e88
ci: test xcpretty output
zhu-xiaowei Feb 2, 2024
735e794
fix: first two screen view events timestamp repeat
Feb 3, 2024
8f4a37a
ci: support local integrate clickstream swift SDK
Feb 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Integration Test

on:
pull_request:
branches: [ "main" ]

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: |
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#branch = main;#branch = $temp_branch;#g" ModerneShopping.xcodeproj/project.pbxproj
zhu-xiaowei marked this conversation as resolved.
Show resolved Hide resolved
git diff
- 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 | xcpretty
- 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-*/**
44 changes: 30 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
Expand All @@ -22,17 +22,33 @@ jobs:
chmod +x release.sh
./release.sh ${{ env.NEW_VERSION }}
git diff
git config user.name '${{ vars.USER_NAME }}'
git config user.email '${{ vars.USER_EMAIL }}'
git add .
git commit -m 'release: clickstream Swift ${{ env.NEW_VERSION }}'
git push
git tag ${{ env.NEW_VERSION }}
git push origin ${{ env.NEW_VERSION }}
- name: Create GitHub release
uses: softprops/action-gh-release@v1
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v5
with:
name: "Clickstream Swift ${{ env.NEW_VERSION }}"
tag_name: "${{ env.NEW_VERSION }}"
prerelease: true
generate_release_notes: true
token: ${{ secrets.PROJECT_TOKEN }}
commit-message: 'release: clickstream Swift ${{ env.NEW_VERSION }}'
title: 'release: clickstream Swift ${{ env.NEW_VERSION }}'
author: github-actions <[email protected]>
committer: github-actions <[email protected]>
signoff: true
body: |
## Description
1. release: clickstream Swift ${{ env.NEW_VERSION }}

## General Checklist
<!-- Check or cross out if not relevant -->

- [x] Added new tests to cover change, if needed
- [x] Build succeeds using Swift Package Manager
- [x] All unit tests pass
- [x] Documentation update for the change if required
- [x] PR title conforms to conventional commit style
- [x] If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

labels: release
branch: release_${{ env.NEW_VERSION }}
36 changes: 36 additions & 0 deletions .github/workflows/tag_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Create Tag And Release
on:
push:
branches: [ "main" ]

jobs:
release:
if: ${{ startsWith(github.event.head_commit.message, 'release:') }}
runs-on: ubuntu-latest
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PROJECT_TOKEN }}
- name: Create new tag
run: |
echo "${{ env.COMMIT_MESSAGE }}"
version=$(echo "${{ env.COMMIT_MESSAGE }}" | grep -oP 'Swift \K\d+\.\d+\.\d+')
echo "release_version=$version" >> "$GITHUB_ENV"
echo $version
git config user.name '${{ vars.USER_NAME }}'
git config user.email '${{ vars.USER_EMAIL }}'
git tag v$version
git push origin v$version
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
name: "Clickstream Swift ${{ env.release_version }}"
tag_name: "${{ env.release_version }}"
prerelease: true
generate_release_notes: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.idea
74 changes: 74 additions & 0 deletions IntegrationTest/appium/shopping_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
with the License. A copy of the License is located at

http://www.apache.org/licenses/LICENSE-2.0

or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
and limitations under the License.
"""
import pytest
from time import sleep

from appium import webdriver
from appium.options.ios import XCUITestOptions
from appium.webdriver.common.appiumby import AppiumBy
from selenium.common.exceptions import NoSuchElementException

capabilities = dict(
platformName='ios',
automationName='xcuitest',
deviceName='iPhone',
bundleId='software.aws.solution.ModerneShopping',
language='en',
locale='US',
)

appium_server_url = 'http://0.0.0.0:4723/wd/hub'


class TestShopping:
def setup_method(self):
self.driver = webdriver.Remote(appium_server_url, options=XCUITestOptions().load_capabilities(capabilities))
self.driver.implicitly_wait(10)

def teardown_method(self):
if self.driver:
self.driver.quit()

@pytest.mark.parametrize("test_suite", [
"test suite 1",
"test suite 2"
])
def test_shopping(self, test_suite):
sleep(3)
self.perform_click_element('Profile')
self.perform_click_element('sign_in')
sleep(3)
self.perform_click_element('Cart')
self.perform_click_element('check_out')
self.perform_click_element('purchase')
self.perform_click_element('Profile')
self.perform_click_element("sign_out")
self.driver.execute_script('mobile: backgroundApp', {"seconds": 5})
sleep(1)
self.perform_click_element("show_log_text")
event_log = self.driver.find_element(by=AppiumBy.ID, value="event_log")
self.driver.log_event("app_event_log", event_log.text)
print(event_log.text)
sleep(1)

def perform_click_element(self, element_id):
try:
element = self.driver.find_element(by=AppiumBy.ID, value=element_id)
element.click()
sleep(2)
except NoSuchElementException:
pytest.skip(f"Element with ID '{element_id}' not found. Skipped the test")


if __name__ == '__main__':
TestShopping.test_shopping()
Loading
Loading