[Xcode] How CI/CD work
Recently I just integrate Codemagic to my Capstone Project and I found something interesting.
How they work ?
- First machine used by many people
- Second how machine used specific Certificate
- Third how machine embed specific Provisioning Profile
- Fourth Run xcodebuild with specific configuration
Previously I didnt notice how they work because we just use tools like Fastlane etc, and we just Run it locally. After I integrate Codemagic my curiosity arose. So I try to understand how they work correctly.
From image above we seeing that fist
- Machine is prepared by system
- Fetching app sources : Downloading app from github
- Setup signing code : This mean, machine downloading Certificate from backend
- Keychain Initialize : Create and Set Keychain (I need to learn more about this)
- Add Certificate to Keychain
- Setup Provisioning Profile to project
- Then Run Test (This is our script that we need to run)
- Build Debug (This is our script that we need to run)
- Publishing : Uploading artifact
- Cleaning
workflows:
ios-project-debug:
name: iOS debug
environment:
xcode: latest
cocoapods: default
vars:
XCODE_PROJECT: "[PROJECT NAME].xcodeproj"
XCODE_SCHEME: "[PROJECT SCHEME]"
ios_signing:
distribution_type: development
bundle_identifier: [YOUR BUNDLE ID]
scripts:
- script: keychain initialize
- script: keychain add-certificates
- script: xcode-project use-profiles
- name: Run tests
script: |
xcodebuild clean test \
-project "$XCODE_PROJECT" \
-scheme "$XCODE_SCHEME" \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 14 Pro Max,OS=16.1'
- name: Build debug app
script: |
xcodebuild build -project "$XCODE_PROJECT" \
-scheme "$XCODE_SCHEME" \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
artifacts:
- $HOME/Library/Developer/Xcode/DerivedData/**/Build/**/*.app
publishing:
email:
recipients:
- xxx@gmail.com [YOUR EMAIL]
Oke what if we want replicate that command in local our machine, so we need to register CODE_SIGN_IDENTITY and PROVISIONING_PROFILE every xcodebuild command (Let’s assume the certificate and provisioning profile has been installed).
First we need to know our installed CODE_SIGN_IDENTITY, so how we know ? Use this command in terminal
security find-identity -v -p codesigning
1) xxxxxxxxxxxxxxxxxxxxxxxxxxx "Apple Development: YOUR NAME (YOUR TEAM)"
Next we need to know all Provisioning Profile installed
cd ~/Library/MobileDevice/Provisioning\ Profiles ls
xxxxxxxxxxxxxxxxxxxxxxxxxxx.mobileprovision xxxxxxxxxxxxxxxxxxxxxxxxxxx.mobileprovision
xxxxxxxxxxxxxxxxxxxxxxxxxxx.mobileprovision
After we got all what we need we can start Run command script, for example I want Run Unit Test.
xcodebuild clean test -project [PROJECT NAME].xcodeproj -scheme [SCHEME NAME] -sdk iphonesimulator -destination “platform=iOS Simulator,name=iPhone 14 Pro,OS=16.2” PROVISIONING_PROFILE=“xxxxxxxxxxxxxxxxxxxxxxxxxxx” CODE_SIGN_IDENTITY="Apple Development"
Done, just Enter and let see !!