Skip to content

Commit 545e9ca

Browse files
committed
fastlane: Decentralize version code generation, fix Sentry sourcemaps
We were previously just sending the value of current_bundle_version as both the RELEASE_NAME and DISTRIBUTION_NAME parameters for the Sentry CLI, however, this was incorrect. It seems that Sentry instead associates with the provided DISTRIBUTION_NAME, (i.e. iOS' CFBundleVersion or Android's versionCode) So we were uploading with `2.8.0-pre` in both RELEASE_NAME and DISTRIBUTION_NAME instead of `2.8.0-pre` for RELEASE_NAME and the distribution version code for DISTRIBUTION_NAME Now, we have a helper that can query against the gradle stuff and get the appropriate values out. Signed-off-by: Kristofer Rye <[email protected]>
1 parent e5e9cc6 commit 545e9ca

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

fastlane/lib/sourcemaps.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def upload_sourcemap_to_sentry
5454
'files',
5555
current_bundle_version,
5656
'upload-sourcemaps',
57-
"--dist #{current_bundle_version}",
57+
"--dist #{current_bundle_code}",
5858
"--strip-prefix #{File.expand_path(File.join(__FILE__, '..', '..', '..'))}",
5959
'--rewrite',
6060
args[:sourcemap_output]

fastlane/lib/versions.rb

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# get the current build number from the environment
2-
def build_number
3-
travis = ENV['TRAVIS_BUILD_NUMBER']
4-
# bring circle's build numbers up to pass Travis'?
5-
circle = (ENV['CIRCLE_BUILD_NUM'].to_i + 3250).to_s
6-
travis || circle
7-
end
8-
91
# Get the current "app bundle" version
102
def current_bundle_version
113
case lane_context[:PLATFORM_NAME]
@@ -19,23 +11,42 @@ def current_bundle_version
1911
end
2012
end
2113

14+
# Get the current "app bundle" version code (mostly for Sentry)
15+
def current_bundle_code
16+
case lane_context[:PLATFORM_NAME]
17+
when :android
18+
get_gradle_version_code(gradle_path: lane_context[:GRADLE_FILE])
19+
when :ios
20+
get_info_plist_value(path: 'ios/AllAboutOlaf/Info.plist',
21+
key: 'CFBundleVersion')
22+
else
23+
raise 'wtf'
24+
end
25+
end
26+
27+
# Generate build number
28+
def generate_build_numbers
29+
build = (ENV['CIRCLE_BUILD_NUM'].to_i + 3250).to_s
30+
31+
# android's build number goes way up because we need to exceed the old build
32+
# numbers generated for the x86 build.
33+
ci_build_num = build
34+
build = ((2 * 1_048_576) + build.to_i).to_s if lane_context[:PLATFORM_NAME] == :android
35+
36+
{ci: ci_build_num, build: build}
37+
end
38+
2239
# Copy the package.json version into the other version locations
2340
def propagate_version
2441
return unless ENV.key? 'CI'
2542

2643
version = get_package_key(key: :version)
27-
build = build_number
2844

2945
UI.message "Propagating version: #{version}"
3046
UI.message 'into the Info.plist and build.gradle files'
3147

32-
UI.message "Setting build number to #{build}"
33-
34-
# android's build number goes way up because we need to exceed the old build
35-
# numbers generated for the x86 build.
36-
ci_build_num = build
37-
build = ((2 * 1_048_576) + build.to_i).to_s if lane_context[:PLATFORM_NAME] == :android
38-
UI.message "Actually setting build number to #{build} because we're on android"
48+
build_numbers = generate_build_numbers
49+
UI.message "Version codes are {CI: #{build_numbers[:ci]}, distribution: #{build_numbers[:build]}}"
3950

4051
version = "#{version.split('-')[0]}-pre" if should_nightly?
4152
UI.message "Actually putting #{version} into the binaries (because we're doing a nightly)"
@@ -44,16 +55,16 @@ def propagate_version
4455
# never set the "+" into the binaries
4556
unless version.include? '+'
4657
# we always want the CI build number in js-land
47-
set_package_data(data: { version: "#{version}+#{ci_build_num}" })
58+
set_package_data(data: { version: "#{version}+#{build_numbers[:ci]}" })
4859
end
4960

5061
case lane_context[:PLATFORM_NAME]
5162
when :android
5263
set_gradle_version_name(version_name: version, gradle_path: lane_context[:GRADLE_FILE])
53-
set_gradle_version_code(version_code: build, gradle_path: lane_context[:GRADLE_FILE])
64+
set_gradle_version_code(version_code: build_numbers[:build], gradle_path: lane_context[:GRADLE_FILE])
5465
when :ios
5566
# we're splitting here because iTC can't handle versions with dashes in them
5667
increment_version_number(version_number: version.split('-')[0], xcodeproj: ENV['GYM_PROJECT'])
57-
increment_build_number(build_number: build, xcodeproj: ENV['GYM_PROJECT'])
68+
increment_build_number(build_number: build_numbers[:build], xcodeproj: ENV['GYM_PROJECT'])
5869
end
5970
end

0 commit comments

Comments
 (0)