Skip to content

Instantly share code, notes, and snippets.

@ChristiaanScheermeijer
Created February 16, 2018 15:32
Show Gist options
  • Save ChristiaanScheermeijer/e87b7b2d7bffcc0c027e6d88d682ec8d to your computer and use it in GitHub Desktop.
Save ChristiaanScheermeijer/e87b7b2d7bffcc0c027e6d88d682ec8d to your computer and use it in GitHub Desktop.
Use Cordova iOS project in MS App Center without opening Xcode
#!/usr/bin/env ruby
require 'xcodeproj'
# This script allows you to build debug and/or appstore builds via MS App Center.
# Using a CI/CD the Cordova application gets build. The iOS project is then
# committed to a separate repository which is connected to MS App Center.
# However, without opening the iOS project in Xcode first and setting up the
# build settings and sharing the scheme, MS App Center can't build the app.
#
# This script creates two schemes. One for debug and one for release. In
# MS App Center you should select <YourAppName>.xcworkspace and the scheme
# you would like to build. For example, you can setup a develop branch to
# build and distribute a debug app and the master branch for a distribution
# (or ad-hoc) build and distribution.
#
# Change the settings below before running.
#
# Install xcodeproj gem `sudo gem install xcodeproj -n /usr/local/bin`
# Run script using `ruby cordova_appcenter.rb`
#
# Using:
# - cordova v8.0.0
# - cordova-ios v4.5.4
# - xcode v9.2
#
# settings
path_to_xcodeproj = "platforms/ios/<YourAppName>.xcodeproj"
development_team = "xxxxxxx"
debug_settings = {
"DEVELOPMENT_TEAM" => development_team,
"PROVISIONING_PROFILE" => "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"PROVISIONING_PROFILE_SPECIFIER" => "xxxxxxxxxxxxx"
}
release_settings = {
"DEVELOPMENT_TEAM" => development_team,
"PROVISIONING_PROFILE" => "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"PROVISIONING_PROFILE_SPECIFIER" => "xxxxxxxxxxxxx"
}
def create_scheme(name, xcproj, settings)
target = xcproj.targets[0]
# update build settings
configuration = xcproj.targets[0].build_configurations.find { |item| item.name === name }
settings.each {|key, value| configuration.build_settings[key] = value }
# create scheme
scheme = Xcodeproj::XCScheme.new
scheme.add_build_target(target)
scheme.set_launch_target(target)
scheme.test_action.build_configuration = name
scheme.profile_action.build_configuration = name
scheme.analyze_action.build_configuration = name
scheme.archive_action.build_configuration = name
scheme.save_as(xcproj.path, target.product_name + ' ' + name)
end
# open xcode project
xcproj = Xcodeproj::Project.open(path_to_xcodeproject)
# create two build schemes
create_scheme("Debug", xcproj, debug_settings)
create_scheme("Release", xcproj, release_settings)
# create TargetAttributes (it didn't work without)
xcproj.root_object.attributes['TargetAttributes'] = {}
xcproj.root_object.attributes['TargetAttributes'][xcproj.targets[0].uuid] = {
"DevelopmentTeam" => development_team
}
xcproj.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment