-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #473 from Kommunicate-io/CM-2285
[CM-2285] Added Github Actions for Automation Testing.
- Loading branch information
Showing
13 changed files
with
394 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
name: iOS Automation Test Workflow | ||
|
||
on: | ||
pull_request: # Trigger this workflow on pull request events | ||
types: | ||
- opened | ||
|
||
jobs: | ||
build-and-test: | ||
name: Build and Test | ||
runs-on: macos-latest | ||
timeout-minutes: 45 # Prevents the workflow from hanging indefinitely | ||
|
||
steps: | ||
# Step 1: Checkout the code | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
# Step 2: Fetch PR Branch Information | ||
- name: Fetch PR Comments | ||
id: fetch-branches | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const prBody = context.payload.pull_request?.body; | ||
if (!prBody) { | ||
core.setFailed("No pull request body found."); | ||
return; | ||
} | ||
console.log("Pull request body:", prBody); // Debugging: log the PR body | ||
const kmChatUIBranchMatch = prBody.match(/KM_ChatUI_Branch\s*:\s*`([^`]+)`/); | ||
const kmCoreBranchMatch = prBody.match(/KM_Core_Branch\s*:\s*`([^`]+)`/); | ||
if (!kmChatUIBranchMatch || !kmCoreBranchMatch) { | ||
core.setFailed("No branch information found in the pull request body."); | ||
return; | ||
} | ||
core.setOutput("kmChatUIBranch", kmChatUIBranchMatch[1].trim()); | ||
core.setOutput("kmCoreBranch", kmCoreBranchMatch[1].trim()); | ||
# Step 3: Set up Xcode | ||
- name: Set up Xcode | ||
uses: maxim-lobanov/setup-xcode@v1 | ||
with: | ||
xcode-version: '16.1.0' | ||
|
||
# Step 4: Set Environment Variables | ||
- name: Set Environment Variables | ||
run: | | ||
echo "KM_CHATUI_BRANCH=${{ steps.fetch-branches.outputs.kmChatUIBranch }}" >> $GITHUB_ENV | ||
echo "KM_CORE_BRANCH=${{ steps.fetch-branches.outputs.kmCoreBranch }}" >> $GITHUB_ENV | ||
# Step 5: Install dependencies | ||
- name: Install Dependencies | ||
run: | | ||
pod install --project-directory=Example | ||
# Step 4: Install Certificates, Provisioning Profiles, and Set Up Keychain | ||
- name: Install Apple Certificate, Provisioning Profile, and Set Up Keychain | ||
env: | ||
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} | ||
P12_PASSWORD: ${{ secrets.P12_PASSWORD }} | ||
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }} | ||
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | ||
run: | | ||
# Define file paths | ||
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 | ||
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision | ||
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | ||
# Decode the 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 and configure a temporary keychain | ||
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | ||
security set-keychain-settings -lut 3600 $KEYCHAIN_PATH | ||
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | ||
security list-keychain -d user -s $KEYCHAIN_PATH | ||
# Import the certificate into the keychain | ||
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH | ||
# Copy the provisioning profile to the expected location | ||
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles | ||
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles | ||
# Step 5: Update Info.plist Files with Secrets | ||
- name: Append new key in Info.plist for Example | ||
run: | | ||
PLIST_PATH="Example/Kommunicate/Info.plist" | ||
KEY="KOMMUNICATE_APP_ID" | ||
VALUE="${{ secrets.KOMMUNICATE_APP_ID }}" | ||
/usr/libexec/PlistBuddy -c "Set :$KEY $VALUE" "$PLIST_PATH" || \ | ||
/usr/libexec/PlistBuddy -c "Add :$KEY string $VALUE" "$PLIST_PATH" | ||
cat "$PLIST_PATH" | ||
- name: Append new key in Info.plist for Tests | ||
run: | | ||
PLIST_PATH="Example/Tests/Info.plist" | ||
KEY="KOMMUNICATE_APP_ID" | ||
VALUE="${{ secrets.KOMMUNICATE_APP_ID }}" | ||
/usr/libexec/PlistBuddy -c "Set :$KEY $VALUE" "$PLIST_PATH" || \ | ||
/usr/libexec/PlistBuddy -c "Add :$KEY string $VALUE" "$PLIST_PATH" | ||
cat "$PLIST_PATH" | ||
- name: Append new key in Info.plist for UI Tests | ||
run: | | ||
PLIST_PATH="Example/Kommunicate_ExampleUITests/Info.plist" | ||
KEY="KOMMUNICATE_APP_ID" | ||
VALUE="${{ secrets.KOMMUNICATE_APP_ID }}" | ||
/usr/libexec/PlistBuddy -c "Set :$KEY $VALUE" "$PLIST_PATH" || \ | ||
/usr/libexec/PlistBuddy -c "Add :$KEY string $VALUE" "$PLIST_PATH" | ||
cat "$PLIST_PATH" | ||
# Step 6: Run Tests with Keychain Management | ||
- name: Run XCTest with Keychain | ||
env: | ||
KOMMUNICATE_APP_ID: ${{ secrets.KOMMUNICATE_APP_ID }} | ||
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} # Keychain password | ||
TEAM_ID: ${{ secrets.TEAM_ID }} # Apple Developer Team ID | ||
run: | | ||
# Unlock the keychain for signing during tests | ||
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | ||
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" | ||
# Run the tests, ensuring code signing is handled | ||
xcodebuild test \ | ||
-workspace Example/Kommunicate.xcworkspace \ | ||
-scheme Kommunicate_Example \ | ||
-destination 'platform=iOS Simulator,name=iPhone 16 Pro Max,OS=18.1' \ | ||
-enableCodeCoverage YES \ | ||
-derivedDataPath ./DerivedData \ | ||
CODE_SIGN_IDENTITY="iPhone Developer" \ | ||
CODE_SIGNING_ALLOWED=YES \ | ||
CODE_SIGNING_REQUIRED=YES \ | ||
DEVELOPMENT_TEAM="$TEAM_ID" \ | ||
KEYCHAIN="$KEYCHAIN_PATH" | ||
# Step 7: Print Test Results | ||
- name: Print Test Results | ||
run: | | ||
cat ./DerivedData/Logs/Test/*.xcresult/TestSummaries.plist || echo "No test results found." | ||
# Step 8: Debug Environment Variables (Optional) | ||
- name: Debug Environment Variables | ||
run: | | ||
echo "Environment variables set successfully." | ||
# Step 9: Post Test Results as a PR Comment | ||
- name: Post Test Results to PR | ||
if: github.event_name == 'pull_request' | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const path = './DerivedData/Logs/Test/*.xcresult/TestSummaries.plist'; | ||
let content = 'Test results not found.'; | ||
try { | ||
content = fs.readFileSync(path, 'utf8'); | ||
} catch (err) { | ||
console.log('Error reading test results:', err); | ||
} | ||
const comment = ` | ||
## iOS Automation Test Results | ||
Congratulations All Tests Passed! 🎉 | ||
`; | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: comment, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.