Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CI/CD for iOS Projects

Sebastian
February 12, 2019

CI/CD for iOS Projects

Continuous Integration & Delivery pipelines with GitHub, Travis CI, SwiftLint, Danger, HoundCI and HockeyApp.

GitHub Links:

iOS Project Template
https://github.com/messeb/ios-project-template

Setup an iOS Project Environment
https://github.com/messeb/ios-project-env-setup

Ansible iOS Build Server Provisioning
https://github.com/messeb/ansible-ios-build-server

Sebastian

February 12, 2019
Tweet

More Decks by Sebastian

Other Decks in Programming

Transcript

  1. Code clone it, fork it, star it 3 • iOS

    Project Template • https://github.com/messeb/ios-project-template • Setup an iOS Project Environment • https://github.com/messeb/ios-project-env-setup • Ansible iOS Build Server Provisioning • https://github.com/messeb/ansible-ios-build-server
  2. Disclaimer 4 • Based on my experience in projects •

    Changing team during project term • Working conditions • Git as SCM • GitLab or GitHub as Git frontend • Build server / service is present in the project
  3. CI? CD? CD? 5 • Continuous Integration • Constant integration

    of new features in main app branch • Verification of integration • Continuous Delivery • Build a release version with new features • Continuous Deployment • Bring the app live to customers • (Internal testers, product owner)
  4. Everything as Code 6 App Tests Project Setup Build CI/CD

    Pipeline Quality Checks Deploy- ment Infrastructure
  5. Everything as Code Why? 7 • Automation of manual steps

    • Traceable of everything • Open for contributions • Versioned state
  6. Infrastructure as Code 9 • iOS Buildserver • macOS 10.14

    • Connected to SCM • Build Service • Travis CI, Bitrise, Circle CI • own Hardware • Xcode installation and GitLab CI Runner, Jenkins
  7. Infrastructure as Code Build Service 10 • Travis CI, Circle

    CI, Bitrise • Simple configuration in project • Mostly GitHub.com only solutions # .travis.yml language: objective-c osx_image: xcode10.1 # .circleci/config.yml version: 2 jobs: build: macos: xcode: "10.1"
  8. Infrastructure as Code Own Hardware 11 • Self-administered installation of

    components • Determine required preinstalled components • Xcode • Homebrew • RVM (Ruby Version Manager) • iOS Project contains other dependencies (Project setup, Build) • Solution: Ansible
  9. Infrastructure as Code Ansible 12 • software for the centralized

    management and administration of distributed servers • Connects over SSH to build servers (without agent) • Install components over predefined commands or custom commands • Can be run in an additional CI Pipeline
  10. Infrastructure as Code Ansible (Example) 13 # macOS updates &

    configuration - name: Install macOS updates command: softwareupdate -i -a --restart - name: Disable computer sleep command: systemsetup -setcomputersleep Never become: true # Homebrew update - name: Install Homebrew command: bash -c "\curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install | ruby” # Xcode download - name: Query Xcode download command: ruby ~/xcode-download.rb
  11. Project Setup 14 • Installs all dependencies • Homebrew packages

    • Ruby Gems • Project frameworks • For new team members and build server (Pipeline) • Build server doesn‘t read README.md • Should be only one command
  12. Project Setup 15 • make with Makefile is a good

    solution • Defined execution order of task (targets) • Command: make bootstrap (make release_build) # Makefile default: bootstrap bootstrap: \ check_for_rvm \ check_for_homebrew \ update_homebrew \ install_bundler_gem \ install_ruby_gems \ install_cocoapods # Install Cocopods dependencies install_cocoapods: $(info Install Cocoapods ...) bundle exec pod install
  13. Project / Build Setup 16 • Configuration of build artefacts

    in project • + encrypted Certificates & Profiles in app repo • Independent from build tool and server (Build) • Build tool configures environment
  14. Build Setup fastlane as build tool 17 • fastlane (https://fastlane.tools)

    • Ruby frontend for xcodebuild • Own „domain specific language“ • Provides actions for typical tasks • App individualizations, like icon bagdes • Distribution of app • Extendable with plugins or custom Ruby code
  15. Build Setup fastlane as build tool 18 Usage # Fastfile

    lane :test do run_tests(scheme: 'iOSProject') end lane :release do build_ios_app( scheme: 'iOSProject', export_method: 'app-store', configuration: 'Release' ) upload_to_testflight(skip_submission: true) end $ fastlane test $ fastlane release
  16. Build Setup Usage of fastlane 19 • Creates build environment

    on build server • Decrypts certificates & provisioning profiles • Creates keychain & copy profiles • App customizations • Build (Dev, Stage, Prod) (Pipeline) • with Xcode configuration
  17. Quality Checks 20 • Predefined team rules • Code Style

    • Test coverage • Commit rules • Local & Pull Requests (Pipeline) • Local: Xcode run scripts, git hooks • Build server: fastlane • Keep annoying discussion from the team members
  18. Quality Checks Swiftlint 21 • Prevents code smells • Force

    casts • Non-weak delegate • Uniform code style • Rules in .swiftlint • Local & Pull Requests
  19. Quality Checks Codecov 22 • Test coverage as „quality indicator“

    • Test coverage for new features • Visualization of test coverage to identify gaps
  20. Quality Checks Danger 23 • „Linter“ for Pull Requests (https://danger.systems)

    • Custom Rulesets • E.g. entry in CHANGELOG.md file missing • Works as bot user on GitHub, GitLab & BitBucket • Info, Warning, Error messages
  21. Quality Checks Danger 24 # Dangerfile # changes in the

    project folder has_app_changes = !git.modified_files.grep(/iOSProject/).empty? # Changelog entries are required for changes to library files. no_changelog_entry = !git.modified_files.include?("CHANGELOG.yml") if has_app_changes && no_changelog_entry warn("Any meaningful changes to the project ....") end
  22. Delivery / Deployment 25 • In House • During development

    with Auto-Updates • Services: Crashlytics Beta, HockeyApp • Ad-hoc or enterprise distribution • App Store • Testflight • App Store distribution • fastlane actions for distributions
  23. Pipeline 27 • Description of CI / CD process •

    In app repository • Not in Jenkins input fields • Not as visual workflow • Runs the same code as a developer • Prevents untraceable errors • Use abstraction of Project Setup and Build
  24. Pipeline 28 • Description of CI / CD process •

    In app repository • Not in Jenkins input fields • Not as visual workflow • Runs the same code as a developer • Prevents untraceable errors • Use abstraction of Project Setup and Build
  25. Pipeline 29 • Description of CI / CD process •

    In app repository • Not in Jenkins input fields • Not as visual workflow • Runs the same code as a developer • Prevents untraceable errors • Use abstraction of Project Setup and Build
  26. Pipeline Rules 30 # .gitlab-ci.yml before_script: - make bootstrap stages:

    - test - build test: stage: test script: - make test tags: - Xcode10.0 release_build: stage: build only: - /^release\/.+$/ except: - branches script: - make release_build # .travis.yml language: objective-c osx_image: xcode10.1 install: make bootstrap stages: - build jobs: include: - name: Pull Request if: type = pull_request stage: build script: make pull_request - name: Staging if: branch = master stage: build script: make staging_build - name: Release if: tag IS present stage: build script: make release_build
  27. Pipeline Rules 31 • Feature Branch / Pull Request •

    Tests • Quality Checks • Merge to develop / master • Build & distribute develop / stage app version • Release Tag • Build & Distribute App Store version
  28. Conclusion 32 • IaaS: Build services are good solutions •

    Project Setup: Configure your project build-ready • Build / Distribution: use fastlane • Quality-Checks: Run during development • Pipeline: Visible for developers & execute same code