Skip to content

Instantly share code, notes, and snippets.

@roderik
Created November 26, 2015 10:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roderik/ed7bf0aa8d6842d5bd06 to your computer and use it in GitHub Desktop.
Save roderik/ed7bf0aa8d6842d5bd06 to your computer and use it in GitHub Desktop.
Fastlane actions mentioned in the Kunstmaan Labs blogpost "iOS continuous delivery with Jenkins and Fastlane" found at https://labs.kunstmaan.be/blog/ios-continuous-delivery-with-jenkins-and-fastlane
module Fastlane
module Actions
class AppNameAction < Action
def self.run(params)
require 'plist'
identifier_key = 'CFBundleDisplayName'
folder = Dir['*.xcodeproj'].first
info_plist_path = params[:plist_path]
raise "Couldn't find info plist file at path '#{params[:plist_path]}'".red unless File.exist?(info_plist_path)
plist = Plist.parse_xml(info_plist_path)
plist[identifier_key] = params[:app_name]
plist_string = Plist::Emit.dump(plist)
File.write(info_plist_path, plist_string)
Helper.log.info "Updated #{params[:plist_path]} 💾.".green
end
#####################################################
# @!group Documentation
#####################################################
def self.is_supported?(platform)
[:ios].include?(platform)
end
def self.description
'Update an app name'
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :plist_path,
env_name: "FL_UPDATE_APP_IDENTIFIER_PLIST_PATH",
description: "Path to info plist, relative to your Xcode project",
verify_block: proc do |value|
raise "Invalid plist file".red unless value[-6..-1].downcase == ".plist"
end),
FastlaneCore::ConfigItem.new(key: :app_name,
env_name: 'FL_UPDATE_APP_NAME',
description: 'The app name of your app',
verify_block: proc do |value|
raise "No app_name".red unless (value and not value.empty?)
end)
]
end
def self.authors
['@r0derik']
end
end
end
end
# Based on: https://gist.github.com/rgm/5377144
# Requires ImageMagick: `brew install imagemagick ghostscript`
module Fastlane
module Actions
class NoSourceFileError < ArgumentError; end
class Icon
attr_accessor :src, :dst
def src= path
if File.exist? path
@src = path
else
raise NoSourceFileError, "no icon file at #{path}"
end
end
def stamp_icon_with str
`convert -background '#0008' -fill white -font Helvetica -density 300 -gravity Center -size #{banner_dims} caption:"#{str}" "#{@src}" +swap -gravity South -composite "#{@dst}"`
end
def banner_dims
banner_ht = (dims[:ht] * 0.2).floor
"#{dims[:wd]}x#{banner_ht}" # imagemagick-style format string
end
def dims
return @dims if @dims
data = `identify -format "%w %h" "#{@src}"`.strip.split.map(&:to_i)
@dims = {:wd => data[0], :ht => data[1]}
end
end
class BuildNumberIconAction < Action
def self.run(params)
icons = sh("find . -iname 'Icon-*'")
icons.each_line do |stem|
begin
source = stem.strip
i = Icon.new
i.src = source
i.dst = "#{source}-edit"
version = ENV["BUILD_NUMBER"] || "1234"
i.stamp_icon_with "##{version}"
FileUtils.cp i.dst, i.src
FileUtils.rm i.dst
rescue NoSourceFileError => msg
STDERR.puts "Warning: #{msg}"
end
end
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Adds the build number to the Icons"
end
def self.authors
["@r0derik"]
end
def self.is_supported?(platform)
platform == :ios
end
end
end
end
# Based on: https://gist.github.com/rgm/5377144
# Requires ImageMagick: `brew install imagemagick ghostscript`
module Fastlane
module Actions
class NoSourceFileError < ArgumentError; end
class Icon
attr_accessor :src, :dst
def src= path
if File.exist? path
@src = path
else
raise NoSourceFileError, "no icon file at #{path}"
end
end
def color_icon modulation
#{}`convert "#{@src}" -fuzz 25% -fill '#{to}' -opaque '#{from}' "#{@dst}"`
`convert "#{@src}" -modulate 100,100,#{modulation} "#{@dst}"`
end
end
class ColorIconAction < Action
def self.run(params)
icons = sh("find . -iname 'Icon-*'")
icons.each_line do |stem|
begin
source = stem.strip
i = Icon.new
i.src = source
i.dst = "#{source}-edit"
i.color_icon "#{params[:modulation]}"
FileUtils.cp i.dst, i.src
FileUtils.rm i.dst
rescue NoSourceFileError => msg
STDERR.puts "Warning: #{msg}"
end
end
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Changes the color of all Icon* files with a modulation degree"
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :modulation,
env_name: "COLOR_MODULATION",
description: "Modulation degrees",
verify_block: proc do |value|
raise "No from color `modulation: '33.3'`".red unless (value and not value.empty?)
end)
]
end
def self.authors
["@r0derik"]
end
def self.is_supported?(platform)
platform == :ios
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment