Slide 1

Slide 1 text

GETTING STARTED WITH XCODE CLOUD april 18, 2023 NEW YORK NY Swifty

Slide 2

Slide 2 text

Who am I? πŸ‘¨πŸ’» Senior software engineer at the BBC ✍ Weekly blog writer at polpiella.dev πŸ“¬ iOS CI/CD Newsle tt er curator 🐝 Based in Manchester πŸ“ From Barcelona

Slide 3

Slide 3 text

What I’ll talk about β€’ What is CI/CD and why do you need it? β€’ What is Xcode Cloud? β€’ Two workflows β€’ Programmatic Xcode Cloud runs β€’ Custom Xcode Cloud functionality

Slide 4

Slide 4 text

What is CI/CD and why do you need it?

Slide 5

Slide 5 text

What is CI/CD? - RedHat β€œContinuous Integration and Continuous Deployment is a method to frequently deliver apps to customers by introducing automation into the stages of app development.”

Slide 6

Slide 6 text

Push a new tag Notify of a change Perform action Report action output Submit Send m essage Trigger a scheduled work fl ow

Slide 7

Slide 7 text

β€’ Automate complex processes β€’ Schedule repetitive tasks β€’ Flexibility and scalability β€’ Build con fi dence on your codebase β€’ Guard against vulnerabilities β€’ Enforce code styles Why do you need CI/CD?

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

What is Xcode Cloud?

Slide 10

Slide 10 text

β€’ Apple’s CI/CD service β€’ Equivalent to GHA, Bitrise, etc. β€’ Deeply integrated into Xcode and App Store Connect β€’ Introduced in WWDC21 β€’ Subscriptions were available from August 2022 What is Xcode Cloud?

Slide 11

Slide 11 text

How does it work? β€’ Products, Work fl ows and Builds. β€’ Product represents your app in Xcode Cloud. β€’ Multiple work fl ows in a product. β€’ Builds are runs of a speci fi c work fl ow.

Slide 12

Slide 12 text

The anatomy of a workflow β€’ Where - Environment β€’ macOS version, Xcode version, Environment variables and secrets, Clean β€’ When - Start conditions β€’ Branch, PR, Tag, Scheduled β€’ What - Actions + Post-Actions β€’ Actions β€’ Build, Test - Multiple devices and versions, Archive and Analyse β€’ Post-Actions β€’ Deploy to Test fl ight, send Slack messages and send emails

Slide 13

Slide 13 text

Where can workflows run? β€’ macOS runners β€’ Set up per-work fl ow β€’ Multiple Xcode versions available β€’ Multiple macOS versions available β€’ No self-hosted runners β€’ Very app focused

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Pricing

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Let’s break it down and let’s read the small le tt er πŸ˜… β€’ A compute hour = 60 minutes of cloud execution. β€’ 12 serial tasks of 5 minutes each = 1 compute hour β€’ 12 parallel tasks of 5 minutes each = 1 compute hour. β€’ 25 free hours - It is more than you think! ⚠ Free tier ends in December 2023! It’s going to be $14.99/month on the cheapest plan

Slide 19

Slide 19 text

Let’s break it down and let’s read the small le tt er πŸ˜…

Slide 20

Slide 20 text

Setting up an Xcode Cloud product

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

h tt ps://www.kodeco.com/36548823-ge tt ing-started-with-xcode-cloud

Slide 34

Slide 34 text

The main workflow Full blog explanation

Slide 35

Slide 35 text

The main workflow β€’ Triggered on every push to the main branch β€’ Runs all unit tests β€’ Archives the app β€’ Distributes the app to AppCenter β€’ Distributes the app to internal testers β€’ Noti fi es a slack channel on completion β€’ Needs to make use of cocoapods ⚠ πŸ§ͺ

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

. β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh

Slide 50

Slide 50 text

#! /bin/sh . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh

Slide 51

Slide 51 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh

Slide 52

Slide 52 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then # πŸ“ Set the install path to a local directory bundle config set -- local path 'vendor' fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh

Slide 53

Slide 53 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then # πŸ“ Set the install path to a local directory bundle config set -- local path 'vendor' # ⬇ Install all dependencies bundle install fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh

Slide 54

Slide 54 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then # πŸ“ Set the install path to a local directory bundle config set -- local path 'vendor' # ⬇ Install all dependencies bundle install # β˜• Install all pods bundle exec pod install fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh

Slide 55

Slide 55 text

. β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh β”‚ └── ci_post_xcodebuild.sh

Slide 56

Slide 56 text

#! /bin/sh . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh β”‚ └── ci_post_xcodebuild.sh

Slide 57

Slide 57 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh β”‚ └── ci_post_xcodebuild.sh

Slide 58

Slide 58 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then # πŸ†™ Go one directory up cd .. fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh β”‚ └── ci_post_xcodebuild.sh

Slide 59

Slide 59 text

#! /bin/sh if [[ $CI_WORKFLOW == "Main" ]]; then # πŸ†™ Go one directory up cd .. # πŸƒ Run the custom lane ... bundle exec fastlane upload_to_appcenter fi . β”œβ”€β”€ ci_scripts β”‚ └── ci_post_clone.sh β”‚ └── ci_post_xcodebuild.sh

Slide 60

Slide 60 text

default_platform(:mac) platform :mac do desc "Description of what the lane does" lane :upload_to_appcenter do archive_path_dir = ENV["CI_ARCHIVE_PATH"] pkg_file = File.join(archive_path_dir, "Products", "Applications", "QReate.app") dsym_file = File.join(archive_path_dir, "dSYMs", "QReate.app.dSYM") appcenter_upload( api_token: ENV["APP_CENTER_API_TOKEN"], owner_name: "polpielladev", app_name: "QReate", release_notes: "Bug fixing and new features", file: pkg_file, dsym: dsym_file, notify_testers: false ) end end

Slide 61

Slide 61 text

default_platform(:mac) platform :mac do desc "Description of what the lane does" lane :upload_to_appcenter do archive_path_dir = ENV["CI_ARCHIVE_PATH"] pkg_file = File.join(archive_path_dir, "Products", "Applications", "QReate.app") dsym_file = File.join(archive_path_dir, "dSYMs", "QReate.app.dSYM") appcenter_upload( api_token: ENV["APP_CENTER_API_TOKEN"], owner_name: "polpielladev", app_name: "QReate", release_notes: "Bug fixing and new features", file: pkg_file, dsym: dsym_file, notify_testers: false ) end end

Slide 62

Slide 62 text

default_platform(:mac) platform :mac do desc "Description of what the lane does" lane :upload_to_appcenter do archive_path_dir = ENV["CI_ARCHIVE_PATH"] pkg_file = File.join(archive_path_dir, "Products", "Applications", "QReate.app") dsym_file = File.join(archive_path_dir, "dSYMs", "QReate.app.dSYM") appcenter_upload( api_token: ENV["APP_CENTER_API_TOKEN"], owner_name: "polpielladev", app_name: "QReate", release_notes: "Bug fixing and new features", file: pkg_file, dsym: dsym_file, notify_testers: false ) end end

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Scheduling a weekly build

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Let’s schedule a build with Xcode Cloud πŸŽ‰ β€’ A build from the latest main commit β€’ Every Sunday evening β€’ Released only to external testers (me πŸ˜…) β€’ Once I have gathered feedback, I can release the version.

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Building custom Xcode Cloud functionalities Full blog explanation

Slide 75

Slide 75 text

β€’ Upload internal TestFlight builds on PRs β€’ I don’t want to upload automatically on every PR change β€’ I want to do this step manually β€’ I would like to trigger a build directly from the PR page. Building a custom start condition

Slide 76

Slide 76 text

How does it work? issue_comment Webhook Trigger a new work fl ow API upload to Test fl ight Comment on a PR

Slide 77

Slide 77 text

h tt ps://developer.apple.com/documentation/appstoreconnectapi/

Slide 78

Slide 78 text

{ "action": "created", "issue": { "pull_request": { "url": β€œhttps: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } } GitHub issue_comment webhook

Slide 79

Slide 79 text

GitHub issue_comment webhook { "action": "created", "issue": { "pull_request": { "url": β€œhttps: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } } /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function

Slide 80

Slide 80 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function { "action": "created", "issue": { "pull_request": { "url": β€œhttps: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } }

Slide 81

Slide 81 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function let productId: String let repositoryId: String { "action": "created", "issue": { "pull_request": { "url": β€œhttps: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } }

Slide 82

Slide 82 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function let productId: String let repositoryId: String { "action": "created", "issue": { "pull_request": { "url": β€œhttps: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } } /v1/ciProducts/productId/work fl ows? fi elds[ciWork fl ows]=name

Slide 83

Slide 83 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function let productId: String let repositoryId: String { "action": "created", "issue": { "pull_request": { "url": β€œhttps: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } } /v1/ciProducts/productId/work fl ows? fi elds[ciWork fl ows]=name let workflowId: String

Slide 84

Slide 84 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function let productId: String let repositoryId: String /v1/ciProducts/productId/work fl ows? fi elds[ciWork fl ows]=name let workflowId: String /repos/OWNER/REPO/pulls/PULL_NUMBER { "action": "created", "issue": { "pull_request": { "url": "https: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } }

Slide 85

Slide 85 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function let productId: String let repositoryId: String /v1/ciProducts/productId/work fl ows? fi elds[ciWork fl ows]=name let workflowId: String /repos/OWNER/REPO/pulls/PULL_NUMBER { "action": "created", "issue": { "pull_request": { "url": "https: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } } /v1/scmRepositories/repositoryId/gitReferences let gitReferenceId: String

Slide 86

Slide 86 text

GitHub issue_comment webhook /v1/ciProducts? fi lter[productType]=APP&include= primaryRepositories Serverless function let productId: String let repositoryId: String /v1/ciProducts/productId/work fl ows? fi elds[ciWork fl ows]=name let workflowId: String /repos/OWNER/REPO/pulls/PULL_NUMBER { "action": "created", "issue": { "pull_request": { "url": "https: // api.github.com/…" } }, "repository": { "name": "QRBuddy" }, "comment": { "body": "Upload to testflight" } } /v1/scmRepositories/repositoryId/gitReferences let gitReferenceId: String /v1/ciBuildRuns

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Xcode Cloud webhooks

Slide 89

Slide 89 text

Xcode Cloud webhooks β€’ There are only 3 types β€’ Create build β€’ Start build β€’ Complete buid β€’ Only con fi gurable in App Store Connect β€’ Can’t subscribe to speci fi c events. β€’ ⚠ Only 5 webhooks per product

Slide 90

Slide 90 text

No content