Skip to content

Instantly share code, notes, and snippets.

@thiagolioy
Last active August 29, 2015 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagolioy/edbb60ba5083877e41fe to your computer and use it in GitHub Desktop.
Save thiagolioy/edbb60ba5083877e41fe to your computer and use it in GitHub Desktop.
Fastfile with tests , coverage and deploy
module Fastlane
module Actions
module SharedValues
DEPLOY_MOBR_CUSTOM_VALUE = :DEPLOY_MOBR_CUSTOM_VALUE
end
class DeployMobrAction
@@releases_folder = "releases"
@@api_key = "dummyapp-apikey"
@@api_user = "DummyAPPUser"
@@app_id = "dummyAppId"
@@platform_id = "iphone-plataform-id"
@@base_url = "http://mobrelease.concretecorp.com.br"
@@release_url = "#{@@base_url}/api/v1/release/?format=json&username=#{@@api_user}&api_key=#{@@api_key}"
@@slug = "dummyapp"
def self.run(params)
require 'rest_client'
require 'json'
RestClient.log = $stdout
puts("Iniciando publicacao no Mobile Release");
version_name = Time.now.strftime("%d-%m-%Y-%Hh-%Mm")
upload_file(create_release(version_name))
download_url(version_name)
end
def self.download_url(version_name)
"#{@@base_url}/application/#{@@slug}/iphone/#{version_name}/"
end
def self.upload_file_url(release_id)
"#{@@base_url}/api/v1/releasefile/#{release_id}/?format=json&username=#{@@api_user}&api_key=#{@@api_key}"
end
def self.create_release(version_name)
json = {
:application => "/api/v1/application/#{@@app_id}/",
:platform => "/api/v1/platform/#{@@platform_id}/",
:version => version_name,
:release_notes => ""
}
puts("Criando release com url:#{@@release_url}")
response = RestClient.post(@@release_url,json.to_json,:content_type => :json, :accept => :json)
JSON.parse(response)['id']
end
def self.upload_file(release_id)
url = upload_file_url(release_id)
file_name = fetch_file_name
puts("Fazendo upload do ipa :#{file_name} para url: #{url}")
RestClient.post url, :file => File.new(file_name, 'rb')
end
def self.fetch_file_name
Dir["#{@@releases_folder}/*.ipa"][0]
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"A short description with <= 80 characters of what this action does"
end
def self.available_options
# Define all options your action supports.
# The environment variable (last parameters) is optional, remove it if you don't need it
# You can add as many parameters as you want
[
# ['path', 'Describe what this parameter is useful for', 'ENVIRONMENT_VARIABLE_NAME'],
# ['second', 'Describe what this parameter is useful for']
]
end
def self.output
# Define the shared values you are going to provide
# Example
[
# ['NOVA_CUSTOM_VALUE', 'A description of what this value contains']
]
end
def self.author
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
'[thiagolioy]'
end
end
end
end
fastlane_version "1.0.2"
default_platform :ios
platform :ios do
before_all do
cocoapods
end
desc "Runs all the tests"
lane :test do
run_tests
lcov_coverage
end
desc "Submit a new release to mobrelease"
lane :mobr do
run_tests
lcov_coverage
ipa(
workspace: "./DummyApp.xcworkspace",
scheme: "DummyApp",
destination: "./releases"
)
applink = deploy_mobr
mailit(applink,"dummyios")
end
def mailit(applink , scheme)
mailgun(
mailgun_sandbox_domain: "",
mailgun_sandbox_postmaster: "",
mailgun_apikey: "",
to: "",
success: true,
message: "Novo release da [DummyApp iOS #{scheme}](#{applink})."
)
end
# You can define as many lanes as you want
after_all do |lane|
# This block is called, only if the executed lane was successful
# slack(
# message: "Successfully deployed new App Update."
# )
end
error do |lane, exception|
# slack(
# message: exception.message,
# success: false
# )
end
end
# More information about multiple platforms in fastlane:
# https://github.com/KrauseFx/fastlane/blob/master/docs/Platforms.md
module Fastlane
module Actions
module SharedValues
LCOV_COVERAGE_CUSTOM_VALUE = :LCOV_COVERAGE_CUSTOM_VALUE
end
class LcovCoverageAction < Action
@@derived_data_path = "#{File.expand_path('~')}/Library/Developer/Xcode/DerivedData/"
@@project = "DummyApp"
@@scheme = "DummyApp"
@@derived_data_end_path = "/Build/Intermediates/#{@@project}.build/Debug-iphonesimulator/#{@@scheme}.build/Objects-normal/i386/"
@@out_cov_file = "/tmp/coverage.info"
@@out_cov_dir = "coverage_reports"
@@exclude_dirs = ["/Applications/*","Frameworks/*"]
def self.run(params)
run_lcov
end
def self.run_lcov
system("lcov --capture --directory \"#{derived_data_dir}\" --output-file #{@@out_cov_file}")
cmd = "lcov "
@@exclude_dirs.each do |e|
cmd << "--remove #{@@out_cov_file} #{e}"
end
cmd << "--output #{@@out_cov_file}"
system(cmd)
system("genhtml #{@@out_cov_file} --output-directory #{@@out_cov_dir}")
end
def self.derived_data_dir
match = `ls -t #{@@derived_data_path}| grep #{@@project} | head -1`.to_s.gsub(/\n/, "")
"#{@@derived_data_path}#{match}#{@@derived_data_end_path}"
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"A short description with <= 80 characters of what this action does"
end
def self.available_options
# Define all options your action supports.
# Below a few examples
[
]
end
def self.output
# Define the shared values you are going to provide
# Example
[
]
end
def self.author
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
'thiagolioy'
end
def self.is_supported?(platform)
# you can do things like
#
# true
#
# platform == :ios
#
# [:ios, :mac].include?platform
#
platform == :ios
end
end
end
end
module Fastlane
module Actions
module SharedValues
RUN_TESTS_CUSTOM_VALUE = :RUN_TESTS_CUSTOM_VALUE
end
class RunTestsAction
@@workspace = "DummyApp.xcworkspace"
@@scheme = "DummyApp"
@@sdks = ["iphonesimulator8.3"]
def self.run(params)
build_tests
run_tests
end
def self.build_tests
system("xctool -workspace #{@@workspace} -scheme #{@@scheme} -configuration Debug -reporter plain GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES build-tests");
end
def self.run_tests
@@sdks.map { |s| system("xctool -workspace #{@@workspace} -scheme #{@@scheme} -sdk #{s} run-tests") }
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"A short description with <= 80 characters of what this action does"
end
def self.available_options
# Define all options your action supports.
# The environment variable (last parameters) is optional, remove it if you don't need it
# You can add as many parameters as you want
[
# ['path', 'Describe what this parameter is useful for', 'ENVIRONMENT_VARIABLE_NAME'],
# ['second', 'Describe what this parameter is useful for']
]
end
def self.output
# Define the shared values you are going to provide
# Example
[
# ['NOVA_CUSTOM_VALUE', 'A description of what this value contains']
]
end
def self.author
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
'[thiagolioy]'
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment