Ci for i-os-codemash-01.2013

124
CI for iOS: do more while you sleep Kevin Munc @muncman Method Up LLC [MU]

description

CI for iOS. CodeMash version.

Transcript of Ci for i-os-codemash-01.2013

Page 1: Ci for i-os-codemash-01.2013

CI for iOS:do more while you sleep

Kevin Munc – @muncmanMethod Up LLC

[MU]

Page 2: Ci for i-os-codemash-01.2013

CI?

Page 3: Ci for i-os-codemash-01.2013

For iOS?

Page 4: Ci for i-os-codemash-01.2013
Page 5: Ci for i-os-codemash-01.2013

Pain

Page 6: Ci for i-os-codemash-01.2013

Pain & Suffering

Page 7: Ci for i-os-codemash-01.2013

It can be done

• Start with the basics

• Xcode and the command line

• Version control and CI server

• Script it, run it, schedule it

Page 8: Ci for i-os-codemash-01.2013

Tip #1

Page 9: Ci for i-os-codemash-01.2013

Jenkins

• http://jenkins-ci.org/

• Mac installer or via homebrew

• Many alternatives

• Many plugins

Page 10: Ci for i-os-codemash-01.2013
Page 11: Ci for i-os-codemash-01.2013

Tip #1.1

Page 12: Ci for i-os-codemash-01.2013

How many Simulators does it take to break a build?

Page 13: Ci for i-os-codemash-01.2013

A CI server gives you:

Page 14: Ci for i-os-codemash-01.2013

A CI server gives you:

Automation

Page 15: Ci for i-os-codemash-01.2013

A CI server gives you:

Automation

Feedback

Page 16: Ci for i-os-codemash-01.2013

A CI server gives you:

Automation

FeedbackWonderful!

Page 17: Ci for i-os-codemash-01.2013

A CI server gives you:

Automation

FeedbackWonderful!

Peace o

f mind

(for bette

r naps)

Page 18: Ci for i-os-codemash-01.2013

Requirement: OS X

Page 19: Ci for i-os-codemash-01.2013

Requirement:

• macminicolo.net

• hosted-ci.com

• cisimple.com

• macincloud.com

• hostmyapple.com

• macminivault.com

• xcloud.me

OS X

Page 20: Ci for i-os-codemash-01.2013

Requirement:

• macminicolo.net

• hosted-ci.com

• cisimple.com

• macincloud.com

• hostmyapple.com

• macminivault.com

• xcloud.me

OS X

Or schedule CI to run at night,

on your own Mac,

while you sleep...

Page 21: Ci for i-os-codemash-01.2013

Securitysudo /usr/sbin/DevToolsSecurity --enable

Page 22: Ci for i-os-codemash-01.2013

Security

sudo xcodebuild -license

Page 23: Ci for i-os-codemash-01.2013

Credentials

• The CI server needs access to your repository

• SSH key

• The CI server needs Keychain credentials if you want to sign your builds

• Developer certificate and profiles

Page 24: Ci for i-os-codemash-01.2013

Keychain

• Export and Import using Keychain Access app

• Keys and Certificates

• Or use the command line:• sudo security import /path/to/distribution.cer -k /Library/Keychains/

System.keychain

• sudo security import /path/to/distribution.p12 -k /Library/Keychains/System.keychain

• Don’t forget about provisioning profiles

• Troubleshooting: http://tinyurl.com/iOSDevToolTroubles

Page 25: Ci for i-os-codemash-01.2013

Tip #2

Page 26: Ci for i-os-codemash-01.2013

Avoid this error from Xcode

RunPlatformUnitTests: warning: Skipping tests;

the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set).

Page 27: Ci for i-os-codemash-01.2013

The culprit

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests

Page 28: Ci for i-os-codemash-01.2013

The workaround(s)

Page 29: Ci for i-os-codemash-01.2013

Xcode Plugin

• https://wiki.jenkins-ci.org/display/JENKINS/Xcode+Plugin

