· 6 years ago · Nov 26, 2019, 11:36 AM
1desc "Submit a new build to Crashlytics, AppCenter or TestFlight"
2desc "This action does the following:"
3desc ""
4desc "- Clear derived data"
5desc "- Turn off automatic signing"
6desc "- Increment the build number"
7desc "- Change the bundle id to appropriate for in house provisioning profile"
8desc "- Download or create certificates"
9desc "- Download or create provisioning profile"
10desc "- Switching to the correct team"
11desc "- Updating provisioning profile with the one from sigh"
12desc "- Build and sign the app"
13desc "- Upload the ipa file to Crashlytics, AppCenter or TestFlight"
14
15# If any of those lanes is not needed for your project, feel free to delete it.
16# THIS FILE INCLUDES THE FOLLOWING LANES:
17# 1. deploy
18 # In case you want to deploy an archive of your app you should execute:
19 # a. For AppCenter: fastlane deploy deploymentPlatform:AppCenter
20 # b. For Crashlytics: fastlane deploy deploymentPlatform:Crashlytics
21 # c. For TestFlight: fastlane deploy deploymentPlatform:TestFlight
22# 2. lint
23 # Using this lane requires to have Swiftlint added as a pod in the project and also having a .swiftlint.yml file locally
24# 3. metrics
25 # Used for SonarQube
26# 4. scanner
27 # Used for SonarQube
28
29lane :deploy do |values|
30
31 # Crashlytics variables
32 CRASHLYTICS_API_KEY = "dc301c285188282514ae046553a7e432176ef15f" # API key of the organization. Defaults to the Upnetix key.
33 CRASHLYTICS_BUILD_SECRET = "aec6a8a4d2c8aefb03918ed8dc872b3d656aebc87a38b0c04cb1e1634b8a1a06" # Build secret of the organization. Defaults to the Upnetix secret.
34 CRASHLYTICS_TEST_GROUP = 'upnetix' # Set to the test group for the app. Make sure the group is existing, or remove it from the crashlytics step. Make sure you use the alias, and not the display name from crashlytics web
35 CRASHLYTICS_DEFAULT_MAIL_LIST = ['v.s.kaltchev@gmail.com', 'valentin.kalchev@upnetix.com', 'oci@upnetix.com'] # any hardcoded mails, which might not be in the particular test group
36
37 # AppCenter variables
38 APP_CENTER_API_TOKEN = "ExampleAPITokenb8fd48ee2b094cb7b9837a76ca5e4ceb"
39 APP_CENTER_APP_ID = "ExampleAppIdd59bbc210354876fc987b458dbea2b08"
40
41 BUILD_NUMBER = Time.new.strftime("%-y.%-m.%-d%H%M")
42 XCPROJECT_PATH = File.expand_path "../ExampleProject.xcodeproj"
43 XCWORKSPACE_PATH = File.expand_path "../ExampleProject.xcworkspace"
44 INFO_PLIST_PATH = File.expand_path "../ExampleProject/Info.plist"
45 PLIST_RELATIVE_TO_PROJECT_PATH = "ExampleProject/Info.plist"
46 JENKINS_APPLEID_WITH_RIGHTS = "ci@upnetix.com"
47 APP_ID_IN_DEVELOPER_PROFILES = "com.upnetix.ExampleName" # change according to your app id, must match the app id in the InHouse Provisioning profile used
48 TEAM_ID = "UWBDU93DZY" # do not change if using UPNETIX AD team (default)
49 SHOULD_NOTIFY_TESTERS = "1" # "1" for yes, "0" for no
50 SCHEME_TO_BUILD = "ExampleProjectScheme"
51 TARGET_FILTER = "ExampleProjectTargetName" #name of target that needs signing
52 # if for some reason you need signing for multiple targets, find the proper way to do it
53
54 emails = values[:test_email] ? values[:test_email] : CRASHLYTICS_DEFAULT_MAIL_LIST # You can list more emails here
55 groups = values[:test_email] ? nil : [CRASHLYTICS_TEST_GROUP] # You can define groups on the web and reference them here
56
57 clear_derived_data
58
59 # Turn off automatic signing for the project.
60 automatic_code_signing(
61 path: XCPROJECT_PATH,
62 use_automatic_signing: false
63 )
64
65 # Increment build number. increment_build_number conflicts with update_app_identifier and currently won't work properly(11.07.2016). Thus using workaround with set_info_plist_value
66 set_info_plist_value(
67 path: INFO_PLIST_PATH,
68 key: "CFBundleVersion",
69 value: BUILD_NUMBER
70 )
71
72 # Update app bundle to reflect beta status
73 update_app_identifier(
74 plist_path: PLIST_RELATIVE_TO_PROJECT_PATH,
75 xcodeproj: XCPROJECT_PATH,
76 app_identifier: APP_ID_IN_DEVELOPER_PROFILES
77 )
78
79 # Download or create certificates
80 cert(
81 username: JENKINS_APPLEID_WITH_RIGHTS,
82 team_id: TEAM_ID
83 )
84
85 # Download or create provisioning profile
86 sigh(
87 app_identifier: APP_ID_IN_DEVELOPER_PROFILES,
88 username: JENKINS_APPLEID_WITH_RIGHTS,
89 team_id: TEAM_ID,
90 filename: "InHouse.mobileprovision"
91 )
92
93 # Switching to the correct team, in case the scheme has been modified
94 update_project_team(
95 path: XCPROJECT_PATH,
96 teamid: TEAM_ID
97 )
98
99 # Updating provisioning profile with the one from sigh
100 update_project_provisioning(
101 xcodeproj: XCPROJECT_PATH,
102 build_configuration: "Release",
103 profile: "./InHouse.mobileprovision",
104 target_filter: TARGET_FILTER
105 )
106
107 # Build your app for hockey distribution
108 gym(
109 scheme: SCHEME_TO_BUILD,
110 workspace: XCWORKSPACE_PATH, # enter project: XCPROJECT_PATH, if you're not using workspace
111 configuration: "Release",
112 export_method: "enterprise",
113 clean: true,
114 codesigning_identity: "iPhone Distribution"
115 )
116
117 # Get all commits since last successfull Jenkins upload and format note message for Hockey
118 changelog = changelog_from_git_commits(
119 # http://git-scm.com/docs/pretty-formats
120 between: [ENV['GIT_PREVIOUS_SUCCESSFUL_COMMIT'] || "HEAD^^^^^", "HEAD"],
121 pretty: "- %s %n"
122 )
123 if changelog.nil?
124 changelog = "Commit history unavailable."
125 end
126 truncatedChangelog = changelog[0..3000].gsub(/\s\w+$/,'...')
127 releaseNotes = "Branch: " + git_branch + "\n\nCommits:\n" + truncatedChangelog + "\n@" + Time.new.strftime("%-Y") + " Upnetix CI"
128
129 deploymentPlatform = values[:deploymentPlatform]
130 if deploymentPlatform.nil?
131 UI.error "You should specify in which platform you want to deploy. Check the documentation."
132 end
133
134 if deploymentPlatform == "AppCenter"
135 UI.success "Pushing an archive to AppCenter..."
136
137 # Upload build to AppCenter
138 # FIXME: REPLACE THE HOCKEY FUNCTION WHEN APPCENTER IS INTEGRATED
139 hockey(
140 api_token: HOCKEY_API_TOKEN,
141 public_identifier: HOCKEY_APP_ID,
142 notes: releaseNotes,
143 notify: SHOULD_NOTIFY_TESTERS)
144 end
145
146 if deploymentPlatform == "Crashlytics"
147 UI.success "Pushing an archive to Crashlytics..."
148
149 # Upload build to Crashlytics
150 crashlytics(api_token: CRASHLYTICS_API_KEY,
151 build_secret: CRASHLYTICS_BUILD_SECRET,
152 emails: emails,
153 groups: groups,
154 notes: releaseNotes,
155 notifications: SHOULD_NOTIFY_TESTERS)
156 end
157
158 if deploymentPlatform == "TestFlight"
159 UI.success "Pushing an archive to TestFlight..."
160 # Deploy to TestFlight
161 # NOTE: You should be having all certificates and provisioning proviles installed locally to deploy successfully to TestFlight
162 pilot(
163 username: JENKINS_APPLEID_WITH_RIGHTS,
164 skip_waiting_for_build_processing: true
165 )
166 end
167end
168
169lane :lint do
170
171 SWIFTLINT_YML_PATH = './.swiftlint.yml'
172 SWIFTLINT_EXECUTABLE = './Pods/SwiftLint/swiftlint'
173 SWIFTLINT_OUTPUT_FILE = 'swiftlint_report.xml'
174 SWIFTLINT_REPORTER = 'junit'
175
176 swiftlint(
177 executable: SWIFTLINT_EXECUTABLE,
178 config_file: SWIFTLINT_YML_PATH,
179 output_file: SWIFTLINT_OUTPUT_FILE,
180 reporter: SWIFTLINT_REPORTER)
181end
182
183lane :metrics do
184
185 SONAR_REPORTS_DIRECTORY = 'sonar-reports'
186 Dir.mkdir "../#{SONAR_REPORTS_DIRECTORY}" unless File.exist?("../#{SONAR_REPORTS_DIRECTORY}")
187
188 lizard(
189 executable: '/usr/local/lib/python2.7/site-packages/lizard.py',
190 source_folder: './SonarQubeExample',
191 language: 'swift',
192 export_type: 'xml',
193 report_file: "#{SONAR_REPORTS_DIRECTORY}/lizard-report.xml")
194
195 swiftlint(
196 executable: SWIFT_LINT_EXECUTABLE,
197 output_file: "#{SONAR_REPORTS_DIRECTORY}/swiftlint-report.txt",
198 ignore_exit_status: true)
199
200end
201
202lane :scanner do
203
204 sonar(
205 project_key: "{SonarQube project key}",
206 project_version: "1.0",
207 project_name: "{SonarQube project name}",
208 sources_path: File.expand_path("../ExampleProject")
209 )
210end