Skip to content

Commit a60a815

Browse files
committed
add fastlane commands to generate source maps for bugsnag
1 parent b9a16e7 commit a60a815

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

fastlane/lib/util.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,70 @@ def propagate_version(**args)
6464
end
6565
end
6666

67+
# Generate argument values for the generate_sourcemap and upload_sourcemap_to_bugsnag lanes
68+
def get_sourcemap_args
69+
# The cwd is /fastlane. I don't know why entry_file doesn't need to be ../, but
70+
# I believe that watchman finds the project root and automatically looks there
71+
case lane_context[:PLATFORM_NAME]
72+
when :android
73+
platform = 'android'
74+
entry_file = 'index.android.js'
75+
bundle_output = '../android-release.bundle'
76+
sourcemap_output = '../android-release.bundle.map'
77+
bundle_url = 'index.android.bundle'
78+
when :ios
79+
platform = 'ios'
80+
entry_file = 'index.ios.js'
81+
bundle_output = '../ios-release.bundle'
82+
sourcemap_output = '../ios-release.bundle.map'
83+
bundle_url = 'main.jsbundle'
84+
end
85+
86+
{
87+
platform: platform,
88+
entry_file: entry_file,
89+
bundle_output: bundle_output,
90+
sourcemap_output: sourcemap_output,
91+
bundle_url: bundle_url,
92+
}
93+
end
94+
95+
# Use react-native cli to generate the source map
96+
def generate_sourcemap
97+
args = get_sourcemap_args
98+
99+
cmd = [
100+
'npx react-native bundle',
101+
'--dev false',
102+
"--platform '#{args[:platform]}'",
103+
"--entry-file '#{args[:entry_file]}'",
104+
"--bundle-output '#{args[:bundle_output]}'",
105+
"--sourcemap-output '#{args[:sourcemap_output]}'",
106+
].join ' '
107+
108+
FastlaneCore::CommandExecutor.execute(command: cmd,
109+
print_all: true,
110+
print_command: true)
111+
end
112+
113+
# Upload source map to Bugsnag
114+
def upload_sourcemap_to_bugsnag
115+
args = get_sourcemap_args
116+
117+
cmd = [
118+
'npx bugsnag-sourcemaps upload',
119+
"--api-key '#{ENV['BUGSNAG_KEY']}'",
120+
"--minified-file '#{args[:bundle_output]}'",
121+
"--source-map '#{args[:sourcemap_output]}'",
122+
"--minified-url '#{args[:bundle_url]}'",
123+
'--upload-sources',
124+
].join ' '
125+
126+
FastlaneCore::CommandExecutor.execute(command: cmd,
127+
print_all: true,
128+
print_command: true)
129+
end
130+
67131
# last_git_tag returns the most recent tag, chronologically.
68132
# newest_tag returns the most recent tag *on this branch*.
69133
def newest_tag

fastlane/platforms/android.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
submit(track: 'alpha')
4040
end
4141

42+
desc 'Bundle an Android sourcemap'
43+
lane :sourcemap do
44+
generate_sourcemap
45+
end
46+
4247
desc 'Run the appropriate action on CI'
4348
lane :'ci-run' do
4449
# prepare for the bright future with signed android betas

fastlane/platforms/ios.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
end
5050
end
5151

52+
desc 'Bundle an iOS sourcemap'
53+
lane :sourcemap do
54+
generate_sourcemap
55+
end
56+
5257
desc 'Upload dYSM symbols to Bugsnag from Apple'
5358
lane :refresh_dsyms do
5459
download_dsyms

0 commit comments

Comments
 (0)