Last active
August 29, 2015 13:58
-
-
Save y310/10240631 to your computer and use it in GitHub Desktop.
Utilities for AutoFlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
PATH=/usr/local/bin:$PATH | |
CERTIFICATE="iPhone Distribution: XXX" | |
SCHEME=TestFlight | |
KEYCHAIN=XXX.keychain | |
BUNDLE_ID_SUFFIX=testflight | |
SCRIPT_DIR=$HOME/jenkins/tools/autoflight | |
BUILD_DIR=${WORKSPACE}/build | |
PROJECT=$project_name.xcodeproj | |
XCWORKSPACE=$project_name.xcworkspace | |
# Set Bundle ID suffix | |
INFO_PLIST=`pwd`/$project_name/$project_name-Info.plist | |
BUNDLE_ID=`defaults read $INFO_PLIST CFBundleIdentifier` | |
defaults write $INFO_PLIST CFBundleIdentifier "\"$BUNDLE_ID-$BUNDLE_ID_SUFFIX\"" | |
defaults write $INFO_PLIST CFBundleVersion "\"$branch\"" | |
# composite TEST ribbon | |
$SCRIPT_DIR/ios_app_icon.rb $PROJECT $SCHEME | xargs -n 1 -IICON $SCRIPT_DIR/composite_icon.sh ICON $SCRIPT_DIR/autoflight.png | |
security unlock-keychain -p $keychain_password $KEYCHAIN | |
security set-keychain-settings -l -t 1800 | |
if [ -e Podfile ]; then | |
pod install | |
xcodebuild -workspace $XCWORKSPACE -scheme $SCHEME "CODE_SIGN_IDENTITY=$CERTIFICATE" "CONFIGURATION_BUILD_DIR=$BUILD_DIR" clean | |
xcodebuild -workspace $XCWORKSPACE -scheme $SCHEME "CODE_SIGN_IDENTITY=$CERTIFICATE" "CONFIGURATION_BUILD_DIR=$BUILD_DIR" build | |
else | |
xcodebuild -project $PROJECT -scheme $SCHEME "CODE_SIGN_IDENTITY=$CERTIFICATE" "CONFIGURATION_BUILD_DIR=$BUILD_DIR" clean | |
xcodebuild -project $PROJECT -scheme $SCHEME "CODE_SIGN_IDENTITY=$CERTIFICATE" "CONFIGURATION_BUILD_DIR=$BUILD_DIR" build | |
fi | |
PACKAGE_NAME_BASE=`find $BUILD_DIR -name *.app | sed -e "s/\.app//"` | |
APP_NAME=$PACKAGE_NAME_BASE.app | |
IPA_NAME=$PACKAGE_NAME_BASE.ipa | |
xcrun -l -sdk iphoneos PackageApplication -v $APP_NAME -o $IPA_NAME --sign "$CERTIFICATE" | |
ditto -c -k --keepParent -rsrc $APP_NAME.dSYM $PACKAGE_NAME_BASE-dSYM.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
original_image=$1 | |
compositing_image=$2 | |
resized_compositing_image=/tmp/resized_compositing_image.png | |
composite_image=/tmp/out.png | |
width=`identify -format "%w" $original_image` | |
convert -resize "$width"x $compositing_image $resized_compositing_image | |
convert $original_image $resized_compositing_image -composite $composite_image | |
mv $composite_image $original_image | |
rm $resized_compositing_image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'xcodeproj' | |
require 'xcodeproj/ext' | |
require 'nokogiri' | |
require 'pathname' | |
require 'json' | |
class Project | |
def initialize(project_name, scheme_name) | |
@project_name = project_name | |
@project = Xcodeproj::Project.open(project_name) | |
@target_name = File.basename(project_name, '.*') | |
@scheme = Scheme.new(project_name, scheme_name) | |
end | |
def target | |
@target ||= @project.targets.find {|t| t.name == @target_name } | |
end | |
def build_settings | |
target.build_settings(@scheme.build_configuration) | |
end | |
def app_icon_set_name | |
build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] | |
end | |
def app_icon_set | |
if app_icon_set_name | |
@app_icon_set ||= AppIconSet.new(app_icon_set_name) | |
end | |
end | |
def old_icon_set | |
@old_icon_set ||= OldIconSet.new(File.basename(@project_name, '.*'), @project) | |
end | |
def icon_files | |
if set = app_icon_set | |
set.icons.map(&:filename).compact.map {|filename| | |
"#{set.directory}/#{filename}" | |
} | |
else | |
old_icon_set.icons.map(&:to_s) | |
end | |
end | |
class Scheme | |
def initialize(project_name, scheme_name) | |
scheme_dir = Xcodeproj::XCScheme.shared_data_dir(project_name) | |
scheme_filepath = Dir.glob(scheme_dir + "#{scheme_name}.xcscheme").first | |
@scheme = Nokogiri::XML.parse(open(scheme_filepath).read) | |
end | |
def build_configuration(action = 'launch') | |
@scheme.xpath("Scheme/#{action.capitalize}Action/@buildConfiguration").first.value | |
end | |
end | |
class OldIconSet | |
attr_reader :icons | |
def initialize(project_name, project) | |
plist = InfoPlist.new(project_name) | |
icon_names = plist.icon_names | |
@icons = project.files.map(&:real_path).select {|path| | |
basename = path.basename.to_s | |
icon_names.any? {|name| basename =~ /#{name}/ } | |
} | |
end | |
class InfoPlist | |
def initialize(project_name) | |
@plist = Xcodeproj.read_plist("#{project_name}/#{project_name}-Info.plist") | |
end | |
def bundle_icons | |
@plist.select do |k, v| | |
k =~ /CFBundleIcons/ | |
end | |
end | |
def icon_names | |
names = bundle_icons.map {|k,v| | |
v['CFBundlePrimaryIcon']['CFBundleIconFiles'] | |
}.flatten.uniq.sort | |
end | |
end | |
end | |
class AppIconSet | |
attr_accessor :icons, :path | |
def initialize(name) | |
@path = Dir.glob("**/*.xcassets/#{name}.appiconset/Contents.json").first | |
@icons = JSON.parse(open(@path).read)['images'].map do |icon| | |
AppIcon.new(icon) | |
end | |
end | |
def directory | |
@directory ||= File.dirname(@path) | |
end | |
class AppIcon | |
attr_reader :idiom, :size, :scale, :filename, :width, :height | |
def initialize(params) | |
@idiom = params['idiom'] | |
@size = params['size'] | |
@scale = params['scale'] | |
@filename = params['filename'] | |
@width, @height = @size.split('x').map(&:to_i) | |
end | |
end | |
end | |
end | |
project_name = ARGV[0] | |
scheme_name = ARGV[1] | |
project = Project.new(project_name, scheme_name) | |
puts project.icon_files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment