[CM-82] Add linter in all the repos | iOS SDK #17
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
name: iOS Automation Test Workflow | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize # Triggers when a new commit is pushed to the PR | |
concurrency: | |
group: pr-${{ github.event.pull_request.number }} | |
cancel-in-progress: true | |
jobs: | |
# Lint Job | |
lint: | |
name: "Run Lint Checks" | |
runs-on: macos-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Xcode | |
uses: maxim-lobanov/setup-xcode@v1 | |
with: | |
xcode-version: '16.1.0' | |
- name: Install Certificates and Provisioning Profiles | |
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: | | |
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 | |
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision | |
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | |
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH | |
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH | |
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 | |
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH | |
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles | |
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles | |
- name: Run Linter Check | |
env: | |
KOMMUNICATE_APP_ID: ${{ secrets.KOMMUNICATE_APP_ID }} | |
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | |
run: | | |
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | |
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" | |
pod lib lint --allow-warnings | |
- name: Debug Environment Variables (Optional) | |
run: echo "Environment variables set successfully." | |
- name: Post Test Results to PR | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const comment = `## iOS Automation Test Results\nCongratulations Linter Check Passed! 🎉`; | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment, | |
}); | |
# Build and Test Job | |
build-and-test: | |
name: Build and Test | |
runs-on: macos-latest | |
timeout-minutes: 45 | |
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, | |
}); |