/
step.rb
115 lines (89 loc) · 3.06 KB
/
step.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require "fileutils"
require 'zip'
require_relative 'project_helper'
require_relative 'functions'
if !ENV['APM_COLLECTOR_TOKEN']
puts 'Error: missing APM_COLLECTOR_TOKEN env, double check envman and if Trace has been enabled in app by navigating to: Bitrise App->Addon->Trace'
exit 1
end
project_path = ENV['project_path']
scheme = ENV['scheme']
lib_version = ENV['lib_version']
xcode_version = ENV['APM_XCODE_VERSION']
if project_path.empty?
puts "Error: BITRISE_PROJECT_PATH env var is required and cannot be empty. #{project_path}"
exit 1
end
if scheme.empty?
puts "Error: BITRISE_SCHEME env var is required and cannot be empty. #{scheme}"
exit 1
end
if lib_version.empty?
puts "Error: missing input lib_version"
exit 1
end
path = lib_version
if xcode_version.start_with?("Xcode 11")
path += " (Xcode 11.7)" # Xcode 11 projects are built using Xcode 11.7. Update Bitrise stack first
end
puts "Will start download for version: #{path}"
url = "https://monitoring-sdk.firebaseapp.com/#{path}/libTrace.a.zip"
tmpf = download_library(url)
if tmpf == nil
puts "Error downloading Bitrise Trace library version #{lib_version} from #{url}: #{e.message}"
exit 1
end
puts "Downloaded Trace library"
puts
puts "Starting step with path: #{project_path}, scheme: #{scheme}, trace version: #{lib_version}"
puts
if File.exist?(tmpf.path) == false
puts "Downloaded file does not exist at: #{tmpf.path}"
end
fileLocation = "#{File.dirname(project_path)}/#{tmpf.original_filename}"
puts "Moving downloaded file to: #{fileLocation}"
if Dir.exist?(fileLocation) == false
puts "File location path is malformed: #{fileLocation}"
puts "Make sure path is a relative path with the full root"
end
FileUtils.mv(tmpf.path, fileLocation)
# Unzip file
puts "Unzipping Trace SDK package"
Zip::File.open(fileLocation) do |zip_file|
zip_file.each do |f|
if f.name == "libTrace.a"
fpath = File.join("#{File.dirname(project_path)}", f.name)
zip_file.extract(f, fpath) unless File.exist?(fpath)
puts "Unzipping: #{fpath}"
elsif f.name == "VERSION"
puts "Trace SDK Version unzipped: #{zip_file.read("VERSION")}"
puts "Skipping file: #{f.name}"
else
puts "Skipping file: #{f.name}"
end
end
end
puts "Unzipped Trace SDK package"
puts
puts "Opening Xcode project: #{project_path}, scheme: #{scheme}"
helper = ProjectHelper.new(project_path, scheme)
begin
puts
puts "Updating project to link Trace library"
helper.link_swift_framework_if_objective_c_only_project()
helper.link_static_library()
puts "Updated project with Trace library"
rescue Exception => e
puts "Error modifying project to link Trace library: #{e.message}"
exit 1
end
begin
puts "Registering configuration plist file into build phase"
helper.register_resource()
puts "Registered configuration plist file into build phase"
rescue Exception => e
puts "Error registering Bitrise configuration plist file: #{e.message}"
exit 1
end
puts
puts "Done!"