Fastfile 2.83 KB
Newer Older
1 2 3 4 5
# Prevent Fastlane from overwriting README.md
skip_docs

default_platform(:ios)

6 7 8 9 10 11 12 13 14 15
def suppress_output
  original_stdout, original_stderr = $stdout.clone, $stderr.clone
  $stderr.reopen File.new('/dev/null', 'w')
  $stdout.reopen File.new('/dev/null', 'w')
  yield
ensure
  $stdout.reopen original_stdout
  $stderr.reopen original_stderr
end

16 17 18 19 20 21
# This should be run after running
# flutter build ios --release --no-codesign
# to build the app using the Flutter toolchain. This lane is meant to only
# rebuild the app by:
# 1- Signing using the publishing credentials; and
# 2- xcodebuild with archive option
22
platform :ios do
23
  desc 'Push a new release to TestFlight'
24
  lane :build_and_deploy_testflight do |options|
25 26 27 28
    # Doesn't do anything when not on a CI bot. Even though it's called
    # "setup_travis", this also runs on Cirrus, since the CI environment
    # variable is set. When on a CI bot, it creates a temporary keychain and
    # switches "match" to readonly mode to not create new profiles/certs on CI.
29 30
    setup_travis

31 32 33 34
    # Relative to this file.
    raw_version = File.read('../../../../version')
    puts "Building and deploying version #{raw_version}..."

35 36 37 38 39 40 41
    update_app_identifier(
      plist_path: 'Runner/Info.plist',
      # Let the checked-in bundle ID be different so users don't collide on
      # provisioning profile creation when building locally.
      app_identifier: 'io.flutter.demo.gallery'
    )

42
    increment_version_number(
43 44
      # Only major, minor, patch digits and dots.
      version_number: /\d+\.\d+\.\d+/.match(raw_version)[0]
45 46
    )

47
    # Stop fastlane from echoing back PUBLISHING_MATCH_CERTIFICATE_REPO var.
48 49
    # Doesn't matter too much since Cirrus doesn't echo back encrypted variables
    # anyway.
50 51 52
    suppress_output {
      # Retrieves all the necessary certs and provisioning profiles.
      sync_code_signing(
53
        git_url:  "https://x-access-token:#{ENV['PUBLISHING_MATCH_REPO_TOKEN']}@#{ENV['PUBLISHING_MATCH_CERTIFICATE_REPO']}" ,
54
        type: 'appstore',
55
        readonly: true,
56 57 58
      )
    }
    puts 'Certificates and profiles installed'
59 60 61 62 63 64

    # Modify the Xcode project to use the new team and profile.
    # It will put the git state to dirty but Travis will be wiped after
    # then run session.
    disable_automatic_code_signing
    update_project_provisioning(
65 66 67 68
      xcodeproj: 'Runner.xcodeproj',
      target_filter: 'Runner',
      build_configuration: 'Release',
      profile: ENV['sigh_io.flutter.demo.gallery_appstore_profile-path'],
69 70 71 72
    )

    # Build and archive the app again.
    build_ios_app(
73 74 75
      workspace: 'Runner.xcworkspace',
      scheme: 'Runner',
      export_method: 'app-store',
76
      # Verify that the right signing identity is used for publishing.
77
      codesigning_identity: 'iPhone Distribution: FLUTTER.IO LLC (S8QB4VV633)',
78 79
    )

80
    if options[:upload]
81 82
      upload_to_testflight
    end
83 84
  end
end