• Specify provisioning profile

• Keychain access

• Signed IPA

Page 30: Ci for i-os-codemash-01.2013

Xcode Plugin

• Recommended xcodebuild arguments:

• GCC_SYMBOLS_PRIVATE_EXTERN=NO

• COPY_PHASE_STRIP=NO

• Allows test bundle to link with Release build symbols

Page 31: Ci for i-os-codemash-01.2013

Signing with the Plugin

Page 32: Ci for i-os-codemash-01.2013

Signing with the Plugin

Page 33: Ci for i-os-codemash-01.2013

Signing with the Plugin

Page 34: Ci for i-os-codemash-01.2013

Tip #3

Page 35: Ci for i-os-codemash-01.2013

Prefer Scripts over CI Plugins

• More flexibility

• More resilient to Apple’s changes

• More power to adapt and expand (specificity)

• Less coupling to the specific CI server type

• You can version control the settings easier

Page 36: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ clean build

Page 37: Ci for i-os-codemash-01.2013

Tip #4

Page 38: Ci for i-os-codemash-01.2013

Be specific with xcodebuild options

Page 39: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 40: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 41: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 42: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 43: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 44: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 45: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 46: Ci for i-os-codemash-01.2013

xcodebuild

xcodebuild \ -scheme SOLID \ -target SOLID \ -configuration Debug \ -arch i386 \ -sdk iphonesimulator \ clean build

Page 47: Ci for i-os-codemash-01.2013

Tip #5

Page 48: Ci for i-os-codemash-01.2013

Specify Alternate Output Locations

• Don’t rely on Xcode’s cryptic locations

• This will make your scripts easier to manage

Page 49: Ci for i-os-codemash-01.2013

# Build location for Instruments test runs. CI_BUILD_DIR=/tmp/SOLID_AUTOMATIONmkdir -p $CI_BUILD_DIR

xcodebuild \ ... \ CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR \ clean build

Page 50: Ci for i-os-codemash-01.2013

# Build location for Instruments test runs. CI_BUILD_DIR=/tmp/SOLID_AUTOMATIONmkdir -p $CI_BUILD_DIR

xcodebuild \ ... \ CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR \ clean build

Page 51: Ci for i-os-codemash-01.2013

# Build location for CI test runs. CI_BUILD_DIR=/tmp/SOLID_AUTOMATIONmkdir -p $CI_BUILD_DIR

xcodebuild \ ... \ CONFIGURATION_BUILD_DIR=$CI_BUILD_DIR \ clean build

Page 52: Ci for i-os-codemash-01.2013

Demo

Page 53: Ci for i-os-codemash-01.2013

Tip #6

Page 54: Ci for i-os-codemash-01.2013

Ensure Return Codes

• If the tool you are invoking in your script doesn’t return an exit code indicating pass/fail, it’s up to you.

• Unix-friendly 0 (success) or 1 (failure)

Page 55: Ci for i-os-codemash-01.2013

Tip #7

Page 56: Ci for i-os-codemash-01.2013

Test against multiple SDKs

-sdk iphonesimulator5.0-sdk iphonesimulator5.1-sdk iphonesimulator6.0

Page 57: Ci for i-os-codemash-01.2013
Page 58: Ci for i-os-codemash-01.2013

Other Tools to Know About

• xcode-select (manage xcode path)

• Overridden by DEVELOPER_DIR

• xcrun (find and run dev tools)

• ibtool (for Interface Builder files)

• /Applications/Xcode.app/Contents/Developer/usr/bin/

• Variables in Xcode

• “Build Settings Reference”

Page 59: Ci for i-os-codemash-01.2013
Page 60: Ci for i-os-codemash-01.2013

OCUnit

Page 61: Ci for i-os-codemash-01.2013

Other Related Tools

Page 62: Ci for i-os-codemash-01.2013

Other Related Tools• OCMock

• OCMockito

• OCHamcrest

• Expecta

• TinyMock

• LRMocky

• OCUnit2JUnit

• OCUnitReport

• Kicker

• xcodebuild-rb

• xcodearchive

• XcodeTest

• AutoBuild

• xcodeproj (CocoaPods)

• Circle?

• Simon?

• ios-maven-plugin

• Ceedling

• XcodeCoverage

• JMRTestTools

• Nocilla

• OHHTTPStubs

Page 63: Ci for i-os-codemash-01.2013

OCUnit Alternatives

• Kiwi

• Cedar

• OCDSpec

• C++ Automated Test Cases in Headers (CATCH)

• Objective-Shoulda

• Specta

Page 64: Ci for i-os-codemash-01.2013

Tip #8

Page 65: Ci for i-os-codemash-01.2013

OCUnit2JUnit for Test Results

• ocunit2junit.rb

• https://github.com/ciryon/OCUnit2JUnit

• Converts output to JUnit format for easier transformation to HTML

Page 66: Ci for i-os-codemash-01.2013
Page 67: Ci for i-os-codemash-01.2013

UIAutomation

Page 68: Ci for i-os-codemash-01.2013

Other UIAutomation Tools

• tunup_js

• jasmine-iphone

• uiautomation-jasmine-iphone

• Bwoken

• Zucchini Framework

• WaxSim

• ios-sim

• ios-sim-locale

• iphonesim

• ui-auto-monkey

• ui-screen-shooter

• uiautomation-rb?

Page 69: Ci for i-os-codemash-01.2013

UIAutomation Alternatives

• Frank

• (iCuke)

• KIF

• Calabash

• UISpec

• Bromine

• Objective C Slim (ocslim)

• AutomationKit

• Sikuli

• MonkeyTalk (formerly FoneMonkey)

• Plus other commercial tools, such as Telerik Test Studio for iOS

Page 70: Ci for i-os-codemash-01.2013
Page 71: Ci for i-os-codemash-01.2013

Tip #9

Page 72: Ci for i-os-codemash-01.2013

PListBuddy is Your Buddy

/usr/libexec/PlistBuddy

Page 73: Ci for i-os-codemash-01.2013
Page 74: Ci for i-os-codemash-01.2013

Tip #10

Page 75: Ci for i-os-codemash-01.2013

Always quit the simulator

• killall

• killall -m -KILL "iPhone Simulator"

• AppleScript

• osascript -e 'tell app "iPhone Simulator" to quit'

Page 76: Ci for i-os-codemash-01.2013

Tip #11

Page 77: Ci for i-os-codemash-01.2013

Use Jonathan Penn’s AutomationExample

https://github.com/jonathanpenn/AutomationExample

Page 78: Ci for i-os-codemash-01.2013

Demo

Page 79: Ci for i-os-codemash-01.2013

More?

Page 80: Ci for i-os-codemash-01.2013

Code Coverage

“Risk coverage”

Page 81: Ci for i-os-codemash-01.2013

Coverage Tools

• gcov

• GCC’s coverage tool

• GUIs for gcov

• LCOV (HTML)

• CoverStory (Mac app)

• ocov?

Page 82: Ci for i-os-codemash-01.2013

Tip #12

Page 83: Ci for i-os-codemash-01.2013

gcovr for Coverage Automation

Produces Cobertura-formatted output from gcov data

Page 84: Ci for i-os-codemash-01.2013

Tip #12.1

Page 85: Ci for i-os-codemash-01.2013

Enable Test Coverage

Page 86: Ci for i-os-codemash-01.2013
Page 87: Ci for i-os-codemash-01.2013

Static Analysis

• Clang

• http://clang-analyzer.llvm.org/

• scan-build

Page 88: Ci for i-os-codemash-01.2013

Tip #13

Page 89: Ci for i-os-codemash-01.2013

Symbolic links can be your ally

Page 90: Ci for i-os-codemash-01.2013

Avoid scan-build Painsudo ln -s \

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/

libarclite_iphonesimulator.a \/usr/lib/arc/libarclite_iphonesimulator.a

Page 91: Ci for i-os-codemash-01.2013
Page 92: Ci for i-os-codemash-01.2013
Page 93: Ci for i-os-codemash-01.2013

What about test build deployment?

Page 94: Ci for i-os-codemash-01.2013

Tip #14

Page 95: Ci for i-os-codemash-01.2013

Use TestFlight

• testflightapp.com

• OTA deployment

• SDK for more features

• Free!!

Page 96: Ci for i-os-codemash-01.2013

TestFlight

• Web UI

• Desktop App

• REST API

• Jenkins Plugin

Page 97: Ci for i-os-codemash-01.2013

TestFlight Alternatives

• HockeyApp

• http://hockeyapp.net

• Also has a Jenkins plugin (forked)

• BetaBuilder for iOS

• http://www.hanchorllc.com/betabuilder-for-ios/

• More players in this space, esp. for enterprises...

Page 98: Ci for i-os-codemash-01.2013

TestFlight Config

• API Token and Team Token

• Need a signed IPA

• They get an email with a link for OTA installation!

Page 99: Ci for i-os-codemash-01.2013

Tip #15

Page 100: Ci for i-os-codemash-01.2013

Protect Your Tokens

• API Token & Team Token

• Keep them out of scripts

• Instead, define them in Jenkins (and leverage Jenkins security)

• 'Configure System'

• 'Global properties' section

• Or use the plugin (same parameters)

Page 101: Ci for i-os-codemash-01.2013

TestFlight Plugin

Page 102: Ci for i-os-codemash-01.2013

TestFlight Script

Page 103: Ci for i-os-codemash-01.2013

Deployment

Page 104: Ci for i-os-codemash-01.2013

Deployment

Page 105: Ci for i-os-codemash-01.2013

Q: Once you have a nightly job to build, unit test, sign an IPA and deploy it to QA,

what’s next?

Page 106: Ci for i-os-codemash-01.2013

Q: Once you have a nightly job to build, unit test, sign an IPA and deploy it to QA,

what’s next?

A: Sleeping easy.

Page 107: Ci for i-os-codemash-01.2013

Documentation

• Appledoc

• Doxygen

• HeaderDoc

Page 108: Ci for i-os-codemash-01.2013

DocSets

Page 109: Ci for i-os-codemash-01.2013

Appledoc

Page 110: Ci for i-os-codemash-01.2013

Doxygen

Page 111: Ci for i-os-codemash-01.2013

Tip #16

Page 112: Ci for i-os-codemash-01.2013

Don’t stop there!

Page 113: Ci for i-os-codemash-01.2013

Other Goodies

Page 114: Ci for i-os-codemash-01.2013

Other Goodies

• Ensure your site or API is up

• Scan your code for TODOs and FIXMEs

• Get trend reports for lines of code (SLOCCount w/ sloc2html)

• Scan for duplicated blocks of code (CPD, Simian, etc.)

• Use agvtool (Apple-Generic Versioning Tool) to increment your build number

Page 115: Ci for i-os-codemash-01.2013
Page 116: Ci for i-os-codemash-01.2013
Page 117: Ci for i-os-codemash-01.2013

Still Missing

• Cyclomatic Complexity

• Coding convention/Style checker

• Code Formatter

• Uncrustify, UniversalIndentGUI

• UML Generation

• via CLI, as opposed to OmniGraffle (AppleScript?)

• ER Diagram from Core Data schema

Page 118: Ci for i-os-codemash-01.2013

Tip #n

Page 119: Ci for i-os-codemash-01.2013
Page 120: Ci for i-os-codemash-01.2013
Page 121: Ci for i-os-codemash-01.2013
Page 123: Ci for i-os-codemash-01.2013

Thank you!

• CodeMash organizers

• CodeMash sponsors

• and YOU!

[MU]

Page 124: Ci for i-os-codemash-01.2013

Thank you!

• CodeMash organizers

• CodeMash sponsors

• and YOU!

Questions?

[MU